import gradio as gr from transformers import pipeline import json # Load the config.json file config_path = "KhadijaAsehnoune12/LeafDiseaseDetector/config.json" # Update this path with open(config_path, "r", encoding="utf-8") as f: config = json.load(f) # Initialize the pipeline pipe = pipeline(task="image-classification", model="KhadijaAsehnoune12/LeafDiseaseDetector") # Define a custom prediction function def predict(image): # Get the predictions from the pipeline predictions = pipe(image) # Get the predicted label index predicted_index = predictions[0]['label'] # Map the index to the corresponding disease name using id2label label_name = config["id2label"][str(predicted_index)] # Optionally, you can add the confidence score as well confidence_score = predictions[0]['score'] return f"{label_name} ({confidence_score:.2f})" # Create Gradio interface iface = gr.Interface(fn=predict, inputs=gr.inputs.Image(type="numpy"), outputs="text", title="Orange Disease Image Classification", description="Detect diseases in orange leaves and fruits.", examples=['MoucheB.jpg', 'verdissement.jpg']) # Launch the app iface.launch()