robin0307 commited on
Commit
e61a121
1 Parent(s): 69571b6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -12
app.py CHANGED
@@ -15,7 +15,7 @@ import pandas as pd
15
  from mmocr.utils.ocr import MMOCR
16
  import os
17
 
18
- def inference(img, det, recog):
19
  print(datetime.datetime.now(), 'start')
20
  # ocr = MMOCR(det='PS_CTW', recog='SAR', kie='SDMGR')
21
  # ocr = MMOCR(det=det, recog=recog, kie='SDMGR')
@@ -25,16 +25,11 @@ def inference(img, det, recog):
25
  recog = None
26
  ocr = MMOCR(det=det, recog=recog)
27
  print(datetime.datetime.now(), 'start read:', img.name)
28
- # results = ocr.readtext(img.name, details=True, output='/tmp')
29
- # result_file = '/tmp/out_{}.png'.format(os.path.splitext(os.path.basename(img.name))[0])
30
- # print(datetime.datetime.now(), results)
31
- # # return result_file, pd.DataFrame(results[0]['result']).iloc[: , 2:]
32
- # return result_file, results
33
- results = ocr.readtext(img.name, details=True, output=None)
34
- # result_file = '/tmp/out_{}.png'.format(os.path.splitext(os.path.basename(img.name))[0])
35
  print(datetime.datetime.now(), results)
36
  # return result_file, pd.DataFrame(results[0]['result']).iloc[: , 2:]
37
- return img.name, results
38
 
39
  description = 'Gradio demo for MMOCR. MMOCR is an open-source toolbox based on PyTorch and mmdetection for text detection, text recognition, and the corresponding downstream tasks including key information extraction. To use it, simply upload your image or click one of the examples to load them. Read more at the links below.'
40
  article = "<p style='text-align: center'><a href='https://mmocr.readthedocs.io/en/latest/'>MMOCR is an open-source toolbox based on PyTorch and mmdetection for text detection, text recognition, and the corresponding downstream tasks including key information extraction.</a> | <a href='https://github.com/open-mmlab/mmocr'>Github Repo</a></p>"
@@ -86,7 +81,7 @@ recog = gr.inputs.Dropdown(choices=[
86
  ], type="value", default='SAR', label='recog')
87
 
88
  gr.Interface(inference,
89
- [gr.inputs.Image(type='file', label='Input'), det, recog ],
90
  # [gr.outputs.Image(type='pil', label='Output'), gr.outputs.Dataframe(headers=['text', 'text_score', 'label', 'label_score'])],
91
  [gr.outputs.Image(type='pil', label='Output'), gr.outputs.Textbox(type='str', label='Prediction')],
92
  title='MMOCR',
@@ -94,5 +89,5 @@ gr.Interface(inference,
94
  article=article,
95
  examples=examples,
96
  css=".output_image, .input_image {height: 40rem !important; width: 100% !important;}",
97
- enable_queue=True
98
- ).launch(debug=True, server_name='0.0.0.0', server_port=7860)
 
15
  from mmocr.utils.ocr import MMOCR
16
  import os
17
 
18
+ def inference(img, is_det, det, recog):
19
  print(datetime.datetime.now(), 'start')
20
  # ocr = MMOCR(det='PS_CTW', recog='SAR', kie='SDMGR')
21
  # ocr = MMOCR(det=det, recog=recog, kie='SDMGR')
 
25
  recog = None
26
  ocr = MMOCR(det=det, recog=recog)
27
  print(datetime.datetime.now(), 'start read:', img.name)
28
+ results = ocr.readtext(img.name, details=True, output='/tmp')
29
+ result_file = '/tmp/out_{}.png'.format(os.path.splitext(os.path.basename(img.name))[0])
 
 
 
 
 
30
  print(datetime.datetime.now(), results)
31
  # return result_file, pd.DataFrame(results[0]['result']).iloc[: , 2:]
32
+ return result_file, results
33
 
34
  description = 'Gradio demo for MMOCR. MMOCR is an open-source toolbox based on PyTorch and mmdetection for text detection, text recognition, and the corresponding downstream tasks including key information extraction. To use it, simply upload your image or click one of the examples to load them. Read more at the links below.'
35
  article = "<p style='text-align: center'><a href='https://mmocr.readthedocs.io/en/latest/'>MMOCR is an open-source toolbox based on PyTorch and mmdetection for text detection, text recognition, and the corresponding downstream tasks including key information extraction.</a> | <a href='https://github.com/open-mmlab/mmocr'>Github Repo</a></p>"
 
81
  ], type="value", default='SAR', label='recog')
82
 
83
  gr.Interface(inference,
84
+ [gr.inputs.Image(type='file', label='Input'), "checkbox", det, recog ],
85
  # [gr.outputs.Image(type='pil', label='Output'), gr.outputs.Dataframe(headers=['text', 'text_score', 'label', 'label_score'])],
86
  [gr.outputs.Image(type='pil', label='Output'), gr.outputs.Textbox(type='str', label='Prediction')],
87
  title='MMOCR',
 
89
  article=article,
90
  examples=examples,
91
  css=".output_image, .input_image {height: 40rem !important; width: 100% !important;}",
92
+ enable_queue=False
93
+ ).launch(debug=True)