import torch
import gradio as gr

model = torch.hub.load("./", "custom", path="best_ffc_11663.pt", source="local")
title = "鸟类视频检测Yolov5模型测试"
desc = "这是一个基于Gradio的Yolov5演示项目，非常方便!"
base_conf, base_iou = 0.5, 0.7


def det_image(img, conf_thres, iou_thres):
    model.conf = conf_thres
    model.iou = iou_thres
    return model(img).render()[0]


# examples中的参数要和inputs中对应
# 获取摄像头拍照检测，修改inputs中的：inputs=[gr.Webcam(),...]就可以了，动态的更新添加属性：live=True
# 如果将launch()更改为launch(share=True)则会将这个代码放在公网进行访问。
gr.Interface(
    # inputs=["image", gr.Slider(minimum=0, maximum=1, value=base_conf), gr.Slider(minimum=0, maximum=1, value=base_iou)],
    inputs=[gr.Webcam(),...],
    outputs=["image"],
    fn=det_image,
    title=title,
    description=desc,
    live=True,
    examples=[["./mydata/test/image/Black_Footed_Albatross_0001_796111.jpg", base_conf, base_iou],
              ["./mydata/test/image/Gadwall_0001_31235.jpg", 0.3, base_iou]]
).launch(share=True)