import gradio as gr import torch ############# 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] inputs = [ gr.Image(type="filepath", label="Input"), gr.Slider(minimum=0.0, maximum=1.0, value=0.2, step=0.05, label="Confidence Threshold", interactive=True), ] outputs = [ gr.Image(type="filepath"), ] css = ".output_image {height: 40rem !important; width: 100% !important;}" demo = gr.Interface( fn=yolov7_inference, inputs=inputs, outputs=outputs, title="The detection of jar lid defects using Yolov7", description = """ This application is detecting damaged jar lids. Type of damages include deformations, holes or scratches. The object detection notebook can be found at Kaggle Contact: Ruthger Righart Email: rrighart@googlemail.com Web: www.rrighart.com """, article = "

Webpage

Kaggle

", examples = [['example1.JPG'], ['example2.JPG'], ['example3.JPG']], #examples = [['example1.JPG', 0.50], ['example2.JPG', 0.50], ['example3.JPG', 0.50]], css=css, cache_examples=True, ) demo.queue().launch(server_name="0.0.0.0", server_port=7860, debug=False, inline=True)