dwililiya commited on
Commit
68aa7ad
·
verified ·
1 Parent(s): 9a18b51

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ from torchvision import transforms
4
+ from PIL import Image
5
+
6
+ # Load the model using Hugging Face pipeline
7
+ MODEL_NAME = "dwililiya/sugarcane-plant-diseases-classification"
8
+ classifier = pipeline("image-classification", model=MODEL_NAME)
9
+
10
+ # Define class names based on your dataset
11
+ class_names = ['Bacterial Blight', 'Healthy', 'Mosaic', 'Red Rot', 'Rust', 'Yellow']
12
+
13
+ def predict(image):
14
+ # Use the classifier to predict
15
+ predictions = classifier(image)
16
+
17
+ # Get the predicted class and confidence score
18
+ predicted_class = predictions[0]['label']
19
+ confidence = predictions[0]['score']
20
+
21
+ return predicted_class, confidence
22
+
23
+ # Gradio interface
24
+ iface = gr.Interface(
25
+ fn=predict,
26
+ inputs=gr.inputs.Image(type="file", label="Upload Sugarcane Leaf Image"),
27
+ outputs=[gr.outputs.Label(num_top_classes=1, label="Predicted Class"),
28
+ gr.outputs.Textbox(label="Confidence Score")],
29
+ title="Sugarcane Plant Diseases Classification",
30
+ description="Upload an image of a sugarcane leaf to classify its disease.",
31
+ )
32
+
33
+ if __name__ == "__main__":
34
+ iface.launch()