awacke1 commited on
Commit
ff31c95
1 Parent(s): 2a554f9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -27,14 +27,15 @@ def draw_boxes(image, bounds, color='yellow', width=2):
27
  return image
28
 
29
  # 🔮 The core function that does the OCR wizardry
30
- def inference(img, lang):
31
  # 🕵️‍♂️ Reading the image, please hold...
32
  reader = easyocr.Reader(lang)
33
- bounds = reader.readtext(img.name)
34
- im = Image.open(img.name)
35
  draw_boxes(im, bounds)
36
- im.save('result.jpg')
37
- return ['result.jpg', pd.DataFrame(bounds).iloc[:, 1:]]
 
38
 
39
  # 🚀 Time to set up the Gradio app!
40
  def main():
@@ -57,11 +58,11 @@ def main():
57
 
58
  with gr.Row():
59
  with gr.Column():
60
- img_input = gr.Image(type='file', label='📥 Input Image')
61
  lang_input = gr.CheckboxGroup(choices, value=['en'], label='🗣️ Language(s)')
62
  submit_btn = gr.Button("Start OCR 🕵️‍♂️")
63
  with gr.Column():
64
- img_output = gr.Image(type='file', label='📤 Output Image')
65
  df_output = gr.Dataframe(headers=['Text', 'Confidence'])
66
 
67
  gr.Examples(
 
27
  return image
28
 
29
  # 🔮 The core function that does the OCR wizardry
30
+ def inference(img_path, lang):
31
  # 🕵️‍♂️ Reading the image, please hold...
32
  reader = easyocr.Reader(lang)
33
+ bounds = reader.readtext(img_path)
34
+ im = Image.open(img_path)
35
  draw_boxes(im, bounds)
36
+ result_path = 'result.jpg'
37
+ im.save(result_path)
38
+ return [result_path, pd.DataFrame(bounds).iloc[:, 1:]]
39
 
40
  # 🚀 Time to set up the Gradio app!
41
  def main():
 
58
 
59
  with gr.Row():
60
  with gr.Column():
61
+ img_input = gr.Image(type='filepath', label='📥 Input Image')
62
  lang_input = gr.CheckboxGroup(choices, value=['en'], label='🗣️ Language(s)')
63
  submit_btn = gr.Button("Start OCR 🕵️‍♂️")
64
  with gr.Column():
65
+ img_output = gr.Image(type='filepath', label='📤 Output Image')
66
  df_output = gr.Dataframe(headers=['Text', 'Confidence'])
67
 
68
  gr.Examples(