awacke1 commited on
Commit
e1caed1
β€’
1 Parent(s): 5aad9e7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -2
app.py CHANGED
@@ -53,6 +53,26 @@ def display_table():
53
  st.table(pd.DataFrame(data, columns=['Question', 'Emoji', 'Title', 'Description']))
54
 
55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  def main():
57
  display_graph()
58
  display_table()
@@ -66,12 +86,24 @@ def main():
66
  '🎬 Response'
67
  ]
68
 
 
 
69
  for term in terms:
70
  st.write(term)
 
 
 
 
71
  upvote_button = st.button(f"πŸ‘ Upvote {term}")
72
  downvote_button = st.button(f"πŸ‘Ž Downvote {term}")
73
 
74
- # ... (upvote and downvote handling) ...
 
 
 
 
 
 
75
 
76
  if __name__ == "__main__":
77
- main()
 
53
  st.table(pd.DataFrame(data, columns=['Question', 'Emoji', 'Title', 'Description']))
54
 
55
 
56
+
57
+ def update_vote_log(term, vote_type):
58
+ with open('vote.log.txt', 'a') as f:
59
+ f.write(json.dumps({'term': term, 'vote': vote_type}) + '\n')
60
+
61
+ def load_vote_log():
62
+ vote_data = []
63
+
64
+ if os.path.exists('vote.log.txt'):
65
+ with open('vote.log.txt', 'r') as f:
66
+ for line in f.readlines():
67
+ vote_data.append(json.loads(line.strip()))
68
+
69
+ return vote_data
70
+
71
+ def count_votes(vote_data, term):
72
+ upvotes = sum(1 for vote in vote_data if vote['term'] == term and vote['vote'] == 'upvote')
73
+ downvotes = sum(1 for vote in vote_data if vote['term'] == term and vote['vote'] == 'downvote')
74
+ return upvotes, downvotes
75
+
76
  def main():
77
  display_graph()
78
  display_table()
 
86
  '🎬 Response'
87
  ]
88
 
89
+ vote_data = load_vote_log()
90
+
91
  for term in terms:
92
  st.write(term)
93
+ upvotes, downvotes = count_votes(vote_data, term)
94
+ st.write(f"Total upvotes: {upvotes}")
95
+ st.write(f"Total downvotes: {downvotes}")
96
+
97
  upvote_button = st.button(f"πŸ‘ Upvote {term}")
98
  downvote_button = st.button(f"πŸ‘Ž Downvote {term}")
99
 
100
+ if upvote_button:
101
+ update_vote_log(term, 'upvote')
102
+ st.experimental_rerun()
103
+
104
+ if downvote_button:
105
+ update_vote_log(term, 'downvote')
106
+ st.experimental_rerun()
107
 
108
  if __name__ == "__main__":
109
+ main()