Dishaa01423 commited on
Commit
0046556
1 Parent(s): a7cdf78

Upload 4 files

Browse files
Files changed (4) hide show
  1. app.py +69 -0
  2. gitattributes +3 -0
  3. gitignore +1 -0
  4. requirements.txt +6 -0
app.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ from PIL import Image
4
+ import tensorflow as tf
5
+ import tensorflow_hub as hub
6
+ from tensorflow.keras import layers
7
+ from tensorflow.keras.models import load_model
8
+
9
+ # Print versions for debugging
10
+ st.write("TensorFlow version:", tf.__version__)
11
+
12
+ # model
13
+ out_len = 10 # Replace this with the actual number of output classes
14
+
15
+ # Ensure no conflicts with 'model' or 'load_model'
16
+ model_path = 'tomato_model'
17
+
18
+ # Load your pre-trained model
19
+ try:
20
+ VIT = load_model(model_path)
21
+ st.write("Model loaded successfully")
22
+ except Exception as e:
23
+ st.error(f"Error loading model: {e}")
24
+
25
+ # Define the class names
26
+ class_names = [
27
+ 'Tomato_Bacterial_spot', 'Tomato_Early_blight', 'Tomato_Late_blight',
28
+ 'Tomato_Leaf_Mold', 'Tomato_Septoria_leaf_spot', 'Tomato_Spider_mites_Two_spotted_spider_mite',
29
+ 'Tomato_Target_Spot', 'Tomato_Tomato_Yellow_Leaf_Curl_Virus',
30
+ 'Tomato_Tomato_mosaic_virus', 'Tomato_healthy'
31
+ ]
32
+
33
+ # Function to load and preprocess the image
34
+ def load_and_prep_image(image):
35
+ try:
36
+ img = image.resize((224, 224)) # Assuming your model expects 224x224 images
37
+ img = np.array(img) / 255.0 # Normalize the image
38
+ img = np.expand_dims(img, axis=0) # Add batch dimension
39
+ return img
40
+ except Exception as e:
41
+ st.error(f"Error preprocessing image: {e}")
42
+ return None
43
+
44
+ # Streamlit app
45
+ st.title("Tomato Disease Detection")
46
+ st.write("Upload an image of a tomato leaf to detect the disease.")
47
+
48
+ # File uploader
49
+ uploaded_file = st.file_uploader("Choose an image...", type="jpg")
50
+
51
+ if uploaded_file is not None:
52
+ try:
53
+ # Display the uploaded image
54
+ image = Image.open(uploaded_file)
55
+ st.image(image, caption='Uploaded Image', use_column_width=True)
56
+
57
+ # Preprocess the image
58
+ prepped_image = load_and_prep_image(image)
59
+
60
+ # Ensure the model is loaded and image is preprocessed before making a prediction
61
+ if VIT is not None and prepped_image is not None:
62
+ # Make prediction
63
+ prediction = VIT.predict(prepped_image)
64
+ predicted_class = class_names[np.argmax(prediction)]
65
+
66
+ # Display the prediction
67
+ st.write(f"Prediction: {predicted_class}")
68
+ except Exception as e:
69
+ st.error(f"Error during prediction: {e}")
gitattributes ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ *.pb filter=lfs diff=lfs merge=lfs -text
2
+ variables.data-00000-of-00001 filter=lfs diff=lfs merge=lfs -text
3
+ variables.index filter=lfs diff=lfs merge=lfs -text
gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ /venv
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ numpy==1.26.4
2
+ pandas==2.2.2
3
+ pillow==10.3.0
4
+ streamlit==1.35.0
5
+ tensorflow==2.14.0
6
+ tensorflow-hub==0.16.1