SWHL commited on
Commit
b8f4c31
·
1 Parent(s): c06e9c3
Files changed (1) hide show
  1. app.py +11 -8
app.py CHANGED
@@ -1,4 +1,5 @@
1
  # -*- encoding: utf-8 -*-
 
2
  import time
3
  from pathlib import Path
4
 
@@ -12,7 +13,7 @@ font_dict = {
12
  'ch': 'FZYTK.TTF',
13
  'japan': 'japan.ttc',
14
  'korean': 'korean.ttf',
15
- 'en': 'FZYTK.TTF'
16
  }
17
 
18
 
@@ -64,13 +65,15 @@ def inference(img_path, box_thresh=0.5, unclip_ratio=1.6, text_score=0.5,
64
  font_path = Path('fonts') / font_dict.get(lan_name)
65
  img_save_path = visualize(img_path, dt_boxes, rec_res, scores,
66
  font_path=str(font_path))
67
- output_text = [f'{one_rec} {float(score):.4f}'
68
- for one_rec, score in zip(rec_res, scores)]
69
- return img_save_path, output_text, out_log
 
 
 
70
 
71
 
72
  if __name__ == '__main__':
73
-
74
  examples = [['images/1.jpg'],
75
  ['images/ch_en_num.jpg'],
76
  ['images/air_ticket.jpg'],
@@ -124,15 +127,15 @@ if __name__ == '__main__':
124
  with gr.Row():
125
  input_img = gr.Image(type='filepath', label='Input')
126
  out_img = gr.Image(type='filepath', label='Output')
 
127
  out_log = gr.outputs.Textbox(type='text', label='Run Log')
128
- out_txt = gr.outputs.Textbox(type='text', label='RecText')
129
  button = gr.Button('Submit')
130
  button.click(fn=inference,
131
  inputs=[input_img, box_thresh, unclip_ratio, text_score,
132
  text_det, text_rec],
133
- outputs=[out_img, out_txt, out_log])
134
  gr.Examples(examples=examples,
135
  inputs=[input_img, box_thresh, unclip_ratio, text_score,
136
  text_det, text_rec],
137
- outputs=[out_img, out_txt, out_log], fn=inference)
138
  demo.launch(debug=True, enable_queue=True)
 
1
  # -*- encoding: utf-8 -*-
2
+ import json
3
  import time
4
  from pathlib import Path
5
 
 
13
  'ch': 'FZYTK.TTF',
14
  'japan': 'japan.ttc',
15
  'korean': 'korean.ttf',
16
+ 'en': 'FZYTK.TTF',
17
  }
18
 
19
 
 
65
  font_path = Path('fonts') / font_dict.get(lan_name)
66
  img_save_path = visualize(img_path, dt_boxes, rec_res, scores,
67
  font_path=str(font_path))
68
+ # output_text = [f'{one_rec} {float(score):.4f}'
69
+ # for one_rec, score in zip(rec_res, scores)]
70
+ out_dict = {i: {'rec_txt': rec, 'score': score}
71
+ for i, (rec, score) in enumerate(zip(rec_res, scores))}
72
+ out_json = json.dumps(out_dict, ensure_ascii=False)
73
+ return img_save_path, out_json, out_log
74
 
75
 
76
  if __name__ == '__main__':
 
77
  examples = [['images/1.jpg'],
78
  ['images/ch_en_num.jpg'],
79
  ['images/air_ticket.jpg'],
 
127
  with gr.Row():
128
  input_img = gr.Image(type='filepath', label='Input')
129
  out_img = gr.Image(type='filepath', label='Output')
130
+ out_json = gr.JSON(label='Rec Res')
131
  out_log = gr.outputs.Textbox(type='text', label='Run Log')
 
132
  button = gr.Button('Submit')
133
  button.click(fn=inference,
134
  inputs=[input_img, box_thresh, unclip_ratio, text_score,
135
  text_det, text_rec],
136
+ outputs=[out_img, out_json, out_log])
137
  gr.Examples(examples=examples,
138
  inputs=[input_img, box_thresh, unclip_ratio, text_score,
139
  text_det, text_rec],
140
+ outputs=[out_img, out_json, out_log], fn=inference)
141
  demo.launch(debug=True, enable_queue=True)