Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,36 +1,40 @@
|
|
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 |
-
|
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=
|
|
|
|
|
|
|
34 |
title="GP Wolf Classifier",
|
35 |
description="Upload images for inference.",
|
36 |
examples=[
|
|
|
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 |
"""Predicts objects in an image using a YOLOv8 model."""
|
9 |
results = model.predict(
|
10 |
source=img,
|
|
|
11 |
show_labels=True,
|
12 |
show_conf=True,
|
13 |
imgsz=640,
|
14 |
)
|
15 |
+
|
16 |
for r in results:
|
17 |
im_array = r.plot()
|
18 |
im = Image.fromarray(im_array[..., ::-1])
|
19 |
+
|
20 |
+
# Extract class names and confidences
|
21 |
+
class_names = [model.names[int(cls)] for cls in r.boxes.cls]
|
22 |
+
confidences = r.boxes.conf.tolist()
|
23 |
+
|
24 |
+
# Create a formatted string of results
|
25 |
+
result_text = "\n".join([f"{name}: {conf:.2f}" for name, conf in zip(class_names, confidences)])
|
26 |
+
|
27 |
+
return im, result_text
|
28 |
|
29 |
iface = gr.Interface(
|
30 |
fn=predict_image,
|
31 |
inputs=[
|
32 |
gr.Image(type="pil", label="Upload Image"),
|
|
|
|
|
33 |
],
|
34 |
+
outputs=[
|
35 |
+
gr.Image(type="pil", label="Result"),
|
36 |
+
gr.Textbox(label="Predictions")
|
37 |
+
],
|
38 |
title="GP Wolf Classifier",
|
39 |
description="Upload images for inference.",
|
40 |
examples=[
|