Jayanthk2004 commited on
Commit
3c2917b
·
verified ·
1 Parent(s): cb6ce91

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -16
app.py CHANGED
@@ -1,26 +1,36 @@
1
- # prompt: use this model, https://huggingface.co/liriope/PlantDiseaseDetection, create app.py for implementing this on gradio
2
 
3
  import gradio as gr
4
- from transformers import pipeline
 
 
 
 
 
 
5
 
6
- # Load the pre-trained model
7
- pipe = pipeline("image-classification", model="liriope/PlantDiseaseDetection")
8
 
9
- def classify_image(image):
 
10
  predictions = pipe(image)
11
- result = ""
 
 
12
  for pred in predictions:
13
- label = pred["label"]
14
- score = pred["score"]
15
- result += f"{label}: {score:.4f}\n"
16
- return result
17
 
 
18
  iface = gr.Interface(
19
- fn=classify_image,
20
- inputs=gr.Image(type="pil"),
21
- outputs="text",
22
- title="Plant Disease Classifier",
23
- description="Upload an image to classify the plant disease.",
24
  )
25
 
26
- iface.launch(debug=True)
 
 
1
+
2
 
3
  import gradio as gr
4
+ from transformers import pipeline, AutoImageProcessor, AutoModelForImageClassification
5
+ from PIL import Image
6
+
7
+ # Load the pre-trained model and image processor
8
+ model_name = "Diginsa/Plant-Disease-Detection-Project"
9
+ processor = AutoImageProcessor.from_pretrained(model_name)
10
+ model = AutoModelForImageClassification.from_pretrained(model_name)
11
 
12
+ # Create the prediction pipeline
13
+ pipe = pipeline("image-classification", model=model, image_processor=processor)
14
 
15
+ def predict_disease(image):
16
+ """Predicts the plant disease based on the input image."""
17
  predictions = pipe(image)
18
+
19
+ # Format the predictions for display
20
+ results = []
21
  for pred in predictions:
22
+ results.append(f"{pred['label']}: {pred['score']:.4f}")
23
+
24
+ return "\n".join(results) # Return predictions as a single string
 
25
 
26
+ # Create the Gradio interface
27
  iface = gr.Interface(
28
+ fn=predict_disease,
29
+ inputs=gr.Image(type="pil"), # Input is a PIL Image
30
+ outputs="text", # Output is a text string with predictions
31
+ title="Plant Disease Detection",
32
+ description="Upload an image of a plant to detect potential diseases.",
33
  )
34
 
35
+ # Launch the Gradio interface
36
+ iface.launch()