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