Add application file
Browse files
app.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from streamlit_option_menu import option_menu
|
3 |
+
# from tensorflow.keras.layers import RandomFlip, RandomRotation, RandomZoom
|
4 |
+
#
|
5 |
+
import tensorflow as tf
|
6 |
+
from tensorflow.keras.models import load_model
|
7 |
+
from tensorflow.keras.preprocessing.image import load_img, img_to_array
|
8 |
+
import numpy as np
|
9 |
+
|
10 |
+
ant_model = load_model("myrmex.h5")
|
11 |
+
|
12 |
+
st.set_page_config(
|
13 |
+
page_title="MyrmexAI", page_icon="π"
|
14 |
+
)
|
15 |
+
|
16 |
+
with st.sidebar:
|
17 |
+
pages = option_menu("",["Intro", "Get started"])
|
18 |
+
st.write("---")
|
19 |
+
st.subheader("Follow me on: ")
|
20 |
+
st.write("π -> [@Anirudh91017141](https://x.com/Anirudh91017141)")
|
21 |
+
st.write("LinkedIn -> [anirudhhegde](https://www.linkedin.com/in/anirudhhegde/)")
|
22 |
+
st.write("GitHub -> [anirudh-hegde](https://www.github.com/anirudh-hegde)")
|
23 |
+
|
24 |
+
if pages == "Intro":
|
25 |
+
st.markdown("<br><br><p style='font-size:26px'><strong>MyrmexAI</strong> is a project based on classification of ant species like"
|
26 |
+
"FireAnts, GhostAnts and WeaverAnts. The model was trained on three datasets using \
|
27 |
+
CNN and custom layers, achieving an accuracy of 87.9%<br><br></p>", unsafe_allow_html=True)
|
28 |
+
st.markdown("<h4>How to get started</h4><br>"
|
29 |
+
"1. Upload the ant image and let the model decide which species it belongs to<br>"
|
30 |
+
"2. The model will predict the ant species for the uploaded image", unsafe_allow_html=True)
|
31 |
+
elif pages == "Get started":
|
32 |
+
title = st.markdown("<h1 style='text-align: center; color: orange; font-size: 6vw'>MyrmexAI π</h1>",
|
33 |
+
unsafe_allow_html=True)
|
34 |
+
upload_img = st.file_uploader("Choose an image")
|
35 |
+
if upload_img:
|
36 |
+
# if st.button(''):
|
37 |
+
img = load_img(upload_img, target_size=(180, 180))
|
38 |
+
img_array = img_to_array(img)
|
39 |
+
img_array = tf.expand_dims(img_array, axis=0)
|
40 |
+
|
41 |
+
predictions = ant_model.predict(img_array)
|
42 |
+
predicted_class = np.argmax(predictions)
|
43 |
+
st.image(upload_img, width=400)
|
44 |
+
# print(predicted_class)
|
45 |
+
if predicted_class == 0:
|
46 |
+
st.markdown("<h1 style='font-size: 1.5vw'>The uploaded image belongs to Fire Ants species</h1>", unsafe_allow_html=True)
|
47 |
+
elif predicted_class == 1:
|
48 |
+
st.markdown("<h1 style='font-size: 1.5vw'>The uploaded image belongs to Ghost Ants species</h1>", unsafe_allow_html=True)
|
49 |
+
elif predicted_class == 2:
|
50 |
+
st.markdown("<h1 style='font-size: 1.5vw'>The uploaded image belongs to Weaver Ants species</h1>", unsafe_allow_html=True)
|
51 |
+
else:
|
52 |
+
st.markdown("<h1 style='font-size: 1.5vw'>The uploaded image doesnt match Ants species</h1>", unsafe_allow_html=True)
|