Spaces:
Runtime error
Runtime error
File size: 3,306 Bytes
8c6e404 c6b7528 8c6e404 cc5b992 8c6e404 c6b7528 8c6e404 e47e343 8c6e404 c6b7528 8c6e404 dfb85b7 03ca938 8c6e404 c6b7528 8c6e404 e47e343 8c6e404 66dc4fd 03ca938 7cfd799 03ca938 ee2124c 7cfd799 03ca938 ee2124c 66dc4fd ee2124c 6b85517 cc5b992 ee2124c cc5b992 ee2124c cc5b992 ee2124c fb06bb5 7cfd799 ee2124c 03ca938 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | # Trained on 80 epochs at Batch size 256 with Learning Rate of 0.001 under 50 seconds!!
from PIL import Image, ImageOps
import numpy as np
import pandas as pd
import streamlit as st
import tensorflow as tf
# Suppress warnings
import warnings
warnings.filterwarnings('ignore', category=UserWarning)
warnings.filterwarnings('ignore', category=FutureWarning)
# Disable scientific notation for clarity
np.set_printoptions(suppress=True)
def load_model_teachable():
# Load the model
model = tf.keras.models.load_model("pages/keras_model.h5")
return model
with st.spinner('Model is being loaded..'):
model = load_model_teachable()
st.write("""
# Teachable Machine Model
"""
)
st.sidebar.info("You should be happy if it classifies as - Healthy plant π")
file = st.file_uploader("Upload the image to be classified", type=["jpg", "png"])
st.set_option('deprecation.showfileUploaderEncoding', False)
def upload_predict_teachable(image, model, class_names):
# Create the array of the right shape to feed into the keras model
# The 'length' or number of images you can put into the array is
# determined by the first position in the shape tuple, in this case 1
data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)
# Replace this with the path to your image
image_RGB = image.convert("RGB")
# resizing the image to be at least 224x224 and then cropping from the center
image_resized = image_RGB.resize((224, 224), resample=Image.LANCZOS)
# turn the image into a numpy array
image_array = np.asarray(image_resized)
# Normalize the image
normalized_image_array = (image_array.astype(np.float32) / 127.5) - 1
# Load the image into the array
data[0] = normalized_image_array
# Predicts the model
prediction = model.predict(data)
return prediction
if file is None:
st.text("Please upload an image file")
else:
image = Image.open(file)
st.image(image, use_column_width=True)
# Load the labels
class_names = open("pages/labels.txt", "r").readlines()
prediction = upload_predict_teachable(image, model,class_names)
index = np.argmax(prediction)
class_name = class_names[index]
confidence_score = prediction[0][index]
# Print prediction and confidence score
result = f"Your plant is suffering from: {class_name[2:]}"
result_score = "β
Accurate prediction score is: {} / 100".format("%.2f" % confidence_score)
st.success(result)
st.info(result_score)
st.markdown("""
#### Know more about this disease and suggestions to prevent them from spreading.
- *Just copy the disease name (result) from above & paste it in the below input box as it is!*
""")
# Loading diseases info & management strategies
df = pd.read_csv('pages/Disease_solutions.csv')
disease = st.text_input('Enter the disease name below π', '')
# Selecting rows based on condition
about = df.loc[df['Diseases'] == disease, ['Type', 'Description']]
strategies = df.loc[df['Diseases'] == disease, 'Management Strategies']
# Print diseases' other info
tab1, tab2 = st.tabs(["π Description", "β Solution"])
with tab1:
st.dataframe(about, use_container_width=True)
with tab2:
st.dataframe(strategies, use_container_width=True) |