Spaces:
Running
Running
Add application file
Browse files
app.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import gradio as gr
|
3 |
+
import torch
|
4 |
+
from ultralyticsplus import YOLO, render_result
|
5 |
+
|
6 |
+
def yolov8_func(image,
|
7 |
+
image_size,
|
8 |
+
conf_thresold=0.4,
|
9 |
+
iou_thresold=0.50):
|
10 |
+
|
11 |
+
# Load the YOLOv8 model
|
12 |
+
model = YOLO('/content/runs/detect/train/weights/best.pt') # Use your custom model path here
|
13 |
+
|
14 |
+
# Make predictions
|
15 |
+
result = model.predict(image, conf=conf_thresold, iou=iou_thresold, imgsz=image_size)
|
16 |
+
|
17 |
+
# Access and print object detection results
|
18 |
+
box = result[0].boxes
|
19 |
+
print("Object type: ", box.cls)
|
20 |
+
print("Confidence: ", box.conf)
|
21 |
+
print("Coordinates: ", box.xyxy)
|
22 |
+
|
23 |
+
# Render and return the result
|
24 |
+
render = render_result(model=model, image=image, result=result[0])
|
25 |
+
return render
|
26 |
+
|
27 |
+
# Define inputs for the Gradio app
|
28 |
+
inputs = [
|
29 |
+
gr.Image(type="filepath", label="Input Image"),
|
30 |
+
gr.Slider(minimum=320, maximum=1280, step=32, value=640, label="Image Size"),
|
31 |
+
gr.Slider(minimum=0, maximum=1, step=0.05, value=0.25, label="Confidence Threshold"),
|
32 |
+
gr.Slider(minimum=0, maximum=1, step=0.05, value=0.45, label="IOU Threshold")
|
33 |
+
]
|
34 |
+
|
35 |
+
# Define the output for the Gradio app
|
36 |
+
outputs = gr.Image(type="filepath", label="Output Image")
|
37 |
+
|
38 |
+
# Set the title of the Gradio app
|
39 |
+
title = "YOLOv8: An Object Detection for Acne"
|
40 |
+
|
41 |
+
# Create the Gradio interface
|
42 |
+
yolo_app = gr.Interface(fn=yolov8_func,
|
43 |
+
inputs=inputs,
|
44 |
+
outputs=outputs,
|
45 |
+
title=title)
|
46 |
+
|
47 |
+
# Launch the app
|
48 |
+
yolo_app.launch(debug=True)
|