|
import gradio as gr |
|
import os |
|
import torch |
|
from PIL import Image |
|
|
|
|
|
|
|
|
|
|
|
def load_model(): |
|
''' |
|
Loading hub model & setting the preferences for the model |
|
''' |
|
model = torch.hub.load('ultralytics/yolov5', 'custom', path='Content/best.pt') |
|
model.conf = 0.38 |
|
model.dnn=True |
|
model.agnostic=True |
|
return model |
|
|
|
model=load_model() |
|
|
|
def detect(inp): |
|
|
|
|
|
results = model(inp,size=640) |
|
results.render() |
|
return Image.fromarray(results.ims[0]) |
|
|
|
|
|
inp = gr.Image(type="pil", label="Original Image") |
|
output = gr.Image(type="pil", label="Output Image") |
|
|
|
|
|
io=gr.Interface(fn=detect, inputs=inp, outputs=output, title='Party Symbol Detection',examples=['Content/4.jpg','Content/10.jpg','Content/18.jpg'],theme='peach') |
|
io.launch(debug=True,share=False) |
|
|
|
|
|
|
|
|
|
|