import gradio as gr import cv2 from ultralytics import YOLO from huggingface_hub import hf_hub_download # Download YOLOv8 weights from Hugging Face weights_path = hf_hub_download( repo_id="foduucom/plant-leaf-detection-and-classification", filename="best.pt" ) # Load YOLOv8 model model = YOLO(weights_path) # Prediction function def predict(image): img = cv2.cvtColor(image, cv2.COLOR_RGB2BGR) # convert for YOLO results = model(img) result_img = results[0].plot() result_img = cv2.cvtColor(result_img, cv2.COLOR_BGR2RGB) return result_img # Gradio interface iface = gr.Interface( fn=predict, inputs=gr.Image(type="numpy"), # simple upload outputs=gr.Image(type="numpy"), title="Plant Leaf Detection & Classification", description="Upload a plant leaf image to detect diseases and classify leaves." ) iface.launch()