Spaces:
Sleeping
Sleeping
maslionok
commited on
Commit
Β·
08efe9a
1
Parent(s):
b7849eb
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"β¨ Processed Result
|
| 74 |
|
| 75 |
except Exception as e:
|
| 76 |
print("β Pipeline error:", e)
|
|
@@ -110,9 +110,10 @@ 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 |
scale=10
|
| 117 |
)
|
| 118 |
info_btn = gr.Button("Pipeline Info", size="sm", scale=1)
|
|
|
|
| 35 |
|
| 36 |
# Language detection
|
| 37 |
if 'language' in result:
|
| 38 |
+
output_lines.append(f"π **Language:** {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} **Quality Score:** {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"π€ **Model:** {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"β
**Known tokens ({len(known_tokens)}):** {', '.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"β **Potential OCR errors ({len(unknown_tokens)}):** {', '.join(unknown_tokens)}")
|
| 63 |
elif 'unknown_tokens' in diagnostics:
|
| 64 |
+
output_lines.append("β¨ **No potential OCR errors detected!**")
|
| 65 |
|
| 66 |
# Other fields
|
| 67 |
for key, value in result.items():
|
| 68 |
if key not in ['language', 'score', 'diagnostics']:
|
| 69 |
+
output_lines.append(f"π **{key.replace('_', ' ').title()}:** {value}")
|
| 70 |
|
| 71 |
+
return "\n\n".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.Textbox(
|
| 114 |
label="Analysis Results",
|
| 115 |
+
lines=15,
|
| 116 |
+
placeholder="Results will appear here...",
|
| 117 |
scale=10
|
| 118 |
)
|
| 119 |
info_btn = gr.Button("Pipeline Info", size="sm", scale=1)
|