KhadijaAsehnoune12 commited on
Commit
543d7d6
·
verified ·
1 Parent(s): c1508e5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -9
app.py CHANGED
@@ -22,6 +22,20 @@ id2label = {
22
  "9": "Trou de balle"
23
  }
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  def predict(image):
26
  # Preprocess the image
27
  inputs = feature_extractor(images=image, return_tensors="pt")
@@ -40,8 +54,9 @@ def predict(image):
40
  # Return the predicted label and confidence score
41
  return predicted_label, f"Confidence: {confidence_score:.2f}"
42
 
43
- gr.Markdown("""
44
-
 
45
  <h1>Citrus Leaf Disease Classification</h1>
46
  <p>Upload an image of a citrus leaf to classify its disease.</p>
47
  <p>Supported diseases:</p>
@@ -57,11 +72,13 @@ gr.Markdown("""
57
  <li>Mineuse des agrumes</li>
58
  <li>Trou de balle</li>
59
  </ul>
60
-
61
  """)
62
- # Create the Gradio interface
63
- image = gr.Image(type="pil")
64
- label = gr.Textbox(label="Prediction")
65
-
66
- gr.Interface(fn=predict, inputs=image, outputs=label, title="Citrus Disease Classification",
67
- description="Upload an image of a citrus leaf to classify its disease.").launch(share=True)
 
 
 
22
  "9": "Trou de balle"
23
  }
24
 
25
+ # Define the image slider with examples of each disease
26
+ image_slider = [
27
+ {"image": "aleurocanthus_spiniferus.jpg", "label": "Aleurocanthus spiniferus"},
28
+ {"image": "chancre_citrique.jpg", "label": "Chancre citrique"},
29
+ {"image": "cochenille_blanche.jpg", "label": "Cochenille blanche"},
30
+ {"image": "deperissement_des_agrumes.jpg", "label": "Dépérissement des agrumes"},
31
+ {"image": "feuille_saine.jpg", "label": "Feuille saine"},
32
+ {"image": "jaunissement_des_feuilles.jpg", "label": "Jaunissement des feuilles"},
33
+ {"image": "maladie_de_loidium.jpg", "label": "Maladie de l'oïdium"},
34
+ {"image": "maladie_du_dragon_jaune.jpg", "label": "Maladie du dragon jaune"},
35
+ {"image": "mineuse_des_agrumes.jpg", "label": "Mineuse des agrumes"},
36
+ {"image": "trou_de_balle.jpg", "label": "Trou de balle"}
37
+ ]
38
+
39
  def predict(image):
40
  # Preprocess the image
41
  inputs = feature_extractor(images=image, return_tensors="pt")
 
54
  # Return the predicted label and confidence score
55
  return predicted_label, f"Confidence: {confidence_score:.2f}"
56
 
57
+ # Create the Gradio interface
58
+ with gr.Blocks() as demo:
59
+ gr.Markdown("""
60
  <h1>Citrus Leaf Disease Classification</h1>
61
  <p>Upload an image of a citrus leaf to classify its disease.</p>
62
  <p>Supported diseases:</p>
 
72
  <li>Mineuse des agrumes</li>
73
  <li>Trou de balle</li>
74
  </ul>
75
+ <p>Example images:</p>
76
  """)
77
+ image_slider_component = gr.Gallery(image_slider, label="Example Images")
78
+ image_input = gr.Image(type="pil", label="Upload Image")
79
+ label_output = gr.Textbox(label="Prediction")
80
+ btn = gr.Button("Classify")
81
+
82
+ btn.click(fn=predict, inputs=image_input, outputs=label_output)
83
+
84
+ demo.launch()