Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,212 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import random
|
3 |
+
|
4 |
+
# Your predefined words list
|
5 |
+
SPECIAL_WORDS = [
|
6 |
+
'movie', 'excited', 'waiting', 'long', 'time', 'production', 'real', 'coded', 'digital', 'favorite',
|
7 |
+
'asking', 'doing', 'basketball', 'soccer', 'football', 'baseball', 'soup', 'food', 'burgers', 'pizza',
|
8 |
+
'fruit', 'pineapple', 'milk', 'jello', 'candy', 'rice', 'greens', 'lettuce', 'oatmeal', 'cereal',
|
9 |
+
'dogs', 'cats', 'animals', 'goats', 'sheep', 'movies', 'money', 'bank', 'account', 'keeping',
|
10 |
+
'looking', 'moving', 'boxes', 'elephants', 'movement', 'coding', 'developing', 'going', 'cruise',
|
11 |
+
'ship', 'boat', 'bahamas', 'foods', 'healthy', 'eating', 'important', 'pennsylvania', 'atlanta',
|
12 |
+
'north carolina', 'new york', 'france', 'paris', 'work', 'jobs', 'computers', 'computer', 'grocery',
|
13 |
+
'glamorous', 'version', 'truck', 'pickup', 'play', 'types', 'games', 'applications', 'quantum',
|
14 |
+
'speeds', 'advancements', 'technological', 'glimpse', 'countless', 'technology', 'future', 'walking',
|
15 |
+
'hello', 'jordan', 'season', 'superstar', 'nba', 'championship', 'leading', 'points', 'assist',
|
16 |
+
'career', 'chicago', 'scared', 'tongue', 'energy', 'disguise', 'business', 'older', 'grown', 'call',
|
17 |
+
'bills', 'garden', 'house', 'fallen', 'blossoms', 'lawn', 'love', 'forever', 'most', 'fan', 'clout',
|
18 |
+
'space', 'team', 'today', 'woke', 'work', 'relax', 'quicker', 'thicker', 'richer', 'data', 'ballet',
|
19 |
+
'dancer', 'goat', 'post', 'lebron', 'james', 'eagles', 'rockets', 'times', 'tank', 'pencil', 'watch',
|
20 |
+
'rolex', 'rappers', 'rockstar', 'rocket', 'rocks', 'tooth', 'teeth', 'pancake', 'breakfast', 'lunch',
|
21 |
+
'dinner', 'zoom', 'calling', 'talking', 'rule', 'ruler', 'rick', 'morty', 'martin', 'smith', 'wild',
|
22 |
+
'track', 'field', 'touchdown', 'basket', 'hope', 'yours', 'thank', 'olympics', 'sports', 'help',
|
23 |
+
'legal', 'law', 'firm', 'crowd', 'winner', 'winter', 'smoking', 'green', 'purple', 'blue', 'pink',
|
24 |
+
'orange', 'black', 'white', 'yellow', 'gold', 'weather', 'sun', 'middle', 'summer', 'heat', 'spring'
|
25 |
+
]
|
26 |
+
|
27 |
+
# Global variables
|
28 |
+
initial_designs = {}
|
29 |
+
selected_words = []
|
30 |
+
|
31 |
+
def generate_word_design(word, use_color=False):
|
32 |
+
"""Generate styled design for a word."""
|
33 |
+
fonts = [
|
34 |
+
"'VT323', monospace",
|
35 |
+
"'Josefin Sans', sans-serif",
|
36 |
+
"'Rajdhani', sans-serif",
|
37 |
+
"'Anton', sans-serif",
|
38 |
+
"'Caveat', cursive",
|
39 |
+
"'Patrick Hand', cursive",
|
40 |
+
"'Nothing You Could Do', cursive",
|
41 |
+
"'Reenie Beanie', cursive",
|
42 |
+
"'Orbitron', sans-serif",
|
43 |
+
"'Raleway', sans-serif",
|
44 |
+
"'Open Sans Condensed', sans-serif",
|
45 |
+
"'Poiret One', cursive",
|
46 |
+
"'Indie Flower', cursive",
|
47 |
+
"'Pacifico', cursive",
|
48 |
+
"'Teko', sans-serif"
|
49 |
+
]
|
50 |
+
font_sizes = ["18px", "19px", "20px"]
|
51 |
+
font_tops = ["0px", "1px", "-1px"]
|
52 |
+
letter_spacings = ["-1px", "0px", "1px"]
|
53 |
+
text_shadows = [
|
54 |
+
"0px 0px 1px",
|
55 |
+
"0px 0px 2px",
|
56 |
+
"1px 0px 0px",
|
57 |
+
"0px 0px 0px",
|
58 |
+
"0px 1px 0px",
|
59 |
+
"0px 2px 0px",
|
60 |
+
"0px 1px 1px",
|
61 |
+
"1px 1px 0px",
|
62 |
+
"1px 0px 1px"
|
63 |
+
]
|
64 |
+
skew_angles = ["-25deg", "-20deg", "-15deg", "-10deg", "0deg", "10deg", "15deg", "20deg", "25deg"]
|
65 |
+
|
66 |
+
# Choose color
|
67 |
+
color = f'#{random.randint(0, 0xFFFFFF):06x}' if use_color else '#000000'
|
68 |
+
|
69 |
+
# Generate unique animation name for movement
|
70 |
+
animation_name = f"animate_{word}_{random.randint(0, 10000)}"
|
71 |
+
|
72 |
+
letters = list(word)
|
73 |
+
styled_letters = []
|
74 |
+
|
75 |
+
for i, letter in enumerate(letters):
|
76 |
+
style = {
|
77 |
+
'font-family': random.choice(fonts),
|
78 |
+
'line-height': '1.6',
|
79 |
+
'font-size': random.choice(font_sizes),
|
80 |
+
'letter-spacing': random.choice(letter_spacings),
|
81 |
+
'text-shadow': random.choice(text_shadows),
|
82 |
+
'transform': f'skew({random.choice(skew_angles)})',
|
83 |
+
'margin-top': random.choice(["-0.02cm", "0.00cm", "0.02cm"]),
|
84 |
+
'position': 'relative',
|
85 |
+
'top': random.choice(font_tops),
|
86 |
+
'color': color,
|
87 |
+
'display': 'inline-block',
|
88 |
+
'margin': '0 1px',
|
89 |
+
'vertical-align': 'middle'
|
90 |
+
}
|
91 |
+
|
92 |
+
if use_color:
|
93 |
+
style['animation'] = f'{animation_name} 0.5s ease-in-out'
|
94 |
+
style['animation-delay'] = f'{i * 0.1}s'
|
95 |
+
|
96 |
+
style_str = '; '.join([f'{k}: {v}' for k, v in style.items()])
|
97 |
+
styled_letter = f'<span class="styled-letter" style="{style_str}">{letter}</span>'
|
98 |
+
styled_letters.append(styled_letter)
|
99 |
+
|
100 |
+
# Create keyframes for movement animation
|
101 |
+
keyframes = f"""
|
102 |
+
@keyframes {animation_name} {{
|
103 |
+
0% {{ transform: scale(1) rotate(0deg); }}
|
104 |
+
50% {{ transform: scale(1.2) rotate(10deg); }}
|
105 |
+
100% {{ transform: scale(1) rotate(0deg); }}
|
106 |
+
}}
|
107 |
+
""" if use_color else ""
|
108 |
+
|
109 |
+
return f'''
|
110 |
+
{f"<style>{keyframes}</style>" if keyframes else ""}
|
111 |
+
<span class="word-container" style="display: inline-block;
|
112 |
+
margin: 10px;
|
113 |
+
padding: 8px 12px;
|
114 |
+
border: 2px solid #333;
|
115 |
+
border-radius: 8px;
|
116 |
+
background-color: rgba(255,255,255,0.8);">
|
117 |
+
<span style="display: inline-flex;
|
118 |
+
align-items: baseline;
|
119 |
+
vertical-align: middle;">
|
120 |
+
{" ".join(styled_letters)}
|
121 |
+
</span>
|
122 |
+
</span>'''
|
123 |
+
|
124 |
+
def generate_random_words():
|
125 |
+
"""Generate 5 random words with initial styling."""
|
126 |
+
global initial_designs, selected_words
|
127 |
+
|
128 |
+
# Pick 5 random words
|
129 |
+
selected_words = random.sample(SPECIAL_WORDS, 5)
|
130 |
+
initial_designs = {}
|
131 |
+
|
132 |
+
styled_words = []
|
133 |
+
for word in selected_words:
|
134 |
+
word_design = generate_word_design(word, use_color=False)
|
135 |
+
initial_designs[word] = word_design
|
136 |
+
styled_words.append(word_design)
|
137 |
+
|
138 |
+
final_output = f"""
|
139 |
+
<html>
|
140 |
+
<head>
|
141 |
+
<link href="https://fonts.googleapis.com/css2?family=VT323&display=swap" rel="stylesheet">
|
142 |
+
<link href="https://fonts.googleapis.com/css2?family=Josefin+Sans:wght@100&display=swap" rel="stylesheet">
|
143 |
+
<link href="https://fonts.googleapis.com/css2?family=Rajdhani:wght@300&display=swap" rel="stylesheet">
|
144 |
+
<link href="https://fonts.googleapis.com/css2?family=Anton&display=swap" rel="stylesheet">
|
145 |
+
<link href="https://fonts.googleapis.com/css2?family=Caveat&display=swap" rel="stylesheet">
|
146 |
+
<link href="https://fonts.googleapis.com/css2?family=Patrick+Hand&display=swap" rel="stylesheet">
|
147 |
+
<link href="https://fonts.googleapis.com/css2?family=Nothing+You+Could+Do&display=swap" rel="stylesheet">
|
148 |
+
<link href="https://fonts.googleapis.com/css2?family=Reenie+Beanie&display=swap" rel="stylesheet">
|
149 |
+
<link href="https://fonts.googleapis.com/css2?family=Orbitron&display=swap" rel="stylesheet">
|
150 |
+
<link href="https://fonts.googleapis.com/css?family=Raleway:500" rel="stylesheet">
|
151 |
+
<link href="https://fonts.googleapis.com/css2?family=Open+Sans+Condensed:wght@300&display=swap" rel="stylesheet">
|
152 |
+
<link href="https://fonts.googleapis.com/css2?family=Poiret+One&display=swap" rel="stylesheet">
|
153 |
+
<link href="https://fonts.googleapis.com/css2?family=Indie+Flower&display=swap" rel="stylesheet">
|
154 |
+
<link href="https://fonts.googleapis.com/css2?family=Pacifico&display=swap" rel="stylesheet">
|
155 |
+
<link href="https://fonts.googleapis.com/css2?family=Teko&display=swap" rel="stylesheet">
|
156 |
+
<style>
|
157 |
+
body {{
|
158 |
+
background-color: #f5f5f5;
|
159 |
+
color: #000;
|
160 |
+
font-size: 18px;
|
161 |
+
line-height: 1.6;
|
162 |
+
font-family: "Josefin Sans", sans-serif;
|
163 |
+
padding: 20px;
|
164 |
+
}}
|
165 |
+
.styled-letter {{
|
166 |
+
transition: all 0.3s ease;
|
167 |
+
}}
|
168 |
+
</style>
|
169 |
+
</head>
|
170 |
+
<body>
|
171 |
+
<div style='max-width: 800px; margin: auto; text-align: center;'>
|
172 |
+
<h2 style="margin-bottom: 30px;">Random Styled Words</h2>
|
173 |
+
<div style="display: flex; flex-wrap: wrap; justify-content: center; align-items: center;">
|
174 |
+
{" ".join(styled_words)}
|
175 |
+
</div>
|
176 |
+
</div>
|
177 |
+
</body>
|
178 |
+
</html>
|
179 |
+
"""
|
180 |
+
|
181 |
+
return final_output
|
182 |
+
|
183 |
+
def trigger_movement(input_html):
|
184 |
+
"""Function to trigger the movement animation."""
|
185 |
+
global initial_designs, selected_words
|
186 |
+
|
187 |
+
if not initial_designs or not selected_words:
|
188 |
+
return input_html
|
189 |
+
|
190 |
+
updated_html = input_html
|
191 |
+
|
192 |
+
# Replace each word with its animated version
|
193 |
+
for word in selected_words:
|
194 |
+
if word in initial_designs:
|
195 |
+
movement_design = generate_word_design(word, use_color=True)
|
196 |
+
updated_html = updated_html.replace(initial_designs[word], movement_design, 1)
|
197 |
+
|
198 |
+
return updated_html
|
199 |
+
|
200 |
+
# Create Gradio interface using Blocks
|
201 |
+
with gr.Blocks() as demo:
|
202 |
+
gr.Markdown("# Random Word Styler\nGenerate 5 random styled words with borders and spacing!")
|
203 |
+
|
204 |
+
generate_button = gr.Button("Generate Random Words", variant="primary")
|
205 |
+
output_html = gr.HTML()
|
206 |
+
animate_button = gr.Button("Trigger Movement Animation", variant="secondary")
|
207 |
+
|
208 |
+
generate_button.click(generate_random_words, outputs=output_html)
|
209 |
+
animate_button.click(trigger_movement, inputs=output_html, outputs=output_html)
|
210 |
+
|
211 |
+
# Launch the app
|
212 |
+
demo.launch()
|