Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from random import choice, sample
|
3 |
+
import pronouncing
|
4 |
+
import emoji
|
5 |
+
|
6 |
+
# Function to add emojis to a line
|
7 |
+
def add_emojis(line, emojis):
|
8 |
+
return ' '.join([emoji.emojize(f":{e}:") + word for word, e in zip(line.split(), cycle(emojis))])
|
9 |
+
|
10 |
+
# Function to generate a line of the tongue twister
|
11 |
+
def generate_line(keyword, humor_words, complexity, emojis):
|
12 |
+
rhymes = pronouncing.rhymes(keyword)
|
13 |
+
if not rhymes:
|
14 |
+
return "No rhymes found."
|
15 |
+
rhyme_words = sample(rhymes, min(len(rhymes), complexity))
|
16 |
+
line = f"{keyword.capitalize()} {choice(humor_words)} {' '.join(rhyme_words)},"
|
17 |
+
return add_emojis(line, emojis)
|
18 |
+
|
19 |
+
# Function to generate a tongue twister
|
20 |
+
def generate_tongue_twister(complexity):
|
21 |
+
keywords = ['duck', 'light', 'night', 'spike', 'fight', 'kite']
|
22 |
+
humor_words = ['jumps over', 'shines bright', 'takes flight', 'ignites', 'bites tight', 'flies a kite']
|
23 |
+
emoji_themes = [['duck', 'star', 'moon', 'zap', 'boxing_glove', 'kite']]
|
24 |
+
twister = []
|
25 |
+
for _ in range(4):
|
26 |
+
for keyword, emoji_theme in zip(keywords, emoji_themes):
|
27 |
+
twister.append(generate_line(keyword, humor_words, complexity, emoji_theme))
|
28 |
+
return ' '.join(twister)
|
29 |
+
|
30 |
+
# Streamlit UI
|
31 |
+
st.title("π The Ultimate Emoji-Rich Tongue Twister Generator π")
|
32 |
+
|
33 |
+
complexity = st.slider("Select the complexity of the tongue twister", 1, 5, 2)
|
34 |
+
|
35 |
+
if st.button('Generate Tongue Twister'):
|
36 |
+
twister = generate_tongue_twister(complexity)
|
37 |
+
st.markdown(f"**Tongue Twister:**\n\n> {twister}")
|
38 |
+
|
39 |
+
st.markdown("""
|
40 |
+
*Note: This app generates humorous, emoji-rich, and rhyming tongue twisters. Adjust the complexity to change the length and challenge.*
|
41 |
+
""")
|