napatswift commited on
Commit
baaae8c
1 Parent(s): 9472f8c

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +4 -20
main.py CHANGED
@@ -22,30 +22,14 @@ def get_rec(points):
22
  return (min(xs), min(ys)), (max(xs), max(ys))
23
 
24
 
25
- def predict(image_input, score_threshold):
26
- draw_img = image_input.copy()
27
- print('image shape', image_input.shape, file=sys.stderr)
28
-
29
- try:
30
- return ocr.readtext(image_input)
31
- except:
32
- output = dict(det_polygons=[], det_scores=[])
33
-
34
- polygons = output['det_polygons']
35
- scores = output['det_scores']
36
- for polygon, score in zip(polygons, scores):
37
- if score < score_threshold:
38
- continue
39
- p0, p1 = get_rec([int(i) for i in polygon])
40
- draw_img = cv2.rectangle(draw_img, p0, p1, (255,0,0), 2)
41
-
42
- return draw_img, output
43
 
44
  def run():
45
  demo = gr.Interface(
46
  fn=predict,
47
- inputs=[gr.components.Image(), gr.Slider(0, 1, 0.8)],
48
- outputs=[gr.components.Image(), gr.JSON()],
49
  )
50
 
51
  demo.launch(server_name="0.0.0.0", server_port=7860)
 
22
  return (min(xs), min(ys)), (max(xs), max(ys))
23
 
24
 
25
+ def predict(image_input):
26
+ return ocr.readtext(image_input)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
  def run():
29
  demo = gr.Interface(
30
  fn=predict,
31
+ inputs=gr.components.Image(),
32
+ outputs=gr.JSON(),
33
  )
34
 
35
  demo.launch(server_name="0.0.0.0", server_port=7860)