napatswift commited on
Commit
83c123b
1 Parent(s): f10784f

Add slider

Browse files
Files changed (1) hide show
  1. main.py +9 -3
main.py CHANGED
@@ -16,19 +16,25 @@ def get_rec(points):
16
  return (min(xs), min(ys)), (max(xs), max(ys))
17
 
18
 
19
- def predict(image_input):
20
  draw_img = image_input.copy()
21
  print(image_input.shape)
22
  output = ocr.readtext(image_input)
23
- for polygon in output['det_polygons']:
 
 
 
 
 
24
  p0, p1 = get_rec([int(i) for i in polygon])
25
  draw_img = cv2.rectangle(draw_img, p0, p1, (255,0,0), 2)
 
26
  return draw_img
27
 
28
  def run():
29
  demo = gr.Interface(
30
  fn=predict,
31
- inputs=gr.components.Image(),
32
  outputs=gr.components.Image(),
33
  )
34
 
 
16
  return (min(xs), min(ys)), (max(xs), max(ys))
17
 
18
 
19
+ def predict(image_input, score_threshold):
20
  draw_img = image_input.copy()
21
  print(image_input.shape)
22
  output = ocr.readtext(image_input)
23
+ polygons = output['det_polygons']
24
+ scores = output['det_scores']
25
+ for polygon, score in zip(polygons, scores):
26
+ if score < score_threshold:
27
+ continue
28
+
29
  p0, p1 = get_rec([int(i) for i in polygon])
30
  draw_img = cv2.rectangle(draw_img, p0, p1, (255,0,0), 2)
31
+ draw_img = cv2.putText(draw_img, '%.3f' % score, p0)
32
  return draw_img
33
 
34
  def run():
35
  demo = gr.Interface(
36
  fn=predict,
37
+ inputs=[gr.components.Image(), gr.Slider(0, 1)],
38
  outputs=gr.components.Image(),
39
  )
40