# 1. app.py # Main Streamlit app for UI and user interaction import streamlit as st from PIL import Image from dataset_utils import preprocess_image, DatasetHandler from model_utils import BugClassifier st.set_page_config( page_title="Bug-O-Scope 🔍🐞", page_icon="🔍", layout="wide" ) @st.cache_resource def load_model(): return BugClassifier() def main(): st.title("Bug-O-Scope 🔍🐞") st.markdown( """ Welcome to Bug-O-Scope! Upload a photo of an insect to identify it and learn about its ecological importance. """ ) st.sidebar.header("About Bug-O-Scope") st.sidebar.markdown( """ Bug-O-Scope is powered by AI to help you: - Identify insects - Learn about species - Understand their ecological roles """ ) model = load_model() tab1, tab2 = st.tabs(["Single Bug Analysis", "Bug Comparison"]) with tab1: single_bug_analysis(model) with tab2: st.markdown("Bug comparison feature coming soon!") def single_bug_analysis(model): uploaded_file = st.file_uploader("Upload a bug photo", type=['png', 'jpg', 'jpeg']) if uploaded_file: image = Image.open(uploaded_file) st.image(image, caption="Uploaded Image", use_container_width=True) with st.spinner("Analyzing your bug..."): prediction, confidence = model.predict(image) st.success("Analysis Complete!") st.markdown(f"**Identified Species**: {prediction}") st.markdown(f"**Confidence**: {confidence:.2f}%") if prediction != "Unknown Insect": species_info = model.get_species_info(prediction) st.markdown("### About This Species") st.markdown(species_info) if __name__ == "__main__": main()