linhdo commited on
Commit
0148d3c
·
1 Parent(s): 1d33aef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -18
app.py CHANGED
@@ -15,7 +15,7 @@ BOX_PADDING = 2
15
  DETECTION_MODEL = YOLO("models/detector-model.pt")
16
  CLASSIFICATION_MODEL = YOLO("models/classifier-model.pt") # 0: block, 1: checked, 2: unchecked
17
 
18
- def detect(image):
19
  """
20
  Output inference image with bounding box
21
 
@@ -24,6 +24,10 @@ def detect(image):
24
 
25
  Return: image with bounding boxes drawn
26
  """
 
 
 
 
27
  # Predict on image
28
  results = DETECTION_MODEL.predict(source=image, conf=0.2, iou=0.8) # Predict on image
29
  boxes = results[0].boxes # Get bounding boxes
@@ -76,20 +80,4 @@ def detect(image):
76
  iface = gr.Interface(fn=detect,
77
  inputs=gr.inputs.Image(label="Upload scanned document", type="filepath"),
78
  outputs="image")
79
- iface.launch()
80
-
81
-
82
-
83
-
84
-
85
-
86
-
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
-
95
-
 
15
  DETECTION_MODEL = YOLO("models/detector-model.pt")
16
  CLASSIFICATION_MODEL = YOLO("models/classifier-model.pt") # 0: block, 1: checked, 2: unchecked
17
 
18
+ def detect(image_path):
19
  """
20
  Output inference image with bounding box
21
 
 
24
 
25
  Return: image with bounding boxes drawn
26
  """
27
+ image = cv2.imread(image_path)
28
+ if image is None:
29
+ return image
30
+
31
  # Predict on image
32
  results = DETECTION_MODEL.predict(source=image, conf=0.2, iou=0.8) # Predict on image
33
  boxes = results[0].boxes # Get bounding boxes
 
80
  iface = gr.Interface(fn=detect,
81
  inputs=gr.inputs.Image(label="Upload scanned document", type="filepath"),
82
  outputs="image")
83
+ iface.launch()