Dishaa01423
commited on
Commit
•
bb83e4d
1
Parent(s):
308d960
Delete app.py
Browse files
app.py
DELETED
@@ -1,69 +0,0 @@
|
|
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}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|