Spaces:
Runtime error
Runtime error
Update app.py
Browse files12345678910111213141516import gradio as grimport torchfrom ultralytics import YOLO# Load YOLO modelmodel = YOLO("yolov9c-seg.pt")# Define function to perform predictiondef predict_image(image):result = model.predict(image, show=True, save=True)return result# Create Gradio interfaceimage_input = gr.inputs.Image()gr.Interface(predict_image, image_input, "image").launch()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990import gradio as grfrom ultralytics import YOLO# Define function to perform prediction with YOLOv9 modeldef predict_image(image, model_path, image_size, conf_threshold, iou_threshold):# Load YOLO modelmodel = YOLO(model_path)# Perform inference with YOLO modelresults = model(image, size=image_size, conf=conf_threshold, iou=iou_threshold)# Render the outputoutput_image = results.render()return output_image[0]# Define Gradio interfacedef app():with gr.Blocks():with gr.Row():with gr.Column():img_path = gr.Image(type="filepath", label="Image")model_path = gr.Dropdown(label="Model",choices=["yolov9c-seg.pt","yolov5m.pt","yolov5l.pt","yolov5x.pt",],value="yolov5s.pt",)image_size = gr.Slider(label="Image Size",minimum=320,maximum=1280,step=32,value=640,)conf_threshold = gr.Slider(label="Confidence Threshold",minimum=0.1,maximum=1.0,step=0.1,value=0.4,)iou_threshold = gr.Slider(label="IoU Threshold",minimum=0.1,maximum=1.0,step=0.1,value=0.5,)yolov9_infer = gr.Button(value="Submit")with gr.Column():output_numpy = gr.Image(type="numpy", label="Output")yolov9_infer.click(fn=predict_image,inputs=[img_path,model_path,image_size,conf_threshold,iou_threshold,],outputs=[output_numpy],)gradio_app = gr.Blocks()with gradio_app:gr.HTML("""<h1 style='text-align: center'>YOLOv9 Base Model</h1>""")gr.HTML("""<h3 style='text-align: center'></h3>""")with gr.Row():with gr.Column():app()gradio_app.launch(debug=True)
app.py+84-10