File size: 1,078 Bytes
0198a7e | 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 | # -*- coding: utf-8 -*-
"""day1deployobjectdetection.ipynb
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/drive/1CwEhyaDiq5FTGAq5PgIHhd1K_mZygEub
"""
from ultralytics import YOLO
import cv2
import time
import gradio as gr
from PIL import Image
import numpy as np
# create the model
model = YOLO("yolov8n.pt")
# create function to detect the image
def detectImage(image):
# if the image is none, then skip it
if image is None:
return None
# get the result
results = model.predict(source=image, save=False)
# create the boxes
resultImage = results[0].plot()
return Image.fromarray(resultImage)
# create the website application
app = gr.Interface(
fn=detectImage,
inputs=gr.Image(type="numpy", label="just upload the some random image"),
outputs=gr.Image(type="pil", label="the result of the object detection goes here"),
title="my object detection using yolo",
description="just upload a random image and then wait until the object detection result show"
)
app.launch(debug=True) |