Spaces:
Running
Running
RizwanMunawar
commited on
Commit
·
21a46ed
1
Parent(s):
6501158
add model support
Browse files
app.py
CHANGED
|
@@ -1,41 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import PIL.Image as Image
|
| 3 |
-
|
| 4 |
-
from ultralytics import ASSETS, YOLO
|
| 5 |
-
|
| 6 |
-
model = YOLO("yolov8n.pt")
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
def predict_image(img, conf_threshold, iou_threshold):
|
| 10 |
-
"""Predicts objects in an image using a YOLOv8 model with adjustable confidence and IOU thresholds."""
|
| 11 |
-
results = model.predict(
|
| 12 |
-
source=img,
|
| 13 |
-
conf=conf_threshold,
|
| 14 |
-
iou=iou_threshold,
|
| 15 |
-
show_labels=True,
|
| 16 |
-
show_conf=True,
|
| 17 |
-
imgsz=640,
|
| 18 |
-
)
|
| 19 |
-
|
| 20 |
-
for r in results:
|
| 21 |
-
im_array = r.plot()
|
| 22 |
-
im = Image.fromarray(im_array[..., ::-1])
|
| 23 |
-
|
| 24 |
-
return im
|
| 25 |
-
|
| 26 |
-
iface = gr.Interface(
|
| 27 |
-
fn=predict_image,
|
| 28 |
-
inputs=[
|
| 29 |
-
gr.Image(type="pil", label="Upload Image"),
|
| 30 |
-
gr.Slider(minimum=0, maximum=1, value=0.25, label="Confidence threshold"),
|
| 31 |
-
gr.Slider(minimum=0, maximum=1, value=0.45, label="IoU threshold"),
|
| 32 |
-
],
|
| 33 |
-
outputs=gr.Image(type="pil", label="Result"),
|
| 34 |
-
title="Ultralytics Gradio Application 🚀",
|
| 35 |
-
description="Upload images for inference. The Ultralytics YOLOv8n model is used by default.",
|
| 36 |
-
examples=[
|
| 37 |
-
[ASSETS / "bus.jpg", 0.25, 0.45],
|
| 38 |
-
[ASSETS / "zidane.jpg", 0.25, 0.45],
|
| 39 |
-
],
|
| 40 |
-
)
|
| 41 |
-
iface.launch(share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|