mlbench123 commited on
Commit
4d1a283
·
verified ·
1 Parent(s): f14a1ad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -23
app.py CHANGED
@@ -1,23 +1,33 @@
1
- import gradio as gr
2
- from ultralytics import YOLO
3
-
4
- # Load the YOLO model
5
- model = YOLO('best.pt')
6
-
7
- def predict(img):
8
-
9
- results = model(img)
10
- annotated_frame = results[0].plot()
11
- return annotated_frame
12
-
13
- # Create the Gradio interface
14
- iface = gr.Interface(
15
- fn=predict,
16
- inputs=gr.Image(label="Input Image", type="filepath"),
17
- outputs="image",
18
- title="Rat Paw Detector",
19
- description="Upload an image to detect rat paws"
20
- )
21
-
22
- # Launch the Gradio interface
23
- iface.launch(share=True)
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from ultralytics import YOLO
3
+
4
+ # Load the YOLO model
5
+ model = YOLO('best.pt')
6
+
7
+ def predict(img, confidence_threshold):
8
+ # Perform inference
9
+ results = model(img)
10
+
11
+ # Filter predictions based on the confidence threshold
12
+ # The results[0].boxes.data contains the detection results, including confidence scores
13
+ filtered_boxes = [box for box in results[0].boxes.data if box[4] >= confidence_threshold]
14
+
15
+ # Plot the results (with the filtered detections)
16
+ annotated_frame = results[0].plot(labels=filtered_boxes)
17
+
18
+ return annotated_frame
19
+
20
+ # Create the Gradio interface
21
+ iface = gr.Interface(
22
+ fn=predict,
23
+ inputs=[
24
+ gr.Image(label="Input Image", type="filepath"),
25
+ gr.Slider(minimum=0, maximum=1, default=0.5, label="Confidence Threshold", step=0.01)
26
+ ],
27
+ outputs="image",
28
+ title="Coin Detector",
29
+ description="Upload an image to detect coins. Adjust the confidence threshold to filter results."
30
+ )
31
+
32
+ # Launch the Gradio interface
33
+ iface.launch(share=True)