yolo9 / app.py
Parthebhan's picture
Update app.py
cbac881 verified
raw
history blame
1.59 kB
import gradio as gr
from huggingface_hub import hf_hub_download
import os
import cv2 # Import OpenCV
import gradio.inputs as gr_inputs
def download_models(model_id):
# Check if the model file exists locally
local_model_path = "./gelan-c-seg.pt"
if not os.path.exists(local_model_path):
# Download the model from Hugging Face if it doesn't exist locally
hf_hub_download(model_id, filename="gelan-c-seg.pt", local_dir="./")
return local_model_path
def yolov9_inference(img):
"""
Perform inference on an image using the YOLOv9 model.
:param img: Input image.
:return: Output image with detections.
"""
# Load the model
model_path = download_models("merve/yolov9")
# Assuming you're using a YOLOv9 model from Ultralytics, you would typically use their library to load the model
model = cv2.dnn.readNetFromDarknet(model_path)
# Perform inference
# Placeholder for inference code; replace with your actual inference code
results = model.forward()
# Optionally, show detection bounding boxes on image
output_image = img # Placeholder for output image; replace with your actual output image
return output_image
def app():
return gr.Interface(
fn=yolov9_inference,
inputs=inputs.Image(type="file", label="Image"), # Use inputs.Image instead of gr.inputs.Image
outputs="image",
title="YOLOv9 Inference",
description="Perform object detection using the YOLOv9 model.",
theme="compact"
)
gradio_app = app()
gradio_app.launch(debug=True)