Commit
•
d4d4818
1
Parent(s):
1f819b1
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,34 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
|
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
+
import json
|
4 |
|
5 |
+
# Load the config.json file
|
6 |
+
config_path = "KhadijaAsehnoune12/LeafDiseaseDetector/config.json" # Update this path
|
7 |
+
with open(config_path, "r", encoding="utf-8") as f:
|
8 |
+
config = json.load(f)
|
9 |
+
|
10 |
+
# Initialize the pipeline
|
11 |
+
pipe = pipeline(task="image-classification", model="KhadijaAsehnoune12/LeafDiseaseDetector")
|
12 |
+
|
13 |
+
# Define a custom prediction function
|
14 |
+
def predict(image):
|
15 |
+
# Get the predictions from the pipeline
|
16 |
+
predictions = pipe(image)
|
17 |
+
# Get the predicted label index
|
18 |
+
predicted_index = predictions[0]['label']
|
19 |
+
# Map the index to the corresponding disease name using id2label
|
20 |
+
label_name = config["id2label"][str(predicted_index)]
|
21 |
+
# Optionally, you can add the confidence score as well
|
22 |
+
confidence_score = predictions[0]['score']
|
23 |
+
return f"{label_name} ({confidence_score:.2f})"
|
24 |
+
|
25 |
+
# Create Gradio interface
|
26 |
+
iface = gr.Interface(fn=predict,
|
27 |
+
inputs=gr.inputs.Image(type="numpy"),
|
28 |
+
outputs="text",
|
29 |
+
title="Orange Disease Image Classification",
|
30 |
+
description="Detect diseases in orange leaves and fruits.",
|
31 |
+
examples=['MoucheB.jpg', 'verdissement.jpg'])
|
32 |
+
|
33 |
+
# Launch the app
|
34 |
+
iface.launch()
|