File size: 1,678 Bytes
446ed41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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.*
""")