Swapnilbpatil commited on
Commit
f757486
·
verified ·
1 Parent(s): 4351f4b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import tensorflow as tf
3
+ from tensorflow.keras.models import load_model
4
+ from tensorflow.keras.preprocessing.image import img_to_array, load_img
5
+ import numpy as np
6
+
7
+ # Load the trained model
8
+ model = load_model('model_final_2.h5')
9
+
10
+ # Define the class names based on your dataset
11
+ class_names = ['Bacterial leaf blight', 'Brown spot', 'Healthy', 'Leaf Blast', 'Leaf scald', 'Narrow Brown Spot']
12
+
13
+ # Streamlit app
14
+ st.title("Rice Leaf Disease Detection")
15
+
16
+ # Image upload
17
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
18
+
19
+ if uploaded_file is not None:
20
+ # Load the image
21
+ image = load_img(uploaded_file, target_size=(299, 299))
22
+
23
+ # Display the image at 50% of the original size
24
+ st.markdown(
25
+ """
26
+ <style>
27
+ img {
28
+ max-width: 50%;
29
+ height: auto;
30
+ }
31
+ </style>
32
+ """,
33
+ unsafe_allow_html=True
34
+ )
35
+ st.image(image, caption='Uploaded Image', use_column_width=False)
36
+
37
+ # Preprocess the image
38
+ image = img_to_array(image)
39
+ image = np.expand_dims(image, axis=0)
40
+ image = image / 255.0
41
+
42
+ # Make predictions
43
+ predictions = model.predict(image)
44
+ predicted_class = np.argmax(predictions, axis=1)
45
+ predicted_class_name = class_names[predicted_class[0]]
46
+
47
+ st.title(f"Detected Diseases: {predicted_class_name}")