Spaces:
Sleeping
Sleeping
File size: 1,782 Bytes
97afc34 e6c16b3 4ad9d2a 97afc34 e6c16b3 97afc34 e6c16b3 97afc34 cc749dd 97afc34 cc749dd 97afc34 4ad9d2a 97afc34 4ad9d2a cc749dd 97afc34 cc749dd 97afc34 cc749dd 97afc34 cc749dd 4ad9d2a cc749dd 5d7a51d 97afc34 cc749dd 97afc34 cc749dd 97afc34 cc749dd c3f9ae7 cc749dd c3f9ae7 97afc34 cc749dd 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 49 50 51 52 53 54 55 56 57 58 59 60 61 |
import gradio as gr
from huggingface_hub import hf_hub_download
import os
import cv2 # Import OpenCV
# Function to download models from Hugging Face
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("merve/yolov9", filename="gelan-c-seg.pt", local_dir="./")
return local_model_path
def yolov9_inference(img_path):
"""
Perform inference on an image using the YOLOv9 model.
:param img_path: Path to the image file.
:return: Output image with detections.
"""
# Load the image from the file path
image = cv2.imread(img_path) # Use OpenCV to read the image
# Load the model
model_path = download_models("gelan-c-seg.pt")
model = cv2.dnn.readNetFromDarknet(model_path)
# Perform inference
# (Add your inference code here)
# Optionally, show detection bounding boxes on image
output_image = image # Placeholder for the output image
return output_image
def app():
with gr.Blocks():
with gr.Row():
with gr.Column():
img_path = gr.Image(type="file", label="Upload Image")
inference_button = gr.Button(label="Run Inference")
with gr.Column():
output_image = gr.Image(label="Output Image")
inference_button.click(
fn=yolov9_inference,
inputs=[img_path],
outputs=[output_image],
)
gradio_app = gr.Interface(
app,
title="YOLOv9 Inference",
description="Perform object detection using the YOLOv9 model.",
)
gradio_app.launch(debug=True)
|