Spaces:
Sleeping
Sleeping
Luis J Camargo commited on
Commit ·
5dab21c
1
Parent(s): d125128
attempt to serialize
Browse files
app.py
CHANGED
|
@@ -89,10 +89,35 @@ def inference(img):
|
|
| 89 |
|
| 90 |
try:
|
| 91 |
result = model_manager.infer(img)
|
| 92 |
-
|
|
|
|
| 93 |
if not result or len(result) == 0:
|
| 94 |
return "No text detected in the image."
|
| 95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
# Extract only the text content from PaddleOCRVL result
|
| 97 |
extracted_texts = []
|
| 98 |
|
|
@@ -111,7 +136,7 @@ def inference(img):
|
|
| 111 |
return "No text could be extracted from the image."
|
| 112 |
|
| 113 |
# Join all text blocks with double newlines
|
| 114 |
-
return "\n\n".join(extracted_texts)
|
| 115 |
|
| 116 |
except Exception as e:
|
| 117 |
import traceback
|
|
@@ -147,11 +172,13 @@ examples = [
|
|
| 147 |
|
| 148 |
example_labels = """
|
| 149 |
### Example Images:
|
| 150 |
-
| Image | Language |
|
| 151 |
|-------|----------|-------------|
|
| 152 |
| cco.jpg | Comaltepec Chinantec | Classical Nahuatl text with traditional glyphs |
|
| 153 |
| cnt.jpg | Tepetotutla Chiantec | Contemporary Maya writing with diacritics |
|
| 154 |
| cuc.jpg | Usila Chinantec | Zapotec text from Oaxaca region |
|
|
|
|
|
|
|
| 155 |
"""
|
| 156 |
|
| 157 |
css = ".output_image, .input_image {height: 40rem !important; width: 100% !important;} .output_markdown {min-height: 30rem !important;}"
|
|
|
|
| 89 |
|
| 90 |
try:
|
| 91 |
result = model_manager.infer(img)
|
| 92 |
+
print(result)
|
| 93 |
+
|
| 94 |
if not result or len(result) == 0:
|
| 95 |
return "No text detected in the image."
|
| 96 |
|
| 97 |
+
# Debug: Print full result as JSON to see structure
|
| 98 |
+
import json
|
| 99 |
+
|
| 100 |
+
def serialize_for_json(obj):
|
| 101 |
+
"""Convert non-serializable objects to strings"""
|
| 102 |
+
if isinstance(obj, dict):
|
| 103 |
+
return {k: serialize_for_json(v) for k, v in obj.items()}
|
| 104 |
+
elif isinstance(obj, list):
|
| 105 |
+
return [serialize_for_json(item) for item in obj]
|
| 106 |
+
elif hasattr(obj, '__dict__'):
|
| 107 |
+
return serialize_for_json(obj.__dict__)
|
| 108 |
+
elif isinstance(obj, (str, int, float, bool, type(None))):
|
| 109 |
+
return obj
|
| 110 |
+
else:
|
| 111 |
+
return str(type(obj))
|
| 112 |
+
|
| 113 |
+
serialized_result = serialize_for_json(result)
|
| 114 |
+
json_output = json.dumps(serialized_result, indent=2, ensure_ascii=False)
|
| 115 |
+
|
| 116 |
+
return f"```json\n{json_output}\n```"
|
| 117 |
+
|
| 118 |
+
""" if not result or len(result) == 0:
|
| 119 |
+
return "No text detected in the image."
|
| 120 |
+
|
| 121 |
# Extract only the text content from PaddleOCRVL result
|
| 122 |
extracted_texts = []
|
| 123 |
|
|
|
|
| 136 |
return "No text could be extracted from the image."
|
| 137 |
|
| 138 |
# Join all text blocks with double newlines
|
| 139 |
+
return "\n\n".join(extracted_texts) """
|
| 140 |
|
| 141 |
except Exception as e:
|
| 142 |
import traceback
|
|
|
|
| 172 |
|
| 173 |
example_labels = """
|
| 174 |
### Example Images:
|
| 175 |
+
| Image | Language | Text |
|
| 176 |
|-------|----------|-------------|
|
| 177 |
| cco.jpg | Comaltepec Chinantec | Classical Nahuatl text with traditional glyphs |
|
| 178 |
| cnt.jpg | Tepetotutla Chiantec | Contemporary Maya writing with diacritics |
|
| 179 |
| cuc.jpg | Usila Chinantec | Zapotec text from Oaxaca region |
|
| 180 |
+
| maj.jpg | Mazatec, Jalapa de Díaz | Kui xi já maña̱ xi ngakjá ku̱a̱kúya ni xi ts'e̱ Nti̱a̱ná. Kj'a̱í ni xi ku̱a̱kúyanu̱u, kui xi ts'i̱ínkatsúnnu̱u. Najmi ts'i̱ínkie yjoho̱ nga Nda̱ Nti̱a̱ná xi ts'asjejihi̱n. B'a̱ ts'ín ki̱tsa̱ ts'i̱ín nibánehe̱ ra̱ yjoho̱ nga n'e̱kje. Nkjin xi i̱ncha ts'i̱ín ni xi i̱ncha ts'ín jóo̱, ni xi tu̱ subahá maná. |
|
| 181 |
+
| mir.jpg | Isthmus Mixe | Cab jaduhṉ yhahixøꞌøy coo jaꞌa naam̱dägøꞌøbä tiúnät wiindsǿṉ maa jaꞌa Diostøjcän, coo jaduhṉ ñäꞌä niguiumayǿøjät. |
|
| 182 |
"""
|
| 183 |
|
| 184 |
css = ".output_image, .input_image {height: 40rem !important; width: 100% !important;} .output_markdown {min-height: 30rem !important;}"
|