Spaces:
Runtime error
Runtime error
Commit
·
7c3de8f
1
Parent(s):
932dbf0
added app.py
Browse files- app.py +64 -0
- assets/background.png +0 -0
app.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import base64
|
| 3 |
+
|
| 4 |
+
def add_bg_from_local(image_file):
|
| 5 |
+
with open(image_file, "rb") as image_file:
|
| 6 |
+
encoded_string = base64.b64encode(image_file.read())
|
| 7 |
+
st.markdown(
|
| 8 |
+
f"""
|
| 9 |
+
<style>
|
| 10 |
+
.stApp {{
|
| 11 |
+
background-image: url(data:image/{"png"};base64,{encoded_string.decode()});
|
| 12 |
+
background-repeat: repeat;
|
| 13 |
+
}}
|
| 14 |
+
</style>
|
| 15 |
+
""",
|
| 16 |
+
unsafe_allow_html=True
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
def header_white_bg(text, fontsize = 40, bold = True):
|
| 20 |
+
st.markdown(
|
| 21 |
+
f"""
|
| 22 |
+
<span style="background:rgba(255, 255, 255, 0.8); font-size:{fontsize}px; font-weight:{"bold" if bold else "normal"}">{text}</span>
|
| 23 |
+
""",
|
| 24 |
+
unsafe_allow_html=True
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
def diagnose_health(file):
|
| 28 |
+
return "Healthy" # Placeholder result for demonstration purposes, waiting to integrate model
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def app():
|
| 32 |
+
add_bg_from_local('assets/background.png')
|
| 33 |
+
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> ')
|
| 34 |
+
|
| 35 |
+
# Upload image of plant
|
| 36 |
+
header_white_bg("Upload an image of your plant:", fontsize=32)
|
| 37 |
+
uploaded_file = st.file_uploader("", type=["jpg", "jpeg", "png"])
|
| 38 |
+
|
| 39 |
+
if uploaded_file:
|
| 40 |
+
header_white_bg("Preview of the selected image:", fontsize=28, bold=False)
|
| 41 |
+
st.image(uploaded_file)
|
| 42 |
+
|
| 43 |
+
# Get diagnosis button
|
| 44 |
+
if st.button("Get Diagnosis"):
|
| 45 |
+
if uploaded_file is not None:
|
| 46 |
+
# Diagnose plant health and display results
|
| 47 |
+
result = diagnose_health(uploaded_file)
|
| 48 |
+
st.success(f"Your plant is {result}")
|
| 49 |
+
else:
|
| 50 |
+
st.warning("Please upload an image of your plant first")
|
| 51 |
+
|
| 52 |
+
# Create user profile button
|
| 53 |
+
if st.button("Create User Profile"):
|
| 54 |
+
st.subheader("User Profile")
|
| 55 |
+
# Prompt user to add their name and the plant they own
|
| 56 |
+
user_name = st.text_input("Enter your name:")
|
| 57 |
+
plant_name = st.text_input("Enter the plant you own:")
|
| 58 |
+
if user_name and plant_name:
|
| 59 |
+
st.success(f"User profile created for {user_name} with plant {plant_name}")
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
# Run Streamlit app
|
| 63 |
+
if __name__ == "__main__":
|
| 64 |
+
app()
|
assets/background.png
ADDED
|