File size: 1,859 Bytes
d2b447d
6d520ad
117f15d
 
e7e6340
6d520ad
117f15d
 
 
 
6d520ad
117f15d
 
37f5146
 
6d520ad
117f15d
 
 
6d520ad
 
 
 
 
117f15d
 
6d520ad
 
 
 
 
 
 
 
 
 
117f15d
 
 
 
6d520ad
117f15d
 
6d520ad
117f15d
6d520ad
 
117f15d
6d520ad
 
 
117f15d
6d520ad
 
 
 
 
117f15d
6d520ad
 
 
 
117f15d
 
d2b447d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# 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()