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