gopiashokan
commited on
Commit
•
b7995af
1
Parent(s):
ca28b01
Update app.py
Browse files
app.py
CHANGED
@@ -1,69 +1,69 @@
|
|
1 |
-
import numpy as np
|
2 |
-
import PIL.Image as Image
|
3 |
-
import tensorflow as tf
|
4 |
-
import streamlit as st
|
5 |
-
from streamlit_extras.add_vertical_space import add_vertical_space
|
6 |
-
from warnings import filterwarnings
|
7 |
-
filterwarnings('ignore')
|
8 |
-
|
9 |
-
|
10 |
-
def streamlit_config():
|
11 |
-
|
12 |
-
# page configuration
|
13 |
-
st.set_page_config(page_title='Classification', layout='centered')
|
14 |
-
|
15 |
-
# page header transparent color
|
16 |
-
page_background_color = """
|
17 |
-
<style>
|
18 |
-
|
19 |
-
[data-testid="stHeader"]
|
20 |
-
{
|
21 |
-
background: rgba(0,0,0,0);
|
22 |
-
}
|
23 |
-
|
24 |
-
</style>
|
25 |
-
"""
|
26 |
-
st.markdown(page_background_color, unsafe_allow_html=True)
|
27 |
-
|
28 |
-
# title and position
|
29 |
-
st.markdown(f'<h1 style="text-align: center;">Potato Disease Classification</h1>',
|
30 |
-
unsafe_allow_html=True)
|
31 |
-
add_vertical_space(4)
|
32 |
-
|
33 |
-
|
34 |
-
# Streamlit Configuration Setup
|
35 |
-
streamlit_config()
|
36 |
-
|
37 |
-
|
38 |
-
def prediction(image_path, class_names=['Potato___Early_blight', 'Potato___Late_blight', 'Potato___healthy']):
|
39 |
-
|
40 |
-
img = Image.open(image_path)
|
41 |
-
img_resized = img.resize((256,256))
|
42 |
-
img_array = tf.keras.preprocessing.image.img_to_array(img_resized)
|
43 |
-
img_array = np.expand_dims(img_array, axis=0)
|
44 |
-
|
45 |
-
model = tf.keras.models.load_model(
|
46 |
-
prediction = model.predict(img_array)
|
47 |
-
|
48 |
-
predicted_class = class_names[np.argmax(prediction)]
|
49 |
-
confidence = round(np.max(prediction)*100, 2)
|
50 |
-
|
51 |
-
add_vertical_space(1)
|
52 |
-
st.markdown(f'<h4 style="color: orange;">Predicted Class : {predicted_class}<br>Confident : {confidence}%</h3>',
|
53 |
-
unsafe_allow_html=True)
|
54 |
-
|
55 |
-
add_vertical_space(1)
|
56 |
-
st.image(img.resize((400,300)))
|
57 |
-
|
58 |
-
|
59 |
-
col1,col2,col3 = st.columns([0.1,0.9,0.1])
|
60 |
-
with col2:
|
61 |
-
input_image = st.file_uploader(label='Upload the Image', type=['jpg', 'jpeg', 'png'])
|
62 |
-
|
63 |
-
|
64 |
-
if input_image is not None:
|
65 |
-
|
66 |
-
col1,col2,col3 = st.columns([0.2,0.8,0.2])
|
67 |
-
with col2:
|
68 |
-
prediction(input_image)
|
69 |
-
|
|
|
1 |
+
import numpy as np
|
2 |
+
import PIL.Image as Image
|
3 |
+
import tensorflow as tf
|
4 |
+
import streamlit as st
|
5 |
+
from streamlit_extras.add_vertical_space import add_vertical_space
|
6 |
+
from warnings import filterwarnings
|
7 |
+
filterwarnings('ignore')
|
8 |
+
|
9 |
+
|
10 |
+
def streamlit_config():
|
11 |
+
|
12 |
+
# page configuration
|
13 |
+
st.set_page_config(page_title='Classification', layout='centered')
|
14 |
+
|
15 |
+
# page header transparent color
|
16 |
+
page_background_color = """
|
17 |
+
<style>
|
18 |
+
|
19 |
+
[data-testid="stHeader"]
|
20 |
+
{
|
21 |
+
background: rgba(0,0,0,0);
|
22 |
+
}
|
23 |
+
|
24 |
+
</style>
|
25 |
+
"""
|
26 |
+
st.markdown(page_background_color, unsafe_allow_html=True)
|
27 |
+
|
28 |
+
# title and position
|
29 |
+
st.markdown(f'<h1 style="text-align: center;">Potato Disease Classification</h1>',
|
30 |
+
unsafe_allow_html=True)
|
31 |
+
add_vertical_space(4)
|
32 |
+
|
33 |
+
|
34 |
+
# Streamlit Configuration Setup
|
35 |
+
streamlit_config()
|
36 |
+
|
37 |
+
|
38 |
+
def prediction(image_path, class_names=['Potato___Early_blight', 'Potato___Late_blight', 'Potato___healthy']):
|
39 |
+
|
40 |
+
img = Image.open(image_path)
|
41 |
+
img_resized = img.resize((256,256))
|
42 |
+
img_array = tf.keras.preprocessing.image.img_to_array(img_resized)
|
43 |
+
img_array = np.expand_dims(img_array, axis=0)
|
44 |
+
|
45 |
+
model = tf.keras.models.load_model('model.h5')
|
46 |
+
prediction = model.predict(img_array)
|
47 |
+
|
48 |
+
predicted_class = class_names[np.argmax(prediction)]
|
49 |
+
confidence = round(np.max(prediction)*100, 2)
|
50 |
+
|
51 |
+
add_vertical_space(1)
|
52 |
+
st.markdown(f'<h4 style="color: orange;">Predicted Class : {predicted_class}<br>Confident : {confidence}%</h3>',
|
53 |
+
unsafe_allow_html=True)
|
54 |
+
|
55 |
+
add_vertical_space(1)
|
56 |
+
st.image(img.resize((400,300)))
|
57 |
+
|
58 |
+
|
59 |
+
col1,col2,col3 = st.columns([0.1,0.9,0.1])
|
60 |
+
with col2:
|
61 |
+
input_image = st.file_uploader(label='Upload the Image', type=['jpg', 'jpeg', 'png'])
|
62 |
+
|
63 |
+
|
64 |
+
if input_image is not None:
|
65 |
+
|
66 |
+
col1,col2,col3 = st.columns([0.2,0.8,0.2])
|
67 |
+
with col2:
|
68 |
+
prediction(input_image)
|
69 |
+
|