File size: 2,097 Bytes
18923c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import streamlit as st
import pandas as pd
from py_thesaurus import Thesaurus
import random
import os.path

def generate_sentence():
    words = ["apple", "banana", "grape", "orange", "watermelon", "pineapple", "cherry", "strawberry", "blueberry", "mango"]
    random_words = random.sample(words, 3)
    question = f"What did the {random_words[0]} say to the {random_words[1]}?"
    answer = f"The {random_words[0]} said, 'Let's hang out with the {random_words[2]}!'"
    context = f"In the context of a fruit gathering, the {random_words[0]}, {random_words[1]}, and {random_words[2]} were having fun."
    return f"{question} {answer} {context}"

def replace_with_synonym(sentence):
    words = sentence.split()
    index = random.randint(0, len(words) - 1)
    word = words[index]
    synonyms = Thesaurus(word).get_synonym()
    if synonyms:
        replacement = random.choice(synonyms)
        words[index] = replacement
    return ' '.join(words)

def load_or_create_scoreboard(filename):
    if os.path.isfile(filename):
        return pd.read_csv(filename)
    else:
        scoreboard = pd.DataFrame({'Upvotes': [0], 'Downvotes': [0]})
        scoreboard.to_csv(filename, index=False)
        return scoreboard

def update_scoreboard(scoreboard, thumbs_up, thumbs_down):
    if thumbs_up:
        scoreboard.loc[0, 'Upvotes'] += 1
    elif thumbs_down:
        scoreboard.loc[0, 'Downvotes'] += 1
    return scoreboard

def main():
    filename = 'output.csv'
    scoreboard = load_or_create_scoreboard(filename)
    st.title('Joke Parts Voting Game')
    thumbs_up = st.button('๐Ÿ‘')
    thumbs_down = st.button('๐Ÿ‘Ž')
    scoreboard = update_scoreboard(scoreboard, thumbs_up, thumbs_down)
    scoreboard.to_csv(filename, index=False)
    col1, col2 = st.columns(2)
    with col1:
        st.write(f'๐Ÿ‘ {scoreboard.loc[0, "Upvotes"]}')
    with col2:
        st.write(f'๐Ÿ‘Ž {scoreboard.loc[0, "Downvotes"]}')
    original_text = generate_sentence()
    modified_text = replace_with_synonym(original_text)
    st.write(f'๐Ÿคฃ {modified_text}')

if __name__ == "__main__":
    main()