Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -142,7 +142,6 @@ def format_pretty_view(output):
|
|
| 142 |
def process_single_image(model_name, image_file):
|
| 143 |
runner = load_model_runner(model_name)
|
| 144 |
image = Image.open(image_file.name).convert("RGB")
|
| 145 |
-
|
| 146 |
result = runner(image)
|
| 147 |
|
| 148 |
parsed_json = result.get("json")
|
|
@@ -151,11 +150,17 @@ def process_single_image(model_name, image_file):
|
|
| 151 |
if parsed_json:
|
| 152 |
json_output = format_result_json(parsed_json)
|
| 153 |
pretty_output = format_pretty_view(parsed_json)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
else:
|
| 155 |
json_output = "(No valid JSON extracted)"
|
| 156 |
pretty_output = "(No structured content extracted)\n\n⚠️ Raw Model Output:\n" + raw_text
|
|
|
|
| 157 |
|
| 158 |
-
return image, json_output, pretty_output
|
| 159 |
|
| 160 |
# === Gradio UI
|
| 161 |
iface = gr.Interface(
|
|
@@ -167,10 +172,11 @@ iface = gr.Interface(
|
|
| 167 |
outputs=[
|
| 168 |
gr.Image(label="Input Image"),
|
| 169 |
gr.Textbox(label="Raw JSON Output (Technical)", lines=20),
|
| 170 |
-
gr.Textbox(label="Prettified View (User-Friendly)", lines=25)
|
|
|
|
| 171 |
],
|
| 172 |
title="🖼️ Vision Model Extractor - JSON + Pretty View",
|
| 173 |
-
description="Upload a BPMN image and select a vision model to extract structured output. GPT-4o
|
| 174 |
flagging_mode="never"
|
| 175 |
)
|
| 176 |
|
|
|
|
| 142 |
def process_single_image(model_name, image_file):
|
| 143 |
runner = load_model_runner(model_name)
|
| 144 |
image = Image.open(image_file.name).convert("RGB")
|
|
|
|
| 145 |
result = runner(image)
|
| 146 |
|
| 147 |
parsed_json = result.get("json")
|
|
|
|
| 150 |
if parsed_json:
|
| 151 |
json_output = format_result_json(parsed_json)
|
| 152 |
pretty_output = format_pretty_view(parsed_json)
|
| 153 |
+
|
| 154 |
+
# Save JSON to a temporary file for download
|
| 155 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".json", mode="w", encoding="utf-8") as tmp:
|
| 156 |
+
json.dump(parsed_json, tmp, indent=2)
|
| 157 |
+
json_path = tmp.name
|
| 158 |
else:
|
| 159 |
json_output = "(No valid JSON extracted)"
|
| 160 |
pretty_output = "(No structured content extracted)\n\n⚠️ Raw Model Output:\n" + raw_text
|
| 161 |
+
json_path = None
|
| 162 |
|
| 163 |
+
return image, json_output, pretty_output, json_path
|
| 164 |
|
| 165 |
# === Gradio UI
|
| 166 |
iface = gr.Interface(
|
|
|
|
| 172 |
outputs=[
|
| 173 |
gr.Image(label="Input Image"),
|
| 174 |
gr.Textbox(label="Raw JSON Output (Technical)", lines=20),
|
| 175 |
+
gr.Textbox(label="Prettified View (User-Friendly)", lines=25),
|
| 176 |
+
gr.File(label="📥 Download JSON", visible=True)
|
| 177 |
],
|
| 178 |
title="🖼️ Vision Model Extractor - JSON + Pretty View",
|
| 179 |
+
description="Upload a BPMN image and select a vision model to extract structured output. Currenty supports only GPT-4o.",
|
| 180 |
flagging_mode="never"
|
| 181 |
)
|
| 182 |
|