nit454 commited on
Commit
b086098
·
verified ·
1 Parent(s): ee601dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -9
app.py CHANGED
@@ -9,7 +9,7 @@ easyocr_reader = easyocr.Reader(['en'])
9
  # Tesseract uses pytesseract directly
10
 
11
  def get_metrics(model):
12
- # Updated simulated fixed scores without PaddleOCR
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
- result_easy = easyocr_reader.readtext(img_array, detail=0, paragraph=True)
25
- text_easy = "\n".join(result_easy)
 
 
 
26
  metrics_easy = get_metrics("EasyOCR")
27
 
28
- # Tesseract
29
- text_tess = pytesseract.image_to_string(img)
 
 
 
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("# Multi-OCR Model Demo without PaddleOCR\nUpload an image and paste the correct ground-truth text below.")
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")