import torch
import gradio as gr
from huggingface_hub import hf_hub_download
from PIL import Image
REPO_ID = "hiraltalsaniya/YOLOv7"
FILENAME = "best.pt"
yolov7_custom_weights = hf_hub_download(repo_id=REPO_ID, filename=FILENAME,repo_type='space')
model = torch.hub.load('WongKinYiu/yolov7:main',model='custom', path_or_model=yolov7_custom_weights, force_reload=True)
def object_detection(im, size=416):
results = model(im)
results.render()
return Image.fromarray(results.imgs[0])
title = "Yolov7 Custom"
image = gr.inputs.Image(shape=(416, 416), image_mode="RGB", source="upload", label="Upload Image", optional=False)
outputs = gr.outputs.Image(type="pil", label="Output Image")
Custom_description="Custom Training Performed on colab style='text-decoration: underline' target='_blank'>Link