Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,36 +1,64 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import random
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
quotes =
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
# App Title
|
| 14 |
st.title("Random Quote Generator")
|
| 15 |
|
| 16 |
-
#
|
| 17 |
-
|
| 18 |
-
st.session_state["current_quote"] = random.choice(quotes)
|
| 19 |
|
| 20 |
-
# Display
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
st.markdown(f"- *{current_quote['author']}*")
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import random
|
| 3 |
|
| 4 |
+
# Quotes categorized by genres
|
| 5 |
+
quotes = {
|
| 6 |
+
"Motivation": [
|
| 7 |
+
{"quote": "The best way to predict the future is to create it.", "author": "Peter Drucker"},
|
| 8 |
+
{"quote": "Believe you can and you're halfway there.", "author": "Theodore Roosevelt"},
|
| 9 |
+
{"quote": "Success is not final, failure is not fatal: It is the courage to continue that counts.", "author": "Winston Churchill"},
|
| 10 |
+
],
|
| 11 |
+
"Happiness": [
|
| 12 |
+
{"quote": "Happiness is not something ready-made. It comes from your own actions.", "author": "Dalai Lama"},
|
| 13 |
+
{"quote": "For every minute you are angry you lose sixty seconds of happiness.", "author": "Ralph Waldo Emerson"},
|
| 14 |
+
{"quote": "Happiness depends upon ourselves.", "author": "Aristotle"},
|
| 15 |
+
],
|
| 16 |
+
"Life": [
|
| 17 |
+
{"quote": "Your time is limited, don't waste it living someone else's life.", "author": "Steve Jobs"},
|
| 18 |
+
{"quote": "Life is 10% what happens to us and 90% how we react to it.", "author": "Charles R. Swindoll"},
|
| 19 |
+
{"quote": "Do not dwell in the past, do not dream of the future, concentrate the mind on the present moment.", "author": "Buddha"},
|
| 20 |
+
],
|
| 21 |
+
}
|
| 22 |
|
| 23 |
# App Title
|
| 24 |
st.title("Random Quote Generator")
|
| 25 |
|
| 26 |
+
# Instruction
|
| 27 |
+
st.subheader("Choose a category to view quotes:")
|
|
|
|
| 28 |
|
| 29 |
+
# Display category buttons
|
| 30 |
+
categories = list(quotes.keys())
|
| 31 |
+
selected_genre = None
|
|
|
|
| 32 |
|
| 33 |
+
col1, col2, col3 = st.columns(3)
|
| 34 |
+
if col1.button("Motivation"):
|
| 35 |
+
selected_genre = "Motivation"
|
| 36 |
+
elif col2.button("Happiness"):
|
| 37 |
+
selected_genre = "Happiness"
|
| 38 |
+
elif col3.button("Life"):
|
| 39 |
+
selected_genre = "Life"
|
| 40 |
|
| 41 |
+
# Display quotes only if a category is selected
|
| 42 |
+
if selected_genre:
|
| 43 |
+
# Initialize session state for the selected genre
|
| 44 |
+
if "current_quote" not in st.session_state or st.session_state["selected_genre"] != selected_genre:
|
| 45 |
+
st.session_state["current_quote"] = random.choice(quotes[selected_genre])
|
| 46 |
+
st.session_state["selected_genre"] = selected_genre
|
| 47 |
|
| 48 |
+
# Display the current quote
|
| 49 |
+
current_quote = st.session_state["current_quote"]
|
| 50 |
+
st.markdown(f"**{current_quote['quote']}**")
|
| 51 |
+
st.markdown(f"- *{current_quote['author']}*")
|
| 52 |
+
|
| 53 |
+
# Buttons for user interaction
|
| 54 |
+
col4, col5 = st.columns(2)
|
| 55 |
+
|
| 56 |
+
with col4:
|
| 57 |
+
if st.button("I Like This Quote"):
|
| 58 |
+
st.success("Thank you for using the Random Quote Generator! Goodbye! 👋")
|
| 59 |
+
st.stop() # End the app
|
| 60 |
+
|
| 61 |
+
with col5:
|
| 62 |
+
if st.button("Show Me Another Quote"):
|
| 63 |
+
# Update the session state to trigger a re-run
|
| 64 |
+
st.session_state["current_quote"] = random.choice(quotes[selected_genre])
|