Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
|
|
|
|
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 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
|
|
|
|
|
|
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 |
-
|
74 |
-
|
75 |
-
|
|
|
|
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()
|