product-defects / app.py
rrighart's picture
blocks
0ba3470
raw history blame
No virus
1.22 kB
import gradio as gr
import os
import torch
def update_value(val):
return f'Value is set to {val}'
def yolov7_inference(
image: gr.Image = None,
conf_threshold: gr.Slider = 0.20,
):
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
path = 'y7-prdef.pt'
model = torch.hub.load("WongKinYiu/yolov7","custom",f"{path}")
model.conf = conf_threshold
results = model([image], size=640)
return results.render()[0]
demo = gr.Blocks()
with demo:
dd = gr.Interface(
yolov7_inference,
gr.Image(type="pil"),
"image",
title="The detection of jar lid defects using Yolov7",
examples=[
os.path.join(os.path.dirname(__file__), "example1.JPG"),
os.path.join(os.path.dirname(__file__), "example2.JPG"),
os.path.join(os.path.dirname(__file__), "example3.JPG"),
],
)
md = gr.Markdown("Confidence Threshold")
conf_threshold = gr.Slider(minimum=0, maximum=1, step=0.1, label='Value')
#inp = gr.Slider(minimum=0.0, maximum=1.0, value=0.2, step=0.05, label="Value"),
#inp.change(fn=yolov7_inference, inputs=inp, outputs=md)
conf_threshold.change(fn=update_value, inputs=conf_threshold, outputs=md)
demo.launch()