SyedAliHusnainGillani commited on
Commit
3602dba
·
verified ·
1 Parent(s): 458aafa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -3
app.py CHANGED
@@ -41,10 +41,27 @@ elif col3.button("Life"):
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']}**")
@@ -60,5 +77,4 @@ if selected_genre:
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])
 
41
  # Display quotes only if a category is selected
42
  if selected_genre:
43
  # Initialize session state for the selected genre
44
+ if "shown_quotes" not in st.session_state:
45
+ st.session_state["shown_quotes"] = {genre: [] for genre in quotes.keys()}
46
  if "current_quote" not in st.session_state or st.session_state["selected_genre"] != selected_genre:
47
+ st.session_state["current_quote"] = None
48
  st.session_state["selected_genre"] = selected_genre
49
 
50
+ # Get a new quote that has not been shown yet
51
+ available_quotes = [
52
+ quote for quote in quotes[selected_genre]
53
+ if quote not in st.session_state["shown_quotes"][selected_genre]
54
+ ]
55
+
56
+ if not available_quotes:
57
+ st.warning("No more quotes left in this category! Resetting...")
58
+ st.session_state["shown_quotes"][selected_genre] = []
59
+ available_quotes = quotes[selected_genre]
60
+
61
+ if not st.session_state["current_quote"]:
62
+ st.session_state["current_quote"] = random.choice(available_quotes)
63
+ st.session_state["shown_quotes"][selected_genre].append(st.session_state["current_quote"])
64
+
65
  # Display the current quote
66
  current_quote = st.session_state["current_quote"]
67
  st.markdown(f"**{current_quote['quote']}**")
 
77
 
78
  with col5:
79
  if st.button("Show Me Another Quote"):
80
+ st.session_state["current_quote"] = None # Clear the current quote