File size: 1,832 Bytes
05f6d24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
60
61
62
63
64
65
66
67
68
69
import streamlit as st
import nltk
import pandas as pd
from py_thesaurus import Thesaurus
import random

# Cache the NLTK corpora and functions for better performance
@st.cache
def load_nltk_data():
    nltk.download('book')
    from nltk.book import text1

    return text1

# Function to generate random text from NLTK corpora
def generate_text():
    text = load_nltk_data()
    words = [word.lower() for word in text if word.isalpha()]
    random_text = ' '.join(nltk.choice(words) for _ in range(10))

    return random_text

# Function to replace a random word with its synonym
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)

st.title('Joke Parts Voting Game')
st.write('Upvote or downvote the funny joke parts generated below!')

# Create thumbs up and thumbs down buttons
thumbs_up = st.button('πŸ‘')
thumbs_down = st.button('πŸ‘Ž')

# Initialize upvote and downvote counts
upvotes = 0
downvotes = 0

# Increment upvote or downvote count when corresponding button is clicked
if thumbs_up:
    upvotes += 1
elif thumbs_down:
    downvotes += 1

# Display upvote and downvote count
st.write(f'πŸ‘ {upvotes} | πŸ‘Ž {downvotes}')

# Create scoreboard using pandas and display it
scoreboard = pd.DataFrame({'Upvotes': [upvotes], 'Downvotes': [downvotes]})
st.write(scoreboard)

# Save scoreboard to output CSV file
scoreboard.to_csv('output.csv', index=False)

# Generate a random text and replace a word with a synonym
original_text = generate_text()
modified_text = replace_with_synonym(original_text)

# Display the modified text
st.write(f'🀣 {modified_text}')