# from fastapi import FastAPI, File, UploadFile | |
# from fastapi.responses import StreamingResponse | |
from io import BytesIO | |
import cv2 | |
import numpy as np | |
import gradio as gr | |
from ultralytics import YOLO | |
# Inicializar o modelo YOLO | |
model = YOLO("/content/best.pt") | |
# Definir a função para detecção de objetos | |
def detect_objects(image): | |
# Realizar a detecção de objetos com YOLOv8 | |
detections = model.predict(image) | |
# Renderizar as detecções na imagem | |
rendered_image = detections.render() | |
return rendered_image | |
# Criar a interface Gradio | |
app = gr.Interface( | |
fn=detect_objects, | |
inputs="image", | |
outputs="image", | |
title="YOLOv8 Object Detection", | |
description="Detect objects in images using YOLOv8.", | |
) | |
# Executar o aplicativo | |
app.launch() | |