|
import gradio as gr |
|
from transformers import pipeline |
|
from huggingface_hub import hf_hub_download |
|
import json |
|
import numpy as np |
|
|
|
|
|
model_repo = "KhadijaAsehnoune12/LeafDiseaseDetector" |
|
config_filename = "config.json" |
|
|
|
|
|
config_path = hf_hub_download(repo_id=model_repo, filename=config_filename) |
|
|
|
|
|
with open(config_path, "r", encoding="utf-8") as f: |
|
config = json.load(f) |
|
|
|
|
|
pipe = pipeline(task="image-classification", model=model_repo) |
|
|
|
|
|
def predict(image): |
|
|
|
predictions = pipe(image) |
|
|
|
predicted_index = predictions[0]['label'] |
|
|
|
label_name = config["id2label"][str(predicted_index)] |
|
|
|
confidence_score = predictions[0]['score'] |
|
return f"{label_name} ({confidence_score:.2f})" |
|
|
|
|
|
iface = gr.Interface(fn=predict, |
|
inputs=gr.inputs.Image(type="numpy"), |
|
outputs=gr.outputs.Textbox(), |
|
title="Orange Disease Image Classification", |
|
description="Detect diseases in orange leaves and fruits.", |
|
examples=[np.random.rand(224, 224, 3)]) |
|
|
|
|
|
iface.launch() |
|
|