Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,30 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import yolov5
|
3 |
+
from PIL import Image
|
4 |
|
5 |
+
# Load YOLOv5 model
|
6 |
+
model = yolov5.load("keremberke/yolov5n-garbage")
|
7 |
|
8 |
+
# Set model parameters
|
9 |
+
model.conf = 0.25 # Confidence threshold
|
10 |
+
model.iou = 0.45 # IoU threshold
|
11 |
+
|
12 |
+
def predict(img):
|
13 |
+
# Convert image to PIL format
|
14 |
+
img = Image.fromarray(img)
|
15 |
+
# Perform inference
|
16 |
+
results = model(img, size=640)
|
17 |
+
# Show results
|
18 |
+
results.save(save_dir="results/")
|
19 |
+
return "results/image0.jpg"
|
20 |
+
|
21 |
+
# Gradio UI
|
22 |
+
iface = gr.Interface(
|
23 |
+
fn=predict,
|
24 |
+
inputs=gr.Image(),
|
25 |
+
outputs=gr.Image(),
|
26 |
+
title="Garbage Object Detection",
|
27 |
+
description="Upload an image and the model will detect garbage objects in it."
|
28 |
+
)
|
29 |
+
|
30 |
+
iface.launch()
|