import gradio as gr from detection import ObjectDetection examples = [ ['test-images/plant1.jpeg', 0.31], ['test-images/plant2.jpeg', 0.51], ['test-images/plant3.webp', 0.39], ] def get_predictions(img, threshold, box_color, text_color): v8_results = yolov8_detector.v8_score_frame(img) v8_frame = yolov8_detector.plot_bboxes(v8_results, img, float(threshold), box_color, text_color) return v8_frame with gr.Blocks(title="Leaf Disease Detection", theme=gr.themes.Monochrome()) as interface: gr.Markdown("# Leaf Disease Detection") with gr.Row(): with gr.Column(): image = gr.Image(shape=(416,416), label="Input Image") with gr.Column(): with gr.Row(): with gr.Column(): box_color = gr.ColorPicker(label="Box Color", value="#0000ff") with gr.Column(): text_color = gr.ColorPicker(label="Prediction Color", value="#ff0000") confidence = gr.Slider(maximum=1, step=0.01, value=0.4, label="Confidence Threshold", interactive=True) btn = gr.Button("Detect") with gr.Row(): with gr.Box(): v8_prediction = gr.Image(shape=(416,416), label="YOLOv8") btn.click( get_predictions, [image, confidence, box_color, text_color], [v8_prediction] ) with gr.Row(): gr.Examples(examples=examples, inputs=[image, confidence]) yolov8_detector = ObjectDetection('yolov8') interface.launch()