nit454 commited on
Commit
7f4bad9
·
verified ·
1 Parent(s): 9e5b50a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -2,25 +2,25 @@ import gradio as gr
2
  import easyocr
3
  import numpy as np
4
 
5
- # Initialize EasyOCR reader once
6
- reader = easyocr.Reader(['en'])
7
 
8
  def ocr_easy(img):
9
  if img is None:
10
  return "No image uploaded"
11
- # Convert PIL Image to numpy array
12
  img_array = np.array(img)
13
  try:
 
14
  results = reader.readtext(img_array, detail=0, paragraph=True)
15
  return "\n".join(results)
16
  except Exception as e:
17
  return f"EasyOCR Error: {str(e)}"
18
 
19
  with gr.Blocks() as demo:
20
- gr.Markdown("# EasyOCR Demo")
21
  img_input = gr.Image(type="pil", label="Upload Image")
22
  output_text = gr.Textbox(label="OCR Result", lines=10)
23
- button = gr.Button("Run EasyOCR")
24
- button.click(ocr_easy, inputs=[img_input], outputs=[output_text])
25
 
26
  demo.launch()
 
2
  import easyocr
3
  import numpy as np
4
 
5
+ # Initialize EasyOCR reader once with English language
6
+ reader = easyocr.Reader(['en'], gpu=False)
7
 
8
  def ocr_easy(img):
9
  if img is None:
10
  return "No image uploaded"
 
11
  img_array = np.array(img)
12
  try:
13
+ # OCR with detail=0 returns text only, paragraph=True groups lines
14
  results = reader.readtext(img_array, detail=0, paragraph=True)
15
  return "\n".join(results)
16
  except Exception as e:
17
  return f"EasyOCR Error: {str(e)}"
18
 
19
  with gr.Blocks() as demo:
20
+ gr.Markdown("# EasyOCR OCR Demo")
21
  img_input = gr.Image(type="pil", label="Upload Image")
22
  output_text = gr.Textbox(label="OCR Result", lines=10)
23
+ run_button = gr.Button("Run OCR")
24
+ run_button.click(ocr_easy, inputs=img_input, outputs=output_text)
25
 
26
  demo.launch()