File size: 2,128 Bytes
7c3de8f
 
d563f38
7c3de8f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5ed9dbe
d563f38
7c3de8f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
66
import streamlit as st
import base64
import predictor

def add_bg_from_local(image_file):
    with open(image_file, "rb") as image_file:
        encoded_string = base64.b64encode(image_file.read())
    st.markdown(
    f"""
    <style>
    .stApp {{
        background-image: url(data:image/{"png"};base64,{encoded_string.decode()});
        background-repeat: repeat;
    }}
    </style>
    """,
        unsafe_allow_html=True
    )

def header_white_bg(text, fontsize = 40, bold = True):
    st.markdown(
        f"""
        <span style="background:rgba(255, 255, 255, 0.8); font-size:{fontsize}px; font-weight:{"bold" if bold else "normal"}">{text}</span>
        """,
        unsafe_allow_html=True
    )

def diagnose_health(file):
    prediction = predict(file)
    return prediction

def app():
    add_bg_from_local('assets/background.png')
    header_white_bg(f'<span style="color:green">Plant</span><span style="color:orange">Dx</span><span style="color:green">: Diagnosis in a Snap!</span> ')

    # Upload image of plant
    header_white_bg("Upload an image of your plant:", fontsize=32)
    uploaded_file = st.file_uploader("", type=["jpg", "jpeg", "png"])

    if uploaded_file:
        header_white_bg("Preview of the selected image:", fontsize=28, bold=False)
        st.image(uploaded_file)

    # Get diagnosis button
    if st.button("Get Diagnosis"):
        if uploaded_file is not None:
            # Diagnose plant health and display results
            result = diagnose_health(uploaded_file)
            st.success(f"Your plant is {result}")
        else:
            st.warning("Please upload an image of your plant first")

    # Create user profile button
    if st.button("Create User Profile"):
        st.subheader("User Profile")
        # Prompt user to add their name and the plant they own
        user_name = st.text_input("Enter your name:")
        plant_name = st.text_input("Enter the plant you own:")
        if user_name and plant_name:
            st.success(f"User profile created for {user_name} with plant {plant_name}")


# Run Streamlit app
if __name__ == "__main__":
    app()