awacke1's picture
Create app.py
446ed41 verified
raw
history blame
1.68 kB
import streamlit as st
from random import choice, sample
import pronouncing
import emoji
# Function to add emojis to a line
def add_emojis(line, emojis):
return ' '.join([emoji.emojize(f":{e}:") + word for word, e in zip(line.split(), cycle(emojis))])
# Function to generate a line of the tongue twister
def generate_line(keyword, humor_words, complexity, emojis):
rhymes = pronouncing.rhymes(keyword)
if not rhymes:
return "No rhymes found."
rhyme_words = sample(rhymes, min(len(rhymes), complexity))
line = f"{keyword.capitalize()} {choice(humor_words)} {' '.join(rhyme_words)},"
return add_emojis(line, emojis)
# Function to generate a tongue twister
def generate_tongue_twister(complexity):
keywords = ['duck', 'light', 'night', 'spike', 'fight', 'kite']
humor_words = ['jumps over', 'shines bright', 'takes flight', 'ignites', 'bites tight', 'flies a kite']
emoji_themes = [['duck', 'star', 'moon', 'zap', 'boxing_glove', 'kite']]
twister = []
for _ in range(4):
for keyword, emoji_theme in zip(keywords, emoji_themes):
twister.append(generate_line(keyword, humor_words, complexity, emoji_theme))
return ' '.join(twister)
# Streamlit UI
st.title("🌟 The Ultimate Emoji-Rich Tongue Twister Generator 🌟")
complexity = st.slider("Select the complexity of the tongue twister", 1, 5, 2)
if st.button('Generate Tongue Twister'):
twister = generate_tongue_twister(complexity)
st.markdown(f"**Tongue Twister:**\n\n> {twister}")
st.markdown("""
*Note: This app generates humorous, emoji-rich, and rhyming tongue twisters. Adjust the complexity to change the length and challenge.*
""")