praysimanjuntak commited on
Commit
45a33d5
1 Parent(s): a073647

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -33,18 +33,22 @@ def annotate_image(image):
33
  cv2.rectangle(image, (left, top), (right, bottom), (0, 0, 255), 2)
34
  cv2.putText(image, f"{prediction['confidence']:.2f}", (left, top - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
35
 
 
 
 
36
  # Convert the image back to RGB for display in Gradio
37
  image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
38
- return image
 
39
 
40
  # Create the Gradio interface
41
  iface = gr.Interface(
42
  fn=annotate_image,
43
  inputs=gr.Image(type="pil"),
44
- outputs="image",
45
  title="TB-Bacillus Detection",
46
  description="Upload an image to get annotated results from the model."
47
  )
48
 
49
  # Launch the app
50
- iface.launch()
 
33
  cv2.rectangle(image, (left, top), (right, bottom), (0, 0, 255), 2)
34
  cv2.putText(image, f"{prediction['confidence']:.2f}", (left, top - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
35
 
36
+ # Get the number of detections
37
+ detection_count = len(result['predictions'])
38
+
39
  # Convert the image back to RGB for display in Gradio
40
  image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
41
+
42
+ return image, f"Number of detections: {detection_count}"
43
 
44
  # Create the Gradio interface
45
  iface = gr.Interface(
46
  fn=annotate_image,
47
  inputs=gr.Image(type="pil"),
48
+ outputs=["image", "text"],
49
  title="TB-Bacillus Detection",
50
  description="Upload an image to get annotated results from the model."
51
  )
52
 
53
  # Launch the app
54
+ iface.launch()