Update app.py
Browse files
app.py
CHANGED
|
@@ -1,39 +1,86 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from PIL import Image
|
|
|
|
| 3 |
|
| 4 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
# Password logic (for simulation only - NOT secure)
|
| 7 |
password_entered = st.text_input("Enter the secret word:", type="password")
|
| 8 |
correct_password = "anna" # Replace with your secret word
|
| 9 |
|
| 10 |
if password_entered == correct_password:
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
if
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
st.error("Incorrect secret word. Try again.")
|
| 37 |
|
| 38 |
-
else:
|
| 39 |
st.info("Enter the secret word to unlock the surprises!")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from PIL import Image
|
| 3 |
+
import os
|
| 4 |
|
| 5 |
+
st.set_page_config(page_title="Valentine's Day Surprise", page_icon="❤️") # Set page title and icon
|
| 6 |
+
|
| 7 |
+
# Load previous data (if it exists)
|
| 8 |
+
if os.path.exists("data.txt"):
|
| 9 |
+
with open("data.txt", "r") as f:
|
| 10 |
+
try:
|
| 11 |
+
saved_data = eval(f.read()) # Use eval carefully, only for trusted data!
|
| 12 |
+
except: # Handle potential errors if file is corrupted
|
| 13 |
+
saved_data = {"messages": [], "reasons": [], "images": []}
|
| 14 |
+
else:
|
| 15 |
+
saved_data = {"messages": [], "reasons": [], "images": []}
|
| 16 |
+
|
| 17 |
+
st.title("Happy Valentine's Day, My Love! ❤️")
|
| 18 |
|
| 19 |
# Password logic (for simulation only - NOT secure)
|
| 20 |
password_entered = st.text_input("Enter the secret word:", type="password")
|
| 21 |
correct_password = "anna" # Replace with your secret word
|
| 22 |
|
| 23 |
if password_entered == correct_password:
|
| 24 |
+
# Tabs
|
| 25 |
+
tabs = ["Memories", "Messages", "Reasons"]
|
| 26 |
+
selected_tab = st.sidebar.radio("Select a tab:", tabs)
|
| 27 |
+
|
| 28 |
+
if selected_tab == "Memories":
|
| 29 |
+
st.write("## Our Memories")
|
| 30 |
+
|
| 31 |
+
uploaded_files = st.file_uploader("Choose images", accept_multiple_files=True, type=["jpg", "png", "jpeg", "gif"])
|
| 32 |
+
|
| 33 |
+
if uploaded_files:
|
| 34 |
+
for uploaded_file in uploaded_files:
|
| 35 |
+
try:
|
| 36 |
+
image = Image.open(uploaded_file)
|
| 37 |
+
st.image(image, caption=uploaded_file.name, use_column_width=True)
|
| 38 |
+
saved_data["images"].append(uploaded_file.name) # Save the image name
|
| 39 |
+
with open("data.txt", "w") as f: # Save data after each upload
|
| 40 |
+
f.write(str(saved_data))
|
| 41 |
+
except Exception as e:
|
| 42 |
+
st.error(f"Error opening image {uploaded_file.name}: {e}")
|
| 43 |
+
elif saved_data["images"]: #Show previously uploaded images
|
| 44 |
+
for image_name in saved_data["images"]:
|
| 45 |
+
try:
|
| 46 |
+
image_path = os.path.join("static", image_name) # Assuming images are in static folder
|
| 47 |
+
image = Image.open(image_path)
|
| 48 |
+
st.image(image, caption=image_name, use_column_width=True)
|
| 49 |
+
except:
|
| 50 |
+
st.warning(f"Could not load previously saved image: {image_name}")
|
| 51 |
+
|
| 52 |
+
elif selected_tab == "Messages":
|
| 53 |
+
st.write("## Sweet Messages")
|
| 54 |
+
new_message = st.text_area("Add a new message:", height=100)
|
| 55 |
+
if st.button("Save Message"):
|
| 56 |
+
if new_message:
|
| 57 |
+
saved_data["messages"].append(new_message)
|
| 58 |
+
with open("data.txt", "w") as f:
|
| 59 |
+
f.write(str(saved_data))
|
| 60 |
+
st.success("Message saved!")
|
| 61 |
+
st.experimental_rerun() # Refresh to show message immediately
|
| 62 |
+
|
| 63 |
+
if saved_data["messages"]: #Display previously saved messages
|
| 64 |
+
for message in saved_data["messages"]:
|
| 65 |
+
st.write(f"- {message}")
|
| 66 |
+
|
| 67 |
+
elif selected_tab == "Reasons":
|
| 68 |
+
st.write("## Reasons I Love You")
|
| 69 |
+
new_reason = st.text_input("Add a reason:")
|
| 70 |
+
if st.button("Save Reason"):
|
| 71 |
+
if new_reason:
|
| 72 |
+
saved_data["reasons"].append(new_reason)
|
| 73 |
+
with open("data.txt", "w") as f:
|
| 74 |
+
f.write(str(saved_data))
|
| 75 |
+
st.success("Reason saved!")
|
| 76 |
+
st.experimental_rerun()
|
| 77 |
+
|
| 78 |
+
if saved_data["reasons"]: #Display previously saved reasons
|
| 79 |
+
for reason in saved_data["reasons"]:
|
| 80 |
+
st.write(f"- {reason}")
|
| 81 |
+
|
| 82 |
+
elif password_entered:
|
| 83 |
st.error("Incorrect secret word. Try again.")
|
| 84 |
|
| 85 |
+
else:
|
| 86 |
st.info("Enter the secret word to unlock the surprises!")
|