Mavhas commited on
Commit
7a0ed23
·
verified ·
1 Parent(s): 885127e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +71 -69
app.py CHANGED
@@ -2,32 +2,46 @@ import streamlit as st
2
  from PIL import Image
3
  import os
4
  import io
 
5
 
6
  st.set_page_config(page_title="Valentine's Day Surprise", page_icon="❤️", layout="wide")
7
 
8
- # Load previous data (if it exists)
9
- if os.path.exists("data.txt"):
10
- with open("data.txt", "r") as f:
11
- try:
12
- saved_data = eval(f.read())
13
- except:
14
- saved_data = {"messages": [], "reasons": [], "images": []}
15
- else:
16
- saved_data = {"messages": [], "reasons": [], "images": []}
17
-
18
- # Password logic (using session state)
19
- if 'password_entered' not in st.session_state:
20
- st.session_state.password_entered = False
21
 
22
- if not st.session_state.password_entered:
23
- password_entered = st.text_input("Enter the secret word:", type="password")
24
- correct_password = "yoursecretword" # Replace with your secret word
25
 
26
  if password_entered == correct_password:
27
  st.session_state.password_entered = True
28
  st.rerun()
29
 
30
- if st.session_state.password_entered:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  st.title("Happy Valentine's Day, My Love! ❤️")
32
 
33
  # --- Styling ---
@@ -119,42 +133,49 @@ if st.session_state.password_entered:
119
  )
120
 
121
  # Tabs
122
- tabs = ["Memories", "Messages", "Reasons"]
123
  selected_tab = st.sidebar.radio("Select a tab:", tabs)
124
 
125
- if selected_tab == "Memories":
126
- st.write("## Our Memories")
127
-
128
- uploaded_files = st.file_uploader("Choose images", accept_multiple_files=True, type=["jpg", "png", "jpeg", "gif"])
129
-
130
- if uploaded_files:
131
- for uploaded_file in uploaded_files:
132
- try:
133
- image = Image.open(uploaded_file)
134
- st.image(image, caption=uploaded_file.name, use_column_width=True)
135
-
136
- image_path = os.path.join("static", uploaded_file.name)
137
- with open(image_path, "wb") as f:
138
- f.write(uploaded_file.getvalue())
139
-
140
- saved_data["images"].append(uploaded_file.name)
141
- with open("data.txt", "w") as f:
142
- f.write(str(saved_data))
 
 
 
 
 
 
 
 
 
143
 
144
- except Exception as e:
145
- st.error(f"Error opening image {uploaded_file.name}: {e}")
 
146
 
147
- if saved_data["images"]:
148
- for image_name in saved_data["images"]:
149
- try:
150
- image_path = os.path.join("static", image_name)
151
- with open(image_path, "rb") as f:
152
- image = Image.open(f)
153
- st.image(image, caption=image_name, use_column_width=True)
154
- except FileNotFoundError:
155
- st.warning(f"Could not load previously saved image: {image_name}. It might have been deleted.")
156
- except Exception as e:
157
- st.error(f"Error loading previously saved image {image_name}: {e}")
158
 
159
  elif selected_tab == "Messages":
160
  st.write("## Sweet Messages")
@@ -183,23 +204,4 @@ if st.session_state.password_entered:
183
  elif selected_tab == "Reasons":
184
  st.write("## Reasons I Love You")
185
 
186
- if saved_data["reasons"]:
187
- for i, reason in enumerate(saved_data["reasons"]):
188
- col1, col2 = st.columns([0.8, 0.2])
189
- with col1:
190
- st.write(f"{i+1}. {reason}")
191
- with col2:
192
- if st.button("Delete", key=f"delete_reason_{i}"):
193
- del saved_data["reasons"][i]
194
- with open("data.txt", "w") as f:
195
- f.write(str(saved_data))
196
- st.rerun()
197
-
198
- new_reason = st.text_input("Add a reason:")
199
- if st.button("Save Reason"):
200
- if new_reason:
201
- saved_data["reasons"].append(new_reason)
202
- with open("data.txt", "w") as f:
203
- f.write(str(saved_data))
204
- st.success("Reason saved!")
205
- st.rer
 
2
  from PIL import Image
3
  import os
4
  import io
5
+ import random
6
 
7
  st.set_page_config(page_title="Valentine's Day Surprise", page_icon="❤️", layout="wide")
8
 
9
+ # --- Startup Page ---
10
+ if not st.session_state.get('password_entered', False):
11
+ st.markdown(
12
+ """
13
+ <div style="display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh;">
14
+ <img src="YOUR_GIF_URL_HERE" width="200" style="margin-bottom: 20px;">
15
+ <h1 style="color: #f08080; font-family: 'Arial', sans-serif;">Happy Valentine's Day!</h1>
16
+ <p style="font-size: 1.2em; margin-bottom: 30px;">Enter the secret word to unlock the surprise:</p>
17
+ </div>
18
+ """,
19
+ unsafe_allow_html=True,
20
+ )
 
21
 
22
+ password_entered = st.text_input("", type="password", placeholder="Enter the secret word")
23
+ correct_password = "anna" # Replace with your secret word
 
24
 
25
  if password_entered == correct_password:
26
  st.session_state.password_entered = True
27
  st.rerun()
28
 
29
+ elif password_entered:
30
+ st.error("Incorrect secret word. Try again.")
31
+
32
+
33
+ # --- Main Content (after password entered) ---
34
+ if st.session_state.get('password_entered', False):
35
+ # Load previous data (if it exists)
36
+ if os.path.exists("data.txt"):
37
+ with open("data.txt", "r") as f:
38
+ try:
39
+ saved_data = eval(f.read())
40
+ except:
41
+ saved_data = {"messages": [], "reasons": [], "compliments": []}
42
+ else:
43
+ saved_data = {"messages": [], "reasons": [], "compliments": []}
44
+
45
  st.title("Happy Valentine's Day, My Love! ❤️")
46
 
47
  # --- Styling ---
 
133
  )
134
 
135
  # Tabs
136
+ tabs = ["Compliments", "Messages", "Reasons"]
137
  selected_tab = st.sidebar.radio("Select a tab:", tabs)
138
 
139
+ if selected_tab == "Compliments":
140
+ st.write("## Sweet Compliments")
141
+
142
+ compliments = [
143
+ "You have the most beautiful smile.",
144
+ "Your kindness is inspiring.",
145
+ "You’re incredibly intelligent and witty.",
146
+ "You make every day an adventure.",
147
+ "Your laugh is contagious and makes me so happy.",
148
+ "You have a heart of gold.",
149
+ "You’re the most supportive person I know.",
150
+ "You have amazing taste in everything.",
151
+ "You’re my best friend and my soulmate.",
152
+ "You’re simply amazing!"
153
+ ]
154
+
155
+ if saved_data["compliments"]:
156
+ for i, compliment in enumerate(saved_data["compliments"]):
157
+ col1, col2 = st.columns([0.8, 0.2])
158
+ with col1:
159
+ st.write(f"{i+1}. {compliment}")
160
+ with col2:
161
+ if st.button("Delete", key=f"delete_compliment_{i}"):
162
+ del saved_data["compliments"][i]
163
+ with open("data.txt", "w") as f:
164
+ f.write(str(saved_data))
165
+ st.rerun()
166
 
167
+ if st.button("Generate Random Compliment"):
168
+ random_compliment = random.choice(compliments)
169
+ st.write(f"💖 {random_compliment}")
170
 
171
+ new_compliment = st.text_area("Add a new compliment:", height=50)
172
+ if st.button("Save Compliment"):
173
+ if new_compliment:
174
+ saved_data["compliments"].append(new_compliment)
175
+ with open("data.txt", "w") as f:
176
+ f.write(str(saved_data))
177
+ st.success("Compliment saved!")
178
+ st.rerun()
 
 
 
179
 
180
  elif selected_tab == "Messages":
181
  st.write("## Sweet Messages")
 
204
  elif selected_tab == "Reasons":
205
  st.write("## Reasons I Love You")
206
 
207
+ if saved