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