Spaces:
Sleeping
Sleeping
File size: 1,585 Bytes
97afc34 e6c16b3 4ad9d2a cbac881 97afc34 e6c16b3 d2a4763 e6c16b3 d2a4763 e6c16b3 97afc34 b00892e 97afc34 cc749dd b00892e 4ad9d2a 97afc34 d2a4763 d14a3a9 cc749dd 97afc34 d14a3a9 cf9246c d14a3a9 cc749dd 5d7a51d b00892e 7ddfbe4 97afc34 b72a262 b00892e 7ddfbe4 b72a262 c3f9ae7 |
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 44 45 46 47 48 |
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)
|