Spaces:
Sleeping
Sleeping
maslionok
commited on
Commit
Β·
b7849eb
1
Parent(s):
d16b939
fix
Browse files
app.py
CHANGED
|
@@ -35,13 +35,13 @@ def process_ocr_qa(text, lang_choice):
|
|
| 35 |
|
| 36 |
# Language detection
|
| 37 |
if 'language' in result:
|
| 38 |
-
output_lines.append(f"π
|
| 39 |
|
| 40 |
# Quality score
|
| 41 |
if 'score' in result:
|
| 42 |
score = result['score']
|
| 43 |
score_emoji = "π’" if score >= 0.8 else "π‘" if score >= 0.5 else "π΄"
|
| 44 |
-
output_lines.append(f"{score_emoji}
|
| 45 |
|
| 46 |
# Diagnostics section
|
| 47 |
if 'diagnostics' in result and result['diagnostics']:
|
|
@@ -49,28 +49,28 @@ def process_ocr_qa(text, lang_choice):
|
|
| 49 |
|
| 50 |
# Model information
|
| 51 |
if 'model_id' in diagnostics:
|
| 52 |
-
output_lines.append(f"π€
|
| 53 |
|
| 54 |
# Known tokens
|
| 55 |
if 'known_tokens' in diagnostics and diagnostics['known_tokens']:
|
| 56 |
known_tokens = diagnostics['known_tokens']
|
| 57 |
-
output_lines.append(f"β
|
| 58 |
|
| 59 |
# Unknown tokens (potential OCR errors)
|
| 60 |
if 'unknown_tokens' in diagnostics and diagnostics['unknown_tokens']:
|
| 61 |
unknown_tokens = diagnostics['unknown_tokens']
|
| 62 |
-
output_lines.append(f"β
|
| 63 |
elif 'unknown_tokens' in diagnostics:
|
| 64 |
-
output_lines.append("β¨
|
| 65 |
|
| 66 |
# Other fields
|
| 67 |
for key, value in result.items():
|
| 68 |
if key not in ['language', 'score', 'diagnostics']:
|
| 69 |
-
output_lines.append(f"π
|
| 70 |
|
| 71 |
-
return "
|
| 72 |
else:
|
| 73 |
-
return f"β¨
|
| 74 |
|
| 75 |
except Exception as e:
|
| 76 |
print("β Pipeline error:", e)
|
|
@@ -110,10 +110,9 @@ with gr.Blocks(title="OCR QA Demo") as demo:
|
|
| 110 |
|
| 111 |
with gr.Column():
|
| 112 |
with gr.Row():
|
| 113 |
-
output = gr.
|
| 114 |
label="Analysis Results",
|
| 115 |
-
|
| 116 |
-
placeholder="Results will appear here...",
|
| 117 |
scale=10
|
| 118 |
)
|
| 119 |
info_btn = gr.Button("Pipeline Info", size="sm", scale=1)
|
|
|
|
| 35 |
|
| 36 |
# Language detection
|
| 37 |
if 'language' in result:
|
| 38 |
+
output_lines.append(f"π <b>Language:</b> {result['language']}")
|
| 39 |
|
| 40 |
# Quality score
|
| 41 |
if 'score' in result:
|
| 42 |
score = result['score']
|
| 43 |
score_emoji = "π’" if score >= 0.8 else "π‘" if score >= 0.5 else "π΄"
|
| 44 |
+
output_lines.append(f"{score_emoji} <b>Quality Score:</b> {score:.1f}")
|
| 45 |
|
| 46 |
# Diagnostics section
|
| 47 |
if 'diagnostics' in result and result['diagnostics']:
|
|
|
|
| 49 |
|
| 50 |
# Model information
|
| 51 |
if 'model_id' in diagnostics:
|
| 52 |
+
output_lines.append(f"π€ <b>Model:</b> {diagnostics['model_id']}")
|
| 53 |
|
| 54 |
# Known tokens
|
| 55 |
if 'known_tokens' in diagnostics and diagnostics['known_tokens']:
|
| 56 |
known_tokens = diagnostics['known_tokens']
|
| 57 |
+
output_lines.append(f"β
<b>Known tokens ({len(known_tokens)}):</b> {', '.join(known_tokens)}")
|
| 58 |
|
| 59 |
# Unknown tokens (potential OCR errors)
|
| 60 |
if 'unknown_tokens' in diagnostics and diagnostics['unknown_tokens']:
|
| 61 |
unknown_tokens = diagnostics['unknown_tokens']
|
| 62 |
+
output_lines.append(f"β <b>Potential OCR errors ({len(unknown_tokens)}):</b> {', '.join(unknown_tokens)}")
|
| 63 |
elif 'unknown_tokens' in diagnostics:
|
| 64 |
+
output_lines.append("β¨ <b>No potential OCR errors detected!</b>")
|
| 65 |
|
| 66 |
# Other fields
|
| 67 |
for key, value in result.items():
|
| 68 |
if key not in ['language', 'score', 'diagnostics']:
|
| 69 |
+
output_lines.append(f"π <b>{key.replace('_', ' ').title()}:</b> {value}")
|
| 70 |
|
| 71 |
+
return "<br><br>".join(output_lines)
|
| 72 |
else:
|
| 73 |
+
return f"β¨ Processed Result: {result}"
|
| 74 |
|
| 75 |
except Exception as e:
|
| 76 |
print("β Pipeline error:", e)
|
|
|
|
| 110 |
|
| 111 |
with gr.Column():
|
| 112 |
with gr.Row():
|
| 113 |
+
output = gr.HTML(
|
| 114 |
label="Analysis Results",
|
| 115 |
+
value="<p style='color: #666;'>Results will appear here...</p>",
|
|
|
|
| 116 |
scale=10
|
| 117 |
)
|
| 118 |
info_btn = gr.Button("Pipeline Info", size="sm", scale=1)
|