Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,42 +1,38 @@
|
|
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 |
-
|
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 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
26 |
|
27 |
iface = gr.Interface(
|
28 |
fn=predict_image,
|
29 |
inputs=[
|
30 |
gr.Image(type="pil", label="Upload Image"),
|
31 |
-
# gr.Slider(minimum=0, maximum=1, value=0.25, label="Confidence threshold"),
|
32 |
-
# gr.Slider(minimum=0, maximum=1, value=0.45, label="IoU threshold"),
|
33 |
],
|
34 |
-
outputs=gr.
|
35 |
title="GP Wolf Classifier",
|
36 |
-
description="Upload images for
|
37 |
examples=[
|
38 |
-
[ASSETS / "gp.jpg"
|
39 |
-
[ASSETS / "wolf.jpg"
|
40 |
],
|
41 |
)
|
42 |
|
|
|
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 |
+
"""Classifies an image using a YOLOv8 model."""
|
|
|
9 |
results = model.predict(
|
10 |
source=img,
|
|
|
|
|
|
|
|
|
11 |
imgsz=640,
|
12 |
+
conf=0.25, # You can adjust this confidence threshold
|
13 |
)
|
14 |
+
|
15 |
+
# Get the top prediction
|
16 |
+
if results and len(results[0].boxes) > 0:
|
17 |
+
top_prediction = results[0].boxes[0]
|
18 |
+
class_id = int(top_prediction.cls)
|
19 |
+
confidence = float(top_prediction.conf)
|
20 |
+
class_name = model.names[class_id]
|
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.Text(label="Classification Result"),
|
31 |
title="GP Wolf Classifier",
|
32 |
+
description="Upload images for classification.",
|
33 |
examples=[
|
34 |
+
[ASSETS / "https://huggingface.co/spaces/gpbhupinder/test/blob/main/gp.jpg"],
|
35 |
+
[ASSETS / "https://huggingface.co/spaces/gpbhupinder/test/blob/main/wolf.jpg"],
|
36 |
],
|
37 |
)
|
38 |
|