KhadijaAsehnoune12
commited on
Commit
•
fc5c4f6
1
Parent(s):
7bdac5a
Update app.py
Browse files
app.py
CHANGED
@@ -37,52 +37,21 @@ def predict(image):
|
|
37 |
# Get the label name
|
38 |
predicted_label = id2label[str(predicted_class_idx)]
|
39 |
|
40 |
-
# Return the predicted label and confidence score
|
41 |
-
return f"
|
|
|
|
|
|
|
42 |
|
43 |
with gr.Blocks() as demo:
|
44 |
with gr.Row():
|
45 |
img1 = gr.Image(value="maladie_du_dragon_jaune.jpg", elem_id="img1")
|
46 |
img2 = gr.Image(value="mineuse_des_agrumes.jpg", elem_id="img2")
|
47 |
-
|
48 |
with gr.Row():
|
49 |
-
input_img = gr.Image(type="pil", label="Upload an image of a citrus leaf to classify its disease.")
|
50 |
-
output = gr.Textbox(label="
|
51 |
-
|
52 |
btn = gr.Button("Classify")
|
53 |
-
|
54 |
btn.click(fn=predict, inputs=input_img, outputs=output)
|
55 |
|
56 |
-
css = """
|
57 |
-
<style>
|
58 |
-
#img1, #img2 {
|
59 |
-
width: 200px;
|
60 |
-
height: 200px;
|
61 |
-
border: 1px solid black;
|
62 |
-
border-radius: 10px;
|
63 |
-
cursor: pointer;
|
64 |
-
}
|
65 |
-
#img1:hover, #img2:hover {
|
66 |
-
border-color: blue;
|
67 |
-
}
|
68 |
-
</style>
|
69 |
-
"""
|
70 |
-
js = """
|
71 |
-
<script>
|
72 |
-
document.getElementById("img1").addEventListener("dragstart", function(event) {
|
73 |
-
event.dataTransfer.setData("text", event.target.src);
|
74 |
-
});
|
75 |
-
document.getElementById("img2").addEventListener("dragstart", function(event) {
|
76 |
-
event.dataTransfer.setData("text", event.target.src);
|
77 |
-
});
|
78 |
-
document.getElementById("input_img").addEventListener("drop", function(event) {
|
79 |
-
event.preventDefault();
|
80 |
-
var data = event.dataTransfer.getData("text");
|
81 |
-
document.getElementById("input_img").src = data;
|
82 |
-
});
|
83 |
-
</script>
|
84 |
-
"""
|
85 |
-
demo.html(css)
|
86 |
-
demo.html(js)
|
87 |
-
|
88 |
demo.launch(share=True)
|
|
|
37 |
# Get the label name
|
38 |
predicted_label = id2label[str(predicted_class_idx)]
|
39 |
|
40 |
+
# Return the predicted label and confidence score
|
41 |
+
return f"{predicted_label}: {confidence_score:.2f}"
|
42 |
+
|
43 |
+
|
44 |
+
# Create the Gradio interface
|
45 |
|
46 |
with gr.Blocks() as demo:
|
47 |
with gr.Row():
|
48 |
img1 = gr.Image(value="maladie_du_dragon_jaune.jpg", elem_id="img1")
|
49 |
img2 = gr.Image(value="mineuse_des_agrumes.jpg", elem_id="img2")
|
50 |
+
|
51 |
with gr.Row():
|
52 |
+
input_img = gr.Image(type="pil", label="Upload an image of a citrus leaf to classify its disease. The model is trained on the following diseases: Aleurocanthus spiniferus, Chancre citrique, Cochenille blanche, Dépérissement des agrumes, Feuille saine, Jaunissement des feuilles, Maladie de l'oïdium, Maladie du dragon jaune, Mineuse des agrumes, Trou de balle.")
|
53 |
+
output = gr.Textbox(label="Prediction")
|
|
|
54 |
btn = gr.Button("Classify")
|
|
|
55 |
btn.click(fn=predict, inputs=input_img, outputs=output)
|
56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
demo.launch(share=True)
|