File size: 839 Bytes
0e04e8e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# -*- coding: utf-8 -*-
"""app.ipynb

Automatically generated by Colab.

Original file is located at
    https://colab.research.google.com/drive/1nIR_ak2SXq9fwQmKpq4eupLwQU_SI4fn
"""

import gradio as gr
import torch
import cv2
from ultralytics import YOLO
import numpy as np

model = YOLO("best.torchscript")

def predict(image):
    results = model(image)
    annotated = results[0].plot()
    annotated_rgb = cv2.cvtColor(annotated, cv2.COLOR_BGR2RGB)
    return annotated_rgb

iface = gr.Interface(
    fn=predict,
    inputs=gr.Image(type="numpy", label="Upload an image"),
    outputs=gr.Image(type="numpy", label="Detected image"),
    title="YOLOv8 Object Detection",
    description="Upload an image to detect objects using a YOLOv8 model in TorchScript format.",
    examples=None
)

if __name__ == "__main__":
    iface.launch()