Update app.py
Browse files
app.py
CHANGED
|
@@ -14,7 +14,7 @@ if os.path.exists("data.txt"):
|
|
| 14 |
else:
|
| 15 |
saved_data = {"messages": [], "reasons": [], "images": []}
|
| 16 |
|
| 17 |
-
# Password logic (
|
| 18 |
if 'password_entered' not in st.session_state:
|
| 19 |
st.session_state.password_entered = False
|
| 20 |
|
|
@@ -24,9 +24,9 @@ if not st.session_state.password_entered:
|
|
| 24 |
|
| 25 |
if password_entered == correct_password:
|
| 26 |
st.session_state.password_entered = True
|
| 27 |
-
st.experimental_rerun()
|
| 28 |
|
| 29 |
-
if st.session_state.password_entered:
|
| 30 |
st.title("Happy Valentine's Day, My Love! ❤️")
|
| 31 |
|
| 32 |
# --- Styling ---
|
|
@@ -34,18 +34,18 @@ if st.session_state.password_entered: # Show content only after correct passwor
|
|
| 34 |
"""
|
| 35 |
<style>
|
| 36 |
body {
|
| 37 |
-
background-color: #f8f0e3;
|
| 38 |
font-family: 'Arial', sans-serif;
|
| 39 |
}
|
| 40 |
.stButton>button {
|
| 41 |
-
background-color: #f08080 !important;
|
| 42 |
color: white !important;
|
| 43 |
border: none;
|
| 44 |
padding: 10px 20px;
|
| 45 |
border-radius: 5px;
|
| 46 |
}
|
| 47 |
.stTextInput, .stTextArea, .stSelectbox {
|
| 48 |
-
border: 2px solid #f08080;
|
| 49 |
border-radius: 5px;
|
| 50 |
}
|
| 51 |
</style>
|
|
@@ -53,8 +53,28 @@ if st.session_state.password_entered: # Show content only after correct passwor
|
|
| 53 |
unsafe_allow_html=True,
|
| 54 |
)
|
| 55 |
|
| 56 |
-
# --- Heart Animation
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
# Tabs
|
| 60 |
tabs = ["Memories", "Messages", "Reasons"]
|
|
@@ -71,7 +91,6 @@ if st.session_state.password_entered: # Show content only after correct passwor
|
|
| 71 |
image = Image.open(uploaded_file)
|
| 72 |
st.image(image, caption=uploaded_file.name, use_column_width=True)
|
| 73 |
|
| 74 |
-
# Save image to static folder and update data.txt
|
| 75 |
image_path = os.path.join("static", uploaded_file.name)
|
| 76 |
with open(image_path, "wb") as f:
|
| 77 |
f.write(uploaded_file.getvalue())
|
|
@@ -83,8 +102,7 @@ if st.session_state.password_entered: # Show content only after correct passwor
|
|
| 83 |
except Exception as e:
|
| 84 |
st.error(f"Error opening image {uploaded_file.name}: {e}")
|
| 85 |
|
| 86 |
-
#
|
| 87 |
-
if saved_data["images"]:
|
| 88 |
for image_name in saved_data["images"]:
|
| 89 |
try:
|
| 90 |
image_path = os.path.join("static", image_name)
|
|
@@ -96,7 +114,38 @@ if st.session_state.password_entered: # Show content only after correct passwor
|
|
| 96 |
st.error(f"Error loading previously saved image {image_name}: {e}")
|
| 97 |
|
| 98 |
elif selected_tab == "Messages":
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
elif selected_tab == "Reasons":
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
else:
|
| 15 |
saved_data = {"messages": [], "reasons": [], "images": []}
|
| 16 |
|
| 17 |
+
# Password logic (using session state)
|
| 18 |
if 'password_entered' not in st.session_state:
|
| 19 |
st.session_state.password_entered = False
|
| 20 |
|
|
|
|
| 24 |
|
| 25 |
if password_entered == correct_password:
|
| 26 |
st.session_state.password_entered = True
|
| 27 |
+
st.experimental_rerun()
|
| 28 |
|
| 29 |
+
if st.session_state.password_entered:
|
| 30 |
st.title("Happy Valentine's Day, My Love! ❤️")
|
| 31 |
|
| 32 |
# --- Styling ---
|
|
|
|
| 34 |
"""
|
| 35 |
<style>
|
| 36 |
body {
|
| 37 |
+
background-color: #f8f0e3;
|
| 38 |
font-family: 'Arial', sans-serif;
|
| 39 |
}
|
| 40 |
.stButton>button {
|
| 41 |
+
background-color: #f08080 !important;
|
| 42 |
color: white !important;
|
| 43 |
border: none;
|
| 44 |
padding: 10px 20px;
|
| 45 |
border-radius: 5px;
|
| 46 |
}
|
| 47 |
.stTextInput, .stTextArea, .stSelectbox {
|
| 48 |
+
border: 2px solid #f08080;
|
| 49 |
border-radius: 5px;
|
| 50 |
}
|
| 51 |
</style>
|
|
|
|
| 53 |
unsafe_allow_html=True,
|
| 54 |
)
|
| 55 |
|
| 56 |
+
# --- Heart Animation ---
|
| 57 |
+
st.markdown(
|
| 58 |
+
"""
|
| 59 |
+
<div style="position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: -1;">
|
| 60 |
+
<div class="heart"></div>
|
| 61 |
+
<div class="heart" style="left: 10%; animation-delay: 2s;"></div>
|
| 62 |
+
<div class="heart" style="left: 20%; animation-delay: 1s;"></div>
|
| 63 |
+
<div class="heart" style="left: 30%; animation-delay: 3s;"></div>
|
| 64 |
+
<div class="heart" style="left: 40%; animation-delay: 0.5s;"></div>
|
| 65 |
+
<div class="heart" style="left: 50%; animation-delay: 2.5s;"></div>
|
| 66 |
+
<div class="heart" style="left: 60%; animation-delay: 1.5s;"></div>
|
| 67 |
+
<div class="heart" style="left: 70%; animation-delay: 3.5s;"></div>
|
| 68 |
+
<div class="heart" style="left: 80%; animation-delay: 0.8s;"></div>
|
| 69 |
+
<div class="heart" style="left: 90%; animation-delay: 2.2s;"></div>
|
| 70 |
+
</div>
|
| 71 |
+
|
| 72 |
+
<style>
|
| 73 |
+
.heart { /* ... (same heart animation CSS as before) ... */ }
|
| 74 |
+
</style>
|
| 75 |
+
""",
|
| 76 |
+
unsafe_allow_html=True,
|
| 77 |
+
)
|
| 78 |
|
| 79 |
# Tabs
|
| 80 |
tabs = ["Memories", "Messages", "Reasons"]
|
|
|
|
| 91 |
image = Image.open(uploaded_file)
|
| 92 |
st.image(image, caption=uploaded_file.name, use_column_width=True)
|
| 93 |
|
|
|
|
| 94 |
image_path = os.path.join("static", uploaded_file.name)
|
| 95 |
with open(image_path, "wb") as f:
|
| 96 |
f.write(uploaded_file.getvalue())
|
|
|
|
| 102 |
except Exception as e:
|
| 103 |
st.error(f"Error opening image {uploaded_file.name}: {e}")
|
| 104 |
|
| 105 |
+
if saved_data["images"]: # Always display previously uploaded images
|
|
|
|
| 106 |
for image_name in saved_data["images"]:
|
| 107 |
try:
|
| 108 |
image_path = os.path.join("static", image_name)
|
|
|
|
| 114 |
st.error(f"Error loading previously saved image {image_name}: {e}")
|
| 115 |
|
| 116 |
elif selected_tab == "Messages":
|
| 117 |
+
st.write("## Sweet Messages")
|
| 118 |
+
new_message = st.text_area("Add a new message:", height=100)
|
| 119 |
+
if st.button("Save Message"):
|
| 120 |
+
if new_message:
|
| 121 |
+
saved_data["messages"].append(new_message)
|
| 122 |
+
with open("data.txt", "w") as f:
|
| 123 |
+
f.write(str(saved_data))
|
| 124 |
+
st.success("Message saved!")
|
| 125 |
+
st.rerun()
|
| 126 |
+
|
| 127 |
+
if saved_data["messages"]:
|
| 128 |
+
for message in saved_data["messages"]:
|
| 129 |
+
st.write(f"- {message}")
|
| 130 |
|
| 131 |
elif selected_tab == "Reasons":
|
| 132 |
+
st.write("## Reasons I Love You")
|
| 133 |
+
|
| 134 |
+
if saved_data["reasons"]:
|
| 135 |
+
for reason in saved_data["reasons"]:
|
| 136 |
+
st.write(f"- {reason}")
|
| 137 |
+
|
| 138 |
+
new_reason = st.text_input("Add a reason:")
|
| 139 |
+
if st.button("Save Reason"):
|
| 140 |
+
if new_reason:
|
| 141 |
+
saved_data["reasons"].append(new_reason)
|
| 142 |
+
with open("data.txt", "w") as f:
|
| 143 |
+
f.write(str(saved_data))
|
| 144 |
+
st.success("Reason saved!")
|
| 145 |
+
st.rerun()
|
| 146 |
+
|
| 147 |
+
elif password_entered: # This should never be reached now
|
| 148 |
+
st.error("Incorrect secret word. Try again.")
|
| 149 |
+
|
| 150 |
+
else:
|
| 151 |
+
st.info("Enter the secret word to unlock the surprises!")
|