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()