Update app.py
Browse files123456789101 unmodified line121314151617181920211 unmodified line23242526272829import gradio as grimport cv2import numpy as npfrom ultralytics import YOLO # Import YOLO from ultralytics# Load the YOLOv5 modelmodel = YOLO('yolov5s') # Use the YOLOv5s pre-trained model# Function to run inference on an imagedef run_inference(image):1 unmodified lineimage = np.array(image)# Run YOLOv5 inferenceresults = model.predict(source=image, save=False, conf=0.25, stream=False)# Annotate the image with detected objectsannotated_image = results[0].plot() # Use YOLO's built-in plotting functionreturn annotated_image1 unmodified lineinterface = gr.Interface(fn=run_inference,inputs=gr.Image(type="pil"),outputs=gr.Image(type="numpy"),title="YOLOv5 Object Detection",description="Upload an image to run YOLOv5 object detection and see the results.")123456789101 unmodified line12131415161718192021221 unmodified line24252627282930import gradio as grimport cv2import torchimport numpy as np# Load the YOLOv5 modelmodel = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True)# Function to run inference on an imagedef run_inference(image):1 unmodified lineimage = np.array(image)# Run YOLOv5 inferenceresults = model(image)# Convert the annotated image from BGR to RGB for displayannotated_image = results.render()[0]annotated_image = cv2.cvtColor(annotated_image, cv2.COLOR_BGR2RGB)return annotated_image1 unmodified lineinterface = gr.Interface(fn=run_inference,inputs=gr.Image(type="pil"),outputs=gr.Image(type="pil"),title="YOLOv5 Object Detection",description="Upload an image to run YOLOv5 object detection and see the results.")
app.py+7-6