Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,37 +1,40 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import PIL.Image as Image
|
|
|
|
| 3 |
from ultralytics import ASSETS, YOLO
|
| 4 |
|
| 5 |
model = YOLO("https://huggingface.co/spaces/gpbhupinder/test/blob/main/model_-%2023%20june%202024%2019_22.pt")
|
| 6 |
|
|
|
|
| 7 |
def predict_image(img):
|
| 8 |
-
"""
|
| 9 |
results = model.predict(
|
| 10 |
source=img,
|
|
|
|
|
|
|
|
|
|
| 11 |
imgsz=640,
|
| 12 |
-
conf=0.25, # You can adjust this confidence threshold
|
| 13 |
)
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
return f"{class_name} (Confidence: {confidence:.2f})"
|
| 22 |
-
else:
|
| 23 |
-
return "No classification made"
|
| 24 |
|
| 25 |
iface = gr.Interface(
|
| 26 |
fn=predict_image,
|
| 27 |
inputs=[
|
| 28 |
gr.Image(type="pil", label="Upload Image"),
|
|
|
|
|
|
|
| 29 |
],
|
| 30 |
-
outputs=gr.
|
| 31 |
title="GP Wolf Classifier",
|
| 32 |
-
description="Upload images for
|
| 33 |
examples=[
|
| 34 |
-
|
| 35 |
["wolf.jpg"],
|
| 36 |
],
|
| 37 |
)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import PIL.Image as Image
|
| 3 |
+
|
| 4 |
from ultralytics import ASSETS, YOLO
|
| 5 |
|
| 6 |
model = YOLO("https://huggingface.co/spaces/gpbhupinder/test/blob/main/model_-%2023%20june%202024%2019_22.pt")
|
| 7 |
|
| 8 |
+
|
| 9 |
def predict_image(img):
|
| 10 |
+
"""Predicts objects in an image using a YOLOv8 model."""
|
| 11 |
results = model.predict(
|
| 12 |
source=img,
|
| 13 |
+
|
| 14 |
+
show_labels=True,
|
| 15 |
+
show_conf=True,
|
| 16 |
imgsz=640,
|
|
|
|
| 17 |
)
|
| 18 |
+
|
| 19 |
+
for r in results:
|
| 20 |
+
im_array = r.plot()
|
| 21 |
+
im = Image.fromarray(im_array[..., ::-1])
|
| 22 |
+
|
| 23 |
+
return im
|
| 24 |
+
|
|
|
|
|
|
|
|
|
|
| 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="GP Wolf Classifier",
|
| 35 |
+
description="Upload images for inference.",
|
| 36 |
examples=[
|
| 37 |
+
["gp.jpg"],
|
| 38 |
["wolf.jpg"],
|
| 39 |
],
|
| 40 |
)
|