Update app.py
Browse files
app.py
CHANGED
|
@@ -1,61 +1,70 @@
|
|
| 1 |
-
from helper.model import fetch_model, preprocess_image, classify_image
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
st.
|
| 12 |
-
|
| 13 |
-
st.
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
"VGNet +
|
| 36 |
-
"VGNet +
|
| 37 |
-
"VGNet +
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
)
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from helper.model import fetch_model, preprocess_image, classify_image
|
| 2 |
+
from PIL import Image
|
| 3 |
+
import streamlit as st
|
| 4 |
+
import io
|
| 5 |
+
|
| 6 |
+
st.set_page_config(
|
| 7 |
+
page_title="VGNet Prototype",
|
| 8 |
+
page_icon="🤖",
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
st.title("Using Deep Learning Techniques on Philippine Corn Leaf Disease Classification")
|
| 12 |
+
st.write("This is the prototype of VGNet model trained using different optimizers")
|
| 13 |
+
st.write("Thesis Project by Group BDK of Mapua University")
|
| 14 |
+
|
| 15 |
+
st.image(
|
| 16 |
+
"resources/corn-field.png",
|
| 17 |
+
caption='A corn field',
|
| 18 |
+
width=700
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
st.header("How to use?")
|
| 22 |
+
st.markdown("""
|
| 23 |
+
1. Select a model.
|
| 24 |
+
2. Select an image (Leaf Blight, Gray Leaf Spot, Common Rust).
|
| 25 |
+
3. Upload the selected image here.
|
| 26 |
+
4. The model will output the classification result if the image is (Leaf Blight, Gray Leaf Spot, Common Rust).
|
| 27 |
+
""")
|
| 28 |
+
|
| 29 |
+
uploaded_image = st.file_uploader(
|
| 30 |
+
"Choose an image...",
|
| 31 |
+
type=["bmp", "png", "jpg", "jpeg"]
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
model_labels = [
|
| 35 |
+
"VGNet + Adam",
|
| 36 |
+
"VGNet + Adan",
|
| 37 |
+
"VGNet + AdamW",
|
| 38 |
+
"VGNet + RMSprop",
|
| 39 |
+
"VGNet + AdaBound"
|
| 40 |
+
]
|
| 41 |
+
model_option = st.selectbox(
|
| 42 |
+
"Select a Model:",
|
| 43 |
+
list(range(len(model_labels))),
|
| 44 |
+
format_func=lambda ind: model_labels[ind]
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
# Check if an image was uploaded
|
| 49 |
+
if uploaded_image is not None:
|
| 50 |
+
|
| 51 |
+
# Preprocess the image
|
| 52 |
+
image = preprocess_image(
|
| 53 |
+
Image.open(
|
| 54 |
+
io.BytesIO(
|
| 55 |
+
uploaded_image
|
| 56 |
+
)
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
# Fetch the model
|
| 62 |
+
model_optimizer_name = ["adam", "adan", "adamw", "rmsprop", "adabound"]
|
| 63 |
+
model = fetch_model(model_optimizer_name[model_option])
|
| 64 |
+
|
| 65 |
+
# Perform classification
|
| 66 |
+
predicted_label = classify_image(model, image)
|
| 67 |
+
|
| 68 |
+
# Display Prediction Result
|
| 69 |
+
st.image(image)
|
| 70 |
+
st.write(f"Prediction Results: {predicted_label}")
|