Spaces:
Sleeping
Sleeping
File size: 915 Bytes
d66a307 c58389b d66a307 c58389b 8c8a124 c58389b 8c8a124 c58389b d66a307 c58389b d40a79b d66a307 c58389b d66a307 c58389b | 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 | import torch
import gradio as gr
from PIL import Image
import io
# Load the YOLOv5 model
model = torch.hub.load('ultralytics/yolov5', 'custom', path='fire.pt') # Load custom model
def detect_objects(image):
# Run the YOLOv5 model
results = model(image)
# Save the results image
results_image = results.render()[0] # Render returns a list, we take the first element
# Convert the numpy array result to an image
results_image = Image.fromarray(results_image)
# Save to a buffer
buf = io.BytesIO()
results_image.save(buf, format='JPEG')
byte_im = buf.getvalue()
return results_image
# Gradio interface
interface = gr.Interface(
fn=detect_objects,
inputs=gr.Image(type="pil"),
outputs=gr.Image(type="pil"),
title="YOLOv5 Image Detection",
description="Upload an image to detect objects using YOLOv5."
)
# Launch the Gradio app
interface.launch() |