GuchaIll commited on
Commit
22cc8da
·
verified ·
1 Parent(s): 405c78b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -4
app.py CHANGED
@@ -1,7 +1,30 @@
1
  import gradio as gr
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()