Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,7 @@ import pandas as pd
|
|
4 |
import json
|
5 |
import os
|
6 |
|
7 |
-
def display_table():
|
8 |
st.title("The Great Debate: Vote on the Funniest Questions!")
|
9 |
|
10 |
data = [
|
@@ -20,7 +20,16 @@ def display_table():
|
|
20 |
(10, "π", "What's the most useless talent you have?", "[Wikipedia](https://en.wikipedia.org/wiki/Talent_(human))"),
|
21 |
]
|
22 |
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
def update_vote_log(term, vote_type):
|
26 |
with open('vote.log.txt', 'a') as f:
|
@@ -42,41 +51,21 @@ def count_votes(vote_data, term):
|
|
42 |
return upvotes, downvotes
|
43 |
|
44 |
def main():
|
45 |
-
display_table()
|
46 |
-
|
47 |
-
terms = [
|
48 |
-
'Question 1',
|
49 |
-
'Question 2',
|
50 |
-
'Question 3',
|
51 |
-
'Question 4',
|
52 |
-
'Question 5',
|
53 |
-
'Question 6',
|
54 |
-
'Question 7',
|
55 |
-
'Question 8',
|
56 |
-
'Question 9',
|
57 |
-
'Question 10'
|
58 |
-
]
|
59 |
-
|
60 |
vote_data = load_vote_log()
|
61 |
|
62 |
-
|
63 |
-
st.title("User Controls")
|
64 |
-
for term in terms:
|
65 |
-
st.write(term)
|
66 |
-
upvotes, downvotes = count_votes(vote_data, term)
|
67 |
-
st.write(f"Total upvotes: {upvotes}")
|
68 |
-
st.write(f"Total downvotes: {downvotes}")
|
69 |
-
|
70 |
-
upvote_button = st.button(f"π Upvote {term}")
|
71 |
-
downvote_button = st.button(f"π Downvote {term}")
|
72 |
-
|
73 |
-
if upvote_button:
|
74 |
-
update_vote_log(term, 'upvote')
|
75 |
-
st.experimental_rerun()
|
76 |
|
77 |
-
|
78 |
-
|
79 |
-
|
|
|
|
|
|
|
|
|
80 |
|
81 |
-
|
|
|
|
|
82 |
|
|
|
|
|
|
4 |
import json
|
5 |
import os
|
6 |
|
7 |
+
def display_table(vote_data):
|
8 |
st.title("The Great Debate: Vote on the Funniest Questions!")
|
9 |
|
10 |
data = [
|
|
|
20 |
(10, "π", "What's the most useless talent you have?", "[Wikipedia](https://en.wikipedia.org/wiki/Talent_(human))"),
|
21 |
]
|
22 |
|
23 |
+
table_data = []
|
24 |
+
for row in data:
|
25 |
+
upvotes, downvotes = count_votes(vote_data, f"Question {row[0]}")
|
26 |
+
table_data.append(row + (upvotes, downvotes))
|
27 |
+
|
28 |
+
df = pd.DataFrame(table_data, columns=['Question', 'Emoji', 'Title', 'Description', 'Upvotes', 'Downvotes'])
|
29 |
+
|
30 |
+
st.table(df)
|
31 |
+
|
32 |
+
return df
|
33 |
|
34 |
def update_vote_log(term, vote_type):
|
35 |
with open('vote.log.txt', 'a') as f:
|
|
|
51 |
return upvotes, downvotes
|
52 |
|
53 |
def main():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
vote_data = load_vote_log()
|
55 |
|
56 |
+
df = display_table(vote_data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
+
for index, row in df.iterrows():
|
59 |
+
question_id = f"Question {row['Question']}"
|
60 |
+
upvote_button = st.button(f"π Upvote {question_id}")
|
61 |
+
downvote_button = st.button(f"π Downvote {question_id}")
|
62 |
+
if upvote_button:
|
63 |
+
update_vote_log(question_id, 'upvote')
|
64 |
+
st.experimental_rerun()
|
65 |
|
66 |
+
if downvote_button:
|
67 |
+
update_vote_log(question_id, 'downvote')
|
68 |
+
st.experimental_rerun()
|
69 |
|
70 |
+
|
71 |
+
main()
|