import torch
import gradio as gr
from huggingface_hub import hf_hub_download
from PIL import Image
REPO_ID = "owaiskha9654/Yolov7_Custom_Object_Detection"
FILENAME = "best.pt"
yolov7_custom_weights = hf_hub_download(repo_id=REPO_ID, filename=FILENAME)
model = torch.hub.load('Owaiskhan9654/yolov7-1:main',model='custom', path_or_model=yolov7_custom_weights, force_reload=True) # My Github repository https://github.com/Owaiskhan9654
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 Kaggle Link
Trainable bag-of-freebies sets new state-of-the-art for real-time object detectors
1st class is for Person Detected
2nd class is for Car Detected"
Footer = (
"Model Trained by: Owais Ahmad Data Scientist at Thoucentric Visit Profile
"
" Model Trained Kaggle Kernel Link
"
" Kaggle Profile Link
"
" HuggingFace🤗 Model Deployed Repository Link
"
)
examples1=[["Image1.jpeg"],["Image2.jpeg"],["Image3.jpeg"],["Image4.jpeg"],["Image5.jpeg"],["Image6.jpeg"],["horses.jpeg"],["horses.jpeg"]]
Top_Title="Yolov7 🚀 Custom Trained by Owais Ahmad 🚗Car and 👦Person Detection"
css = ".output-image, .input-image {height: 50rem !important; width: 100% !important;}"
css = ".image-preview {height: auto !important;}"
gr.Interface(
fn=object_detection,
inputs=image,
outputs=outputs,
title=Top_Title,
description=Custom_description,
article=Footer,
examples=[["car-person-2.jpg"], ["car-person-2.jpg"]]).launch()