import gradio as gr from ultralytics import YOLO from PIL import Image CONF_THRESH=0.332 IOU=0.4 model = YOLO("best.pt") def predict(image): results = model(image, verbose=False, conf=CONF_THRESH, iou=IOU, agnostic_nms=True) results[0].names = {0: 'bee', 1: 'stylopidae', 2: 'meloidae larvae'} bgr_result_img = results[0].plot() rgb_result_img = Image.fromarray(bgr_result_img[..., ::-1]) return rgb_result_img def main(): with gr.Blocks() as demo: gr.HTML("

Deep Learning Based Detection of Bee Parasites under Natural Conditions

") with gr.Row(): image_input = gr.Image(type="pil", label="Upload Image") image_output = gr.Image(label="Prediction") gr.Examples( examples=["stylops.jpeg", "larvae.jpeg"], inputs=image_input ) submit_btn = gr.Button("Detect") submit_btn.click(fn=predict, inputs=image_input, outputs=[image_output]) gr.HTML("""
Sources:
TU Ilmenau """) demo.launch() if __name__ == '__main__': main()