Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,7 +9,7 @@ easyocr_reader = easyocr.Reader(['en'])
|
|
| 9 |
# Tesseract uses pytesseract directly
|
| 10 |
|
| 11 |
def get_metrics(model):
|
| 12 |
-
#
|
| 13 |
if model == "EasyOCR":
|
| 14 |
return {"Accuracy": "95%", "Precision": "94%", "Pipeline": "Easy Integration (90%)"}
|
| 15 |
elif model == "Tesseract":
|
|
@@ -18,15 +18,23 @@ def get_metrics(model):
|
|
| 18 |
return {}
|
| 19 |
|
| 20 |
def ocr_all(img, ground_truth):
|
|
|
|
|
|
|
| 21 |
img_array = np.array(img)
|
| 22 |
|
| 23 |
-
# EasyOCR
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
| 26 |
metrics_easy = get_metrics("EasyOCR")
|
| 27 |
|
| 28 |
-
# Tesseract
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
| 30 |
metrics_tess = get_metrics("Tesseract")
|
| 31 |
|
| 32 |
output_easy = f"**Output:**\n{text_easy}\n\n" + "\n".join([f"{k}: {v}" for k,v in metrics_easy.items()])
|
|
@@ -35,10 +43,10 @@ def ocr_all(img, ground_truth):
|
|
| 35 |
return output_easy, output_tess
|
| 36 |
|
| 37 |
with gr.Blocks() as demo:
|
| 38 |
-
gr.Markdown("#
|
| 39 |
with gr.Row():
|
| 40 |
-
img_in = gr.Image(type="pil", label="Screenshot")
|
| 41 |
-
txt_in = gr.Textbox(lines=4, label="Ground Truth Text Here")
|
| 42 |
btn = gr.Button("Run OCR")
|
| 43 |
with gr.Row():
|
| 44 |
out_easy = gr.Markdown(label="EasyOCR Output")
|
|
|
|
| 9 |
# Tesseract uses pytesseract directly
|
| 10 |
|
| 11 |
def get_metrics(model):
|
| 12 |
+
# Simulated fixed metrics
|
| 13 |
if model == "EasyOCR":
|
| 14 |
return {"Accuracy": "95%", "Precision": "94%", "Pipeline": "Easy Integration (90%)"}
|
| 15 |
elif model == "Tesseract":
|
|
|
|
| 18 |
return {}
|
| 19 |
|
| 20 |
def ocr_all(img, ground_truth):
|
| 21 |
+
if img is None:
|
| 22 |
+
return "No image provided", "No image provided"
|
| 23 |
img_array = np.array(img)
|
| 24 |
|
| 25 |
+
# EasyOCR processing
|
| 26 |
+
try:
|
| 27 |
+
result_easy = easyocr_reader.readtext(img_array, detail=0, paragraph=True)
|
| 28 |
+
text_easy = "\n".join(result_easy)
|
| 29 |
+
except Exception as e:
|
| 30 |
+
text_easy = f"EasyOCR Error: {str(e)}"
|
| 31 |
metrics_easy = get_metrics("EasyOCR")
|
| 32 |
|
| 33 |
+
# Tesseract processing
|
| 34 |
+
try:
|
| 35 |
+
text_tess = pytesseract.image_to_string(img)
|
| 36 |
+
except Exception as e:
|
| 37 |
+
text_tess = f"Tesseract Error: {str(e)}"
|
| 38 |
metrics_tess = get_metrics("Tesseract")
|
| 39 |
|
| 40 |
output_easy = f"**Output:**\n{text_easy}\n\n" + "\n".join([f"{k}: {v}" for k,v in metrics_easy.items()])
|
|
|
|
| 43 |
return output_easy, output_tess
|
| 44 |
|
| 45 |
with gr.Blocks() as demo:
|
| 46 |
+
gr.Markdown("# OCR Model Comparison Demo\nUpload a screenshot image and optionally paste ground-truth text.")
|
| 47 |
with gr.Row():
|
| 48 |
+
img_in = gr.Image(type="pil", label="Upload Screenshot Image")
|
| 49 |
+
txt_in = gr.Textbox(lines=4, label="Paste Ground Truth Text Here")
|
| 50 |
btn = gr.Button("Run OCR")
|
| 51 |
with gr.Row():
|
| 52 |
out_easy = gr.Markdown(label="EasyOCR Output")
|