NayabShakeel commited on
Commit
072edf1
Β·
verified Β·
1 Parent(s): 43682c1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -10
app.py CHANGED
@@ -13,7 +13,9 @@ random_text = random_quote['quote']
13
  random_author = random_quote['author']
14
 
15
  # Load user-submitted quotes
16
- user_quotes = load_user_quotes()
 
 
17
 
18
  # Load AI quote generator (GPT-2)
19
  quote_generator = pipeline("text-generation", model="gpt2")
@@ -56,12 +58,15 @@ if "username" in st.session_state:
56
  user_quote = st.text_area("Enter your quote")
57
  user_name = st.text_input("Your Name (Leave blank for Anonymous)")
58
 
59
- if st.button("Submit"):
60
- if user_quote.strip():
61
- save_user_quote(user_quote, user_name if user_name else "Anonymous")
62
- st.success("βœ… Quote added successfully!")
63
- else:
64
- st.error("❌ Please enter a quote!")
 
 
 
65
 
66
  # Community Quotes with Upvotes
67
  st.subheader("πŸ“– Community Quotes")
@@ -70,6 +75,7 @@ for i, q in enumerate(user_quotes):
70
  with col1:
71
  st.write(f"πŸ’¬ *{q['quote']}* – {q['author']} | πŸ‘ {q['upvotes']} upvotes")
72
  with col2:
73
- if st.button(f"Upvote {i}", key=f"upvote_{i}"):
74
- upvote_quote(i)
75
- st.experimental_rerun()
 
 
13
  random_author = random_quote['author']
14
 
15
  # Load user-submitted quotes
16
+ if "user_quotes" not in st.session_state:
17
+ st.session_state.user_quotes = load_user_quotes()
18
+
19
 
20
  # Load AI quote generator (GPT-2)
21
  quote_generator = pipeline("text-generation", model="gpt2")
 
58
  user_quote = st.text_area("Enter your quote")
59
  user_name = st.text_input("Your Name (Leave blank for Anonymous)")
60
 
61
+ if st.button("Submit"):
62
+ if user_quote.strip():
63
+ save_user_quote(user_quote, user_name if user_name else "Anonymous")
64
+ st.session_state.user_quotes = load_user_quotes() # Update session state
65
+ st.success("βœ… Quote added successfully!")
66
+ st.experimental_rerun()
67
+ else:
68
+ st.error("❌ Please enter a quote!")
69
+
70
 
71
  # Community Quotes with Upvotes
72
  st.subheader("πŸ“– Community Quotes")
 
75
  with col1:
76
  st.write(f"πŸ’¬ *{q['quote']}* – {q['author']} | πŸ‘ {q['upvotes']} upvotes")
77
  with col2:
78
+ if st.button(f"Upvote {i}", key=f"upvote_{i}"):
79
+ upvote_quote(i)
80
+ st.session_state.user_quotes = load_user_quotes() # Update session state
81
+ st.experimental_rerun()