Spaces:
Sleeping
Sleeping
abdelkader
commited on
Commit
Β·
e585852
1
Parent(s):
bb2d44f
Fix Gradio JSON schema error by returning JSON as string
Browse files- ui/detection_wrapper.py +7 -3
- ui/shared_interface.py +2 -1
ui/detection_wrapper.py
CHANGED
|
@@ -12,6 +12,7 @@ import os
|
|
| 12 |
import requests
|
| 13 |
import base64
|
| 14 |
import io
|
|
|
|
| 15 |
from PIL import Image
|
| 16 |
from typing import Tuple, Optional
|
| 17 |
import traceback
|
|
@@ -83,7 +84,8 @@ def detect_with_service(
|
|
| 83 |
detections_list = list(json_payload.get("detections", {}).values())
|
| 84 |
summary_text = f"**OCR-only mode**\n**Total OCR texts:** {len(detections_list)}"
|
| 85 |
|
| 86 |
-
|
|
|
|
| 87 |
|
| 88 |
# Standard detection path
|
| 89 |
service = get_detection_service()
|
|
@@ -136,7 +138,8 @@ def detect_with_service(
|
|
| 136 |
summary_lines.append(f"- BLIP description: {'β
Enabled' if enable_blip else 'β Disabled'}")
|
| 137 |
summary_text = "\n".join(summary_lines)
|
| 138 |
|
| 139 |
-
|
|
|
|
| 140 |
|
| 141 |
except Exception as e:
|
| 142 |
error_msg = f"""β **Error during detection:**
|
|
@@ -286,7 +289,8 @@ The API request timed out after {timeout_seconds} seconds.
|
|
| 286 |
ocr_only=json_payload.get("parameters", {}).get("ocr_only", False)
|
| 287 |
)
|
| 288 |
|
| 289 |
-
|
|
|
|
| 290 |
|
| 291 |
except Exception as e:
|
| 292 |
error_msg = f"""β **Error during detection:**
|
|
|
|
| 12 |
import requests
|
| 13 |
import base64
|
| 14 |
import io
|
| 15 |
+
import json
|
| 16 |
from PIL import Image
|
| 17 |
from typing import Tuple, Optional
|
| 18 |
import traceback
|
|
|
|
| 84 |
detections_list = list(json_payload.get("detections", {}).values())
|
| 85 |
summary_text = f"**OCR-only mode**\n**Total OCR texts:** {len(detections_list)}"
|
| 86 |
|
| 87 |
+
# Return JSON as string for Gradio compatibility
|
| 88 |
+
return annotated, summary_text, json.dumps(json_payload, indent=2)
|
| 89 |
|
| 90 |
# Standard detection path
|
| 91 |
service = get_detection_service()
|
|
|
|
| 138 |
summary_lines.append(f"- BLIP description: {'β
Enabled' if enable_blip else 'β Disabled'}")
|
| 139 |
summary_text = "\n".join(summary_lines)
|
| 140 |
|
| 141 |
+
# Return JSON as string for Gradio compatibility
|
| 142 |
+
return annotated, summary_text, json.dumps(json_payload, indent=2)
|
| 143 |
|
| 144 |
except Exception as e:
|
| 145 |
error_msg = f"""β **Error during detection:**
|
|
|
|
| 289 |
ocr_only=json_payload.get("parameters", {}).get("ocr_only", False)
|
| 290 |
)
|
| 291 |
|
| 292 |
+
# Return JSON as string for Gradio compatibility
|
| 293 |
+
return annotated_image, summary_text, json.dumps(json_payload, indent=2) if json_payload else None
|
| 294 |
|
| 295 |
except Exception as e:
|
| 296 |
error_msg = f"""β **Error during detection:**
|
ui/shared_interface.py
CHANGED
|
@@ -177,7 +177,8 @@ def create_interface(
|
|
| 177 |
summary_output = gr.Markdown(label="Detection Summary")
|
| 178 |
|
| 179 |
with gr.Accordion("Raw Results (JSON)", open=False):
|
| 180 |
-
json_output = gr.
|
|
|
|
| 181 |
|
| 182 |
with gr.Accordion("API Quickstart", open=False):
|
| 183 |
api_docs = gr.Markdown(
|
|
|
|
| 177 |
summary_output = gr.Markdown(label="Detection Summary")
|
| 178 |
|
| 179 |
with gr.Accordion("Raw Results (JSON)", open=False):
|
| 180 |
+
json_output = gr.Code(label="Detections JSON", language="json")
|
| 181 |
+
|
| 182 |
|
| 183 |
with gr.Accordion("API Quickstart", open=False):
|
| 184 |
api_docs = gr.Markdown(
|