Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|