Spaces:
Build error
Build error
Delete app.py
Browse files
app.py
DELETED
@@ -1,64 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from ultralyticsplus import YOLO, render_result
|
3 |
-
|
4 |
-
|
5 |
-
def yoloV8_func(image: gr.inputs.Image = None,
|
6 |
-
image_size: gr.inputs.Slider = 640,
|
7 |
-
conf_threshold: gr.inputs.Slider = 0.4,
|
8 |
-
iou_threshold: gr.inputs.Slider = 0.50):
|
9 |
-
"""This function performs YOLOv8 object detection on the given image.
|
10 |
-
|
11 |
-
Args:
|
12 |
-
image (gr.inputs.Image, optional): Input image to detect objects on. Defaults to None.
|
13 |
-
image_size (gr.inputs.Slider, optional): Desired image size for the model. Defaults to 640.
|
14 |
-
conf_threshold (gr.inputs.Slider, optional): Confidence threshold for object detection. Defaults to 0.4.
|
15 |
-
iou_threshold (gr.inputs.Slider, optional): Intersection over Union threshold for object detection. Defaults to 0.50.
|
16 |
-
"""
|
17 |
-
# Load the YOLOv8 model from the 'best.pt' checkpoint
|
18 |
-
model_path = "best.pt"
|
19 |
-
model = YOLO(model_path)
|
20 |
-
|
21 |
-
# Perform object detection on the input image using the YOLOv8 model
|
22 |
-
results = model.predict(image,
|
23 |
-
conf=conf_threshold,
|
24 |
-
iou=iou_threshold,
|
25 |
-
imgsz=image_size)
|
26 |
-
|
27 |
-
# Print the detected objects' information (class, coordinates, and probability)
|
28 |
-
box = results[0].boxes
|
29 |
-
print("Object type:", box.cls)
|
30 |
-
print("Coordinates:", box.xyxy)
|
31 |
-
print("Probability:", box.conf)
|
32 |
-
|
33 |
-
# Render the output image with bounding boxes around detected objects
|
34 |
-
render = render_result(model=model, image=image, result=results[0])
|
35 |
-
return render
|
36 |
-
|
37 |
-
|
38 |
-
inputs = [
|
39 |
-
gr.inputs.Image(type="filepath", label="Input Image"),
|
40 |
-
gr.inputs.Slider(minimum=320, maximum=1280, default=640,
|
41 |
-
step=32, label="Image Size"),
|
42 |
-
gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.25,
|
43 |
-
step=0.05, label="Confidence Threshold"),
|
44 |
-
gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.45,
|
45 |
-
step=0.05, label="IOU Threshold"),
|
46 |
-
]
|
47 |
-
|
48 |
-
|
49 |
-
outputs = gr.outputs.Image(type="filepath", label="Output Image")
|
50 |
-
|
51 |
-
title = "Water Meter"
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
yolo_app = gr.Interface(
|
56 |
-
fn=yoloV8_func,
|
57 |
-
inputs=inputs,
|
58 |
-
outputs=outputs,
|
59 |
-
title=title,
|
60 |
-
cache_examples=True,
|
61 |
-
)
|
62 |
-
|
63 |
-
# Launch the Gradio interface in debug mode with queue enabled
|
64 |
-
yolo_app.launch(debug=True, enable_queue=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|