ombhojane commited on
Commit
a4429fb
·
1 Parent(s): a422426

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -13
app.py CHANGED
@@ -1,22 +1,37 @@
1
  import streamlit as st
 
2
  from transformers import pipeline
3
 
4
- # Load the Hugging Face model
5
- model = pipeline("image-classification", model="models/ombhojane/healthyPlantsModel")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
- # Create a Streamlit app
8
- st.title("Plant Disease Detection")
9
 
10
- # Add a file uploader to allow the user to upload an image
11
- uploaded_file = st.file_uploader("Upload an image of your plant")
12
 
13
- # If the user has uploaded an image, make a prediction
14
- if uploaded_file is not None:
15
- prediction = model(uploaded_file)
16
 
17
  # Display the prediction
18
- st.write("Prediction:")
19
- st.text(prediction[0]["label"])
20
 
21
- else:
22
- st.write("Please upload an image of your plant")
 
1
  import streamlit as st
2
+
3
  from transformers import pipeline
4
 
5
+ pipe = pipeline("image-classification", model="ombhojane/healthyPlantsModel")
6
+
7
+ def predict_disease(image):
8
+ """Predicts the disease of a plant from an image.
9
+
10
+ Args:
11
+ image: A NumPy array representing the image.
12
+
13
+ Returns:
14
+ A string representing the predicted disease.
15
+ """
16
+
17
+ prediction = pipe(image)
18
+ label = prediction[0]["label"]
19
+ return label
20
+
21
+ def main():
22
+ """Creates the Streamlit app."""
23
 
24
+ st.title("Plant Disease Detection App")
 
25
 
26
+ # Upload an image
27
+ image = st.file_uploader("Upload an image of a plant")
28
 
29
+ # Predict the disease
30
+ if image is not None:
31
+ disease = predict_disease(image)
32
 
33
  # Display the prediction
34
+ st.markdown(f"Predicted disease: {disease}")
 
35
 
36
+ if __name__ == "__main__":
37
+ main()