Update app.py
Browse files
app.py
CHANGED
@@ -109,7 +109,8 @@ def load_quotes(source="famous"):
|
|
109 |
"Love is the universal language, transcending boundaries and touching souls.",
|
110 |
"Through love, we find connection, unity, and the essence of existence."
|
111 |
]
|
112 |
-
|
|
|
113 |
|
114 |
# Vote saver - the tally keeper counting thumbs up! ππ
|
115 |
def save_vote(file, item, user_hash):
|
@@ -238,7 +239,8 @@ def create_streamlit_interface(initial_username):
|
|
238 |
if 'last_refresh' not in st.session_state:
|
239 |
st.session_state.last_refresh = time.time()
|
240 |
if 'quote_index' not in st.session_state:
|
241 |
-
|
|
|
242 |
if 'quote_source' not in st.session_state:
|
243 |
st.session_state.quote_source = "famous"
|
244 |
|
@@ -272,21 +274,28 @@ def create_streamlit_interface(initial_username):
|
|
272 |
# Quote section
|
273 |
st.subheader("Quote of the Moment π")
|
274 |
quotes = load_quotes(st.session_state.quote_source)
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
st.
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
283 |
st.session_state.last_refresh = time.time()
|
284 |
st.rerun()
|
285 |
-
|
286 |
-
st.
|
287 |
-
st.session_state.quote_source = "custom" if st.session_state.quote_source == "famous" else "famous"
|
288 |
-
st.session_state.last_refresh = time.time()
|
289 |
-
st.rerun()
|
290 |
|
291 |
# Image voting section
|
292 |
st.subheader("Image Voting πΌοΈ")
|
|
|
109 |
"Love is the universal language, transcending boundaries and touching souls.",
|
110 |
"Through love, we find connection, unity, and the essence of existence."
|
111 |
]
|
112 |
+
quotes = famous_quotes if source == "famous" else custom_quotes
|
113 |
+
return quotes if quotes else ["No quotes available - check back later! π"]
|
114 |
|
115 |
# Vote saver - the tally keeper counting thumbs up! ππ
|
116 |
def save_vote(file, item, user_hash):
|
|
|
239 |
if 'last_refresh' not in st.session_state:
|
240 |
st.session_state.last_refresh = time.time()
|
241 |
if 'quote_index' not in st.session_state:
|
242 |
+
quotes = load_quotes("famous")
|
243 |
+
st.session_state.quote_index = random.randint(0, max(0, len(quotes) - 1)) if quotes else 0
|
244 |
if 'quote_source' not in st.session_state:
|
245 |
st.session_state.quote_source = "famous"
|
246 |
|
|
|
274 |
# Quote section
|
275 |
st.subheader("Quote of the Moment π")
|
276 |
quotes = load_quotes(st.session_state.quote_source)
|
277 |
+
if quotes:
|
278 |
+
# Ensure quote_index is within bounds
|
279 |
+
st.session_state.quote_index = st.session_state.quote_index % len(quotes)
|
280 |
+
quote = quotes[st.session_state.quote_index]
|
281 |
+
col1, col2 = st.columns([5, 1])
|
282 |
+
with col1:
|
283 |
+
st.markdown(quote)
|
284 |
+
with col2:
|
285 |
+
if st.button("π Upvote", key="quote_vote"):
|
286 |
+
user_hash = generate_user_hash()
|
287 |
+
save_vote(QUOTE_VOTES_FILE, quote, user_hash)
|
288 |
+
st.session_state.last_refresh = time.time()
|
289 |
+
st.rerun()
|
290 |
+
if time.time() - st.session_state.last_refresh > 10: # 10s quote refresh
|
291 |
+
st.session_state.quote_index = (st.session_state.quote_index + 1) % len(quotes)
|
292 |
+
st.session_state.quote_source = "custom" if st.session_state.quote_source == "famous" else "famous"
|
293 |
+
quotes = load_quotes(st.session_state.quote_source) # Reload quotes for new source
|
294 |
+
st.session_state.quote_index = st.session_state.quote_index % len(quotes) if quotes else 0
|
295 |
st.session_state.last_refresh = time.time()
|
296 |
st.rerun()
|
297 |
+
else:
|
298 |
+
st.markdown("No quotes available - check back later! π")
|
|
|
|
|
|
|
299 |
|
300 |
# Image voting section
|
301 |
st.subheader("Image Voting πΌοΈ")
|