Shruti9756 commited on
Commit
be45fc0
β€’
1 Parent(s): 68482ff

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ from py_thesaurus import Thesaurus
4
+ import random
5
+ import os.path
6
+
7
+ def generate_sentence():
8
+ words = ["apple", "banana", "grape", "orange", "watermelon", "pineapple", "cherry", "strawberry", "blueberry", "mango"]
9
+ random_words = random.sample(words, 3)
10
+ question = f"What did the {random_words[0]} say to the {random_words[1]}?"
11
+ answer = f"The {random_words[0]} said, 'Let's hang out with the {random_words[2]}!'"
12
+ context = f"In the context of a fruit gathering, the {random_words[0]}, {random_words[1]}, and {random_words[2]} were having fun."
13
+ return f"{question} {answer} {context}"
14
+
15
+ def replace_with_synonym(sentence):
16
+ words = sentence.split()
17
+ index = random.randint(0, len(words) - 1)
18
+ word = words[index]
19
+ synonyms = Thesaurus(word).get_synonym()
20
+ if synonyms:
21
+ replacement = random.choice(synonyms)
22
+ words[index] = replacement
23
+ return ' '.join(words)
24
+
25
+ def load_or_create_scoreboard(filename):
26
+ if os.path.isfile(filename):
27
+ return pd.read_csv(filename)
28
+ else:
29
+ scoreboard = pd.DataFrame({'Upvotes': [0], 'Downvotes': [0]})
30
+ scoreboard.to_csv(filename, index=False)
31
+ return scoreboard
32
+
33
+ def update_scoreboard(scoreboard, thumbs_up, thumbs_down):
34
+ if thumbs_up:
35
+ scoreboard.loc[0, 'Upvotes'] += 1
36
+ elif thumbs_down:
37
+ scoreboard.loc[0, 'Downvotes'] += 1
38
+ return scoreboard
39
+
40
+ def main():
41
+ filename = 'output.csv'
42
+ scoreboard = load_or_create_scoreboard(filename)
43
+ st.title('Joke Parts Voting Game')
44
+ thumbs_up = st.button('πŸ‘')
45
+ thumbs_down = st.button('πŸ‘Ž')
46
+ scoreboard = update_scoreboard(scoreboard, thumbs_up, thumbs_down)
47
+ scoreboard.to_csv(filename, index=False)
48
+ col1, col2 = st.columns(2)
49
+ with col1:
50
+ st.write(f'πŸ‘ {scoreboard.loc[0, "Upvotes"]}')
51
+ with col2:
52
+ st.write(f'πŸ‘Ž {scoreboard.loc[0, "Downvotes"]}')
53
+ original_text = generate_sentence()
54
+ modified_text = replace_with_synonym(original_text)
55
+ st.write(f'🀣 {modified_text}')
56
+
57
+ if __name__ == "__main__":
58
+ main()