Spaces:
Running on Zero
Running on Zero
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -61,8 +61,12 @@ def recognize_text(image):
|
|
| 61 |
if not results:
|
| 62 |
return "No text recognized", 0.0, ""
|
| 63 |
|
| 64 |
-
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
raw = json.dumps(results, ensure_ascii=False, indent=2)
|
| 67 |
return text, float(score), raw
|
| 68 |
except Exception as e:
|
|
|
|
| 61 |
if not results:
|
| 62 |
return "No text recognized", 0.0, ""
|
| 63 |
|
| 64 |
+
# Results may be nested under a "res" key
|
| 65 |
+
first = results[0]
|
| 66 |
+
if "res" in first:
|
| 67 |
+
first = first["res"]
|
| 68 |
+
text = first.get("rec_text", "")
|
| 69 |
+
score = first.get("rec_score", 0.0)
|
| 70 |
raw = json.dumps(results, ensure_ascii=False, indent=2)
|
| 71 |
return text, float(score), raw
|
| 72 |
except Exception as e:
|