Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,36 +3,13 @@ import random
|
|
3 |
from transformers import pipeline
|
4 |
|
5 |
# Load the model once when the app starts
|
6 |
-
generator = pipeline('text-generation', model='distilgpt2', max_length=25)
|
7 |
|
8 |
# Predefined words to check
|
9 |
-
SPECIAL_WORDS = [
|
10 |
-
'movie', 'excited', 'waiting', 'long', 'time', 'production', 'real', 'coded', 'digital', 'favorite',
|
11 |
-
'asking', 'doing', 'basketball', 'soccer', 'football', 'baseball', 'soup', 'food', 'burgers', 'pizza',
|
12 |
-
'fruit', 'pineapple', 'milk', 'jello', 'candy', 'rice', 'greens', 'lettuce', 'oatmeal', 'cereal',
|
13 |
-
'dogs', 'cats', 'animals', 'goats', 'sheep', 'movies', 'money', 'bank', 'account', 'keeping',
|
14 |
-
'looking', 'moving', 'boxes', 'elephants', 'movement', 'coding', 'developing', 'going', 'cruise',
|
15 |
-
'ship', 'boat', 'bahamas', 'foods', 'healthy', 'eating', 'important', 'pennsylvania', 'atlanta',
|
16 |
-
'north carolina', 'new york', 'france', 'paris', 'work', 'jobs', 'computers', 'computer', 'grocery',
|
17 |
-
'glamorous', 'version', 'truck', 'pickup', 'play', 'types', 'games', 'applications', 'quantum',
|
18 |
-
'speeds', 'advancements', 'technological', 'glimpse', 'countless', 'technology', 'future', 'walking',
|
19 |
-
'hello', 'jordan', 'season', 'superstar', 'nba', 'championship', 'leading', 'points', 'assist',
|
20 |
-
'career', 'chicago', 'scared', 'tongue', 'energy', 'disguise', 'business', 'older', 'grown', 'call',
|
21 |
-
'bills', 'garden', 'house', 'fallen', 'blossoms', 'lawn', 'love', 'forever', 'most', 'fan', 'clout',
|
22 |
-
'space', 'team', 'today', 'woke', 'work', 'relax', 'quicker', 'thicker', 'richer', 'data', 'ballet',
|
23 |
-
'dancer', 'goat', 'post', 'lebron', 'james', 'eagles', 'rockets', 'times', 'tank', 'pencil', 'watch',
|
24 |
-
'rolex', 'rappers', 'rockstar', 'rocket', 'rocks', 'tooth', 'teeth', 'pancake', 'breakfast', 'lunch',
|
25 |
-
'dinner', 'zoom', 'calling', 'talking', 'rule', 'ruler', 'rick', 'morty', 'martin', 'smith', 'wild',
|
26 |
-
'track', 'field', 'touchdown', 'basket', 'hope', 'yours', 'thank', 'olympics', 'sports', 'help',
|
27 |
-
'legal', 'law', 'firm', 'crowd', 'winner', 'winter', 'smoking', 'green', 'purple', 'blue', 'pink',
|
28 |
-
'orange', 'black', 'white', 'yellow', 'gold', 'weather', 'sun', 'middle', 'summer', 'heat', 'spring'
|
29 |
-
]
|
30 |
-
# Global variables
|
31 |
-
initial_word_design = ""
|
32 |
-
special_word = ""
|
33 |
|
34 |
-
def
|
35 |
-
"""Generate
|
36 |
fonts = [
|
37 |
"'VT323', monospace",
|
38 |
"'Josefin Sans', sans-serif",
|
@@ -43,16 +20,10 @@ def generate_initial_design(word):
|
|
43 |
"'Nothing You Could Do', cursive",
|
44 |
"'Reenie Beanie', cursive",
|
45 |
"'Orbitron', sans-serif",
|
46 |
-
"'Raleway', sans-serif"
|
47 |
-
"'Open Sans Condensed', sans-serif",
|
48 |
-
"'Poiret One', cursive",
|
49 |
-
"'Indie Flower', cursive",
|
50 |
-
"'Pacifico', cursive",
|
51 |
-
"'Teko', sans-serif"
|
52 |
]
|
53 |
-
font_sizes = ["18px", "19px", "20px"]
|
54 |
-
|
55 |
-
letter_spacings = ["-1px", "0px", "1px"] # Reduced range
|
56 |
text_shadows = [
|
57 |
"0px 0px 1px",
|
58 |
"0px 0px 2px",
|
@@ -64,105 +35,34 @@ def generate_initial_design(word):
|
|
64 |
"1px 1px 0px",
|
65 |
"1px 0px 1px"
|
66 |
]
|
67 |
-
skew_angles = ["-
|
68 |
|
69 |
letters = list(word)
|
70 |
styled_letters = []
|
71 |
|
72 |
-
|
73 |
-
style = {
|
74 |
-
'font-family': random.choice(fonts),
|
75 |
-
'line-height': '1.6', # Consistent with body text
|
76 |
-
'font-size': random.choice(font_sizes),
|
77 |
-
'letter-spacing': random.choice(letter_spacings),
|
78 |
-
'text-shadow': random.choice(text_shadows),
|
79 |
-
'transform': f'skew({random.choice(skew_angles)})',
|
80 |
-
'margin-top': random.choice(["-0.02cm", "0.00cm", "0.02cm"]), # Reduced range
|
81 |
-
'position': 'relative',
|
82 |
-
'top': random.choice(font_tops),
|
83 |
-
'color': '#000000',
|
84 |
-
'display': 'inline-block',
|
85 |
-
'margin': '0 1px',
|
86 |
-
'vertical-align': 'middle'
|
87 |
-
}
|
88 |
-
|
89 |
-
style_str = '; '.join([f'{k}: {v}' for k, v in style.items()])
|
90 |
-
styled_letter = f'<span class="styled-letter" style="{style_str}">{letter}</span>'
|
91 |
-
styled_letters.append(styled_letter)
|
92 |
-
|
93 |
-
return f'''
|
94 |
-
<span style="display: inline-flex;
|
95 |
-
align-items: baseline;
|
96 |
-
vertical-align: middle;
|
97 |
-
margin: 0 2px;">
|
98 |
-
{" ".join(styled_letters)}
|
99 |
-
</span>'''
|
100 |
-
|
101 |
-
def generate_movement_design(word):
|
102 |
-
"""Generate a completely new random design for the movement animation."""
|
103 |
-
fonts = [
|
104 |
-
"'VT323', monospace",
|
105 |
-
"'Josefin Sans', sans-serif",
|
106 |
-
"'Rajdhani', sans-serif",
|
107 |
-
"'Anton', sans-serif",
|
108 |
-
"'Caveat', cursive",
|
109 |
-
"'Patrick Hand', cursive",
|
110 |
-
"'Nothing You Could Do', cursive",
|
111 |
-
"'Reenie Beanie', cursive",
|
112 |
-
"'Orbitron', sans-serif",
|
113 |
-
"'Raleway', sans-serif"
|
114 |
-
]
|
115 |
-
font_sizes = ["18px", "19px", "20px"] # Narrower range
|
116 |
-
font_tops = ["0px", "1px", "-1px"] # Smaller adjustments
|
117 |
-
letter_spacings = ["-1px", "0px", "1px"] # Reduced range
|
118 |
-
text_shadows = [
|
119 |
-
"0px 0px 1px",
|
120 |
-
"0px 0px 2px",
|
121 |
-
"1px 0px 0px",
|
122 |
-
"0px 0px 0px",
|
123 |
-
"0px 1px 0px",
|
124 |
-
"0px 2px 0px",
|
125 |
-
"0px 1px 1px",
|
126 |
-
"1px 1px 0px",
|
127 |
-
"1px 0px 1px"
|
128 |
-
]
|
129 |
-
skew_angles = ["-25deg", "-20deg", "-15deg", "-10deg", "0deg", "10deg", "15deg", "20deg", "25deg"]
|
130 |
-
|
131 |
-
# Generate random color for the movement design
|
132 |
-
random_color = f'#{random.randint(0, 0xFFFFFF):06x}'
|
133 |
-
|
134 |
-
# Generate unique animation name
|
135 |
-
animation_name = f"animate_{random.randint(0, 10000)}"
|
136 |
-
|
137 |
-
# Create keyframes for the animation sequence
|
138 |
keyframes = f"""
|
139 |
@keyframes {animation_name} {{
|
140 |
0% {{ transform: scale(1) rotate(0deg); }}
|
141 |
50% {{ transform: scale(1.2) rotate(10deg); }}
|
142 |
100% {{ transform: scale(1) rotate(0deg); }}
|
143 |
}}
|
144 |
-
"""
|
145 |
|
146 |
-
letters = list(word)
|
147 |
-
styled_letters = []
|
148 |
-
|
149 |
for i, letter in enumerate(letters):
|
150 |
style = {
|
151 |
'font-family': random.choice(fonts),
|
152 |
-
'line-height': '1.6',
|
153 |
'font-size': random.choice(font_sizes),
|
154 |
'letter-spacing': random.choice(letter_spacings),
|
155 |
'text-shadow': random.choice(text_shadows),
|
156 |
'transform': f'skew({random.choice(skew_angles)})',
|
157 |
-
'
|
158 |
-
'position': 'relative',
|
159 |
-
'top': random.choice(font_tops),
|
160 |
-
'color': random_color,
|
161 |
'display': 'inline-block',
|
162 |
'margin': '0 1px',
|
163 |
'vertical-align': 'middle',
|
164 |
-
'animation': f'{animation_name} 0.5s ease-in-out',
|
165 |
-
'animation-delay': f'{i * 0.1}s'
|
166 |
}
|
167 |
|
168 |
style_str = '; '.join([f'{k}: {v}' for k, v in style.items()])
|
@@ -176,35 +76,28 @@ def generate_movement_design(word):
|
|
176 |
transition: all 0.3s ease;
|
177 |
}}
|
178 |
</style>
|
179 |
-
<span style="display: inline-flex;
|
180 |
-
align-items: baseline;
|
181 |
-
vertical-align: middle;
|
182 |
-
margin: 0 2px;">
|
183 |
{" ".join(styled_letters)}
|
184 |
</span>
|
185 |
'''
|
186 |
|
187 |
def process_text(input_text):
|
188 |
"""Process text and generate the initial output with special word styled in black."""
|
189 |
-
global initial_word_design, special_word
|
190 |
-
|
191 |
-
# Generate text with limited length
|
192 |
generated = generator(input_text, num_return_sequences=1)
|
193 |
generated_text = generated[0]['generated_text']
|
194 |
-
generated_text = generated_text[:200]
|
195 |
|
196 |
words = generated_text.split()
|
197 |
-
|
198 |
-
|
|
|
199 |
clean_word = ''.join(filter(str.isalnum, word)).lower()
|
200 |
if clean_word in SPECIAL_WORDS:
|
201 |
-
|
202 |
-
initial_word_design = generate_initial_design(word)
|
203 |
-
words[i] = initial_word_design
|
204 |
else:
|
205 |
-
|
206 |
|
207 |
-
output_html = ' '.join(
|
208 |
|
209 |
final_output = f"""
|
210 |
<html>
|
@@ -242,24 +135,17 @@ def process_text(input_text):
|
|
242 |
|
243 |
def trigger_movement(input_html):
|
244 |
"""Function to trigger the movement animation for all special words."""
|
245 |
-
global initial_word_design, special_word
|
246 |
-
|
247 |
-
# Split the input HTML into words
|
248 |
words = input_html.split()
|
249 |
-
|
250 |
-
# Iterate over each word and apply movement design if it's a special word
|
251 |
updated_words = []
|
|
|
252 |
for word in words:
|
253 |
clean_word = ''.join(filter(str.isalnum, word)).lower()
|
254 |
if clean_word in SPECIAL_WORDS:
|
255 |
-
|
256 |
-
updated_words.append(movement_design)
|
257 |
else:
|
258 |
updated_words.append(word)
|
259 |
|
260 |
-
# Join the updated words back into a single HTML string
|
261 |
updated_html = ' '.join(updated_words)
|
262 |
-
|
263 |
return updated_html
|
264 |
|
265 |
# Create Gradio interface using Blocks
|
|
|
3 |
from transformers import pipeline
|
4 |
|
5 |
# Load the model once when the app starts
|
6 |
+
generator = pipeline('text-generation', model='distilgpt2', max_length=25)
|
7 |
|
8 |
# Predefined words to check
|
9 |
+
SPECIAL_WORDS = ['weather', 'sun', 'middle', 'summer', 'heat', 'spring', 'winter']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
+
def generate_design(word, color='#000000', animate=False):
|
12 |
+
"""Generate design for the special word."""
|
13 |
fonts = [
|
14 |
"'VT323', monospace",
|
15 |
"'Josefin Sans', sans-serif",
|
|
|
20 |
"'Nothing You Could Do', cursive",
|
21 |
"'Reenie Beanie', cursive",
|
22 |
"'Orbitron', sans-serif",
|
23 |
+
"'Raleway', sans-serif"
|
|
|
|
|
|
|
|
|
|
|
24 |
]
|
25 |
+
font_sizes = ["18px", "19px", "20px"]
|
26 |
+
letter_spacings = ["-1px", "0px", "1px"]
|
|
|
27 |
text_shadows = [
|
28 |
"0px 0px 1px",
|
29 |
"0px 0px 2px",
|
|
|
35 |
"1px 1px 0px",
|
36 |
"1px 0px 1px"
|
37 |
]
|
38 |
+
skew_angles = ["-10deg", "0deg", "10deg"]
|
39 |
|
40 |
letters = list(word)
|
41 |
styled_letters = []
|
42 |
|
43 |
+
animation_name = f"animate_{random.randint(0, 10000)}" if animate else ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
keyframes = f"""
|
45 |
@keyframes {animation_name} {{
|
46 |
0% {{ transform: scale(1) rotate(0deg); }}
|
47 |
50% {{ transform: scale(1.2) rotate(10deg); }}
|
48 |
100% {{ transform: scale(1) rotate(0deg); }}
|
49 |
}}
|
50 |
+
""" if animate else ""
|
51 |
|
|
|
|
|
|
|
52 |
for i, letter in enumerate(letters):
|
53 |
style = {
|
54 |
'font-family': random.choice(fonts),
|
55 |
+
'line-height': '1.6',
|
56 |
'font-size': random.choice(font_sizes),
|
57 |
'letter-spacing': random.choice(letter_spacings),
|
58 |
'text-shadow': random.choice(text_shadows),
|
59 |
'transform': f'skew({random.choice(skew_angles)})',
|
60 |
+
'color': color,
|
|
|
|
|
|
|
61 |
'display': 'inline-block',
|
62 |
'margin': '0 1px',
|
63 |
'vertical-align': 'middle',
|
64 |
+
'animation': f'{animation_name} 0.5s ease-in-out' if animate else '',
|
65 |
+
'animation-delay': f'{i * 0.1}s' if animate else ''
|
66 |
}
|
67 |
|
68 |
style_str = '; '.join([f'{k}: {v}' for k, v in style.items()])
|
|
|
76 |
transition: all 0.3s ease;
|
77 |
}}
|
78 |
</style>
|
79 |
+
<span style="display: inline-flex; align-items: baseline; vertical-align: middle; margin: 0 2px;">
|
|
|
|
|
|
|
80 |
{" ".join(styled_letters)}
|
81 |
</span>
|
82 |
'''
|
83 |
|
84 |
def process_text(input_text):
|
85 |
"""Process text and generate the initial output with special word styled in black."""
|
|
|
|
|
|
|
86 |
generated = generator(input_text, num_return_sequences=1)
|
87 |
generated_text = generated[0]['generated_text']
|
88 |
+
generated_text = generated_text[:200]
|
89 |
|
90 |
words = generated_text.split()
|
91 |
+
processed_words = []
|
92 |
+
|
93 |
+
for word in words:
|
94 |
clean_word = ''.join(filter(str.isalnum, word)).lower()
|
95 |
if clean_word in SPECIAL_WORDS:
|
96 |
+
processed_words.append(generate_design(word))
|
|
|
|
|
97 |
else:
|
98 |
+
processed_words.append(word)
|
99 |
|
100 |
+
output_html = ' '.join(processed_words)
|
101 |
|
102 |
final_output = f"""
|
103 |
<html>
|
|
|
135 |
|
136 |
def trigger_movement(input_html):
|
137 |
"""Function to trigger the movement animation for all special words."""
|
|
|
|
|
|
|
138 |
words = input_html.split()
|
|
|
|
|
139 |
updated_words = []
|
140 |
+
|
141 |
for word in words:
|
142 |
clean_word = ''.join(filter(str.isalnum, word)).lower()
|
143 |
if clean_word in SPECIAL_WORDS:
|
144 |
+
updated_words.append(generate_design(clean_word, color=f'#{random.randint(0, 0xFFFFFF):06x}', animate=True))
|
|
|
145 |
else:
|
146 |
updated_words.append(word)
|
147 |
|
|
|
148 |
updated_html = ' '.join(updated_words)
|
|
|
149 |
return updated_html
|
150 |
|
151 |
# Create Gradio interface using Blocks
|