# Import streamlit
import streamlit as st
from streamlit_option_menu import option_menu
from fastai.vision.all import *
from fastai.learner import load_learner
import pickle
from bird_species import model_info
from bird_species import capture_photo
from bird_species import upload_photo
def app():
#######################################################################################################################
# Set the page config
st.set_page_config(
page_title="Bird Species Detector (525 Species)", # The title of the web page
page_icon="🕊️", # The icon of the web page, can be an emoji or a file path
initial_sidebar_state="collapsed"
)
#######################################################################################################################
st.markdown("
🕊️Birds Species Detector (525 Species)🕊️
",
unsafe_allow_html=True)
#######################################################################################################################
# Options Menu at the top of the homepage
selected = option_menu(None, ["Upload", "Capture", "Model"],
icons=["cloud upload", "camera", "gear"],
menu_icon="cast", default_index=0, orientation="horizontal")
#######################################################################################################################
# Load model and model class labels (vocab)
model = load_learner(fname="models/birds_learner.pkl")
with open("models/birds_vocab.pkl", "rb") as f:
vocab = pickle.load(f)
# Sorting
vocab = sorted(vocab)
with open("models/freezed_model_summary.pkl", "rb") as f:
freezed_arch_summary = pickle.load(f)
with open("models/unfreezed_model_summary.pkl", "rb") as f:
unfreezed_arch_summary = pickle.load(f)
with open("models/birds_model_preprocessing.pkl","rb") as f:
preprocessing_steps = pickle.load(f)
#######################################################################################################################
if selected == "Upload":
st.caption("""Our project utilizes FastAI Vision with the ResNet50 architecture to classify
525 bird species. Our dataset comprises 84,635 training images, 2,625 test images and 2,625 validation
images, all standardized to 224x224x3 pixels. Initial training yields 96.6% accuracy, improved to 98% post
fine-tuning. Despite gender imbalances, it's a valuable resource for accurate bird species classification.""")
upload_photo(model=model, vocab=vocab, key="upload photo")
# Link for other projects
# st.divider()
st.markdown("### `Other Projects`")
# st.markdown("* [**Cat and Dog's Breed Detector**](https://subrata-mondal-cat-and-dog-breed-detector.streamlit.app/)")
st.link_button(label="**Cat and Dog's Breed Detector**", url="https://subrata-mondal-cat-and-dog-breed-detector.streamlit.app/")
st.divider()
#######################################################################################################################
if selected == "Capture":
capture_photo(model=model, vocab=None, key="capture photo")
if selected == "Model":
model_info()
st.subheader("Preprocessing Steps")
st.code(preprocessing_steps)
st.subheader("FastAi Model Summary (Freezed)")
st.code(freezed_arch_summary)
st.subheader("FastAi Model Summary (Unfreezed)")
st.code(unfreezed_arch_summary)
#######################################################################################################################
if __name__ == "__main__":
app()