Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,7 @@ import time
|
|
5 |
# Global variables
|
6 |
initial_word_designs = []
|
7 |
special_words = []
|
|
|
8 |
|
9 |
def generate_initial_design(word):
|
10 |
"""Generate initial design for the special word in black color."""
|
@@ -18,12 +19,7 @@ def generate_initial_design(word):
|
|
18 |
"'Nothing You Could Do', cursive",
|
19 |
"'Reenie Beanie', cursive",
|
20 |
"'Orbitron', sans-serif",
|
21 |
-
"'Raleway', sans-serif"
|
22 |
-
"'Open Sans Condensed', sans-serif",
|
23 |
-
"'Poiret One', cursive",
|
24 |
-
"'Indie Flower', cursive",
|
25 |
-
"'Pacifico', cursive",
|
26 |
-
"'Teko', sans-serif"
|
27 |
]
|
28 |
font_sizes = ["18px", "19px", "20px"]
|
29 |
font_tops = ["0px", "1px", "-1px"]
|
@@ -65,13 +61,7 @@ def generate_initial_design(word):
|
|
65 |
styled_letter = f'<span class="styled-letter" style="{style_str}">{letter}</span>'
|
66 |
styled_letters.append(styled_letter)
|
67 |
|
68 |
-
return f''
|
69 |
-
<span class="special-word" style="display: inline-flex;
|
70 |
-
align-items: baseline;
|
71 |
-
vertical-align: middle;
|
72 |
-
margin: 0 2px;">
|
73 |
-
{" ".join(styled_letters)}
|
74 |
-
</span>'''
|
75 |
|
76 |
def generate_movement_design(word):
|
77 |
"""Generate a completely new random design for the movement animation."""
|
@@ -105,18 +95,6 @@ def generate_movement_design(word):
|
|
105 |
|
106 |
# Generate random color for the movement design
|
107 |
random_color = f'#{random.randint(0, 0xFFFFFF):06x}'
|
108 |
-
|
109 |
-
# Generate unique animation name
|
110 |
-
animation_name = f"animate_{random.randint(0, 10000)}"
|
111 |
-
|
112 |
-
# Create keyframes for the animation sequence
|
113 |
-
keyframes = f"""
|
114 |
-
@keyframes {animation_name} {{
|
115 |
-
0% {{ transform: scale(1) rotate(0deg); }}
|
116 |
-
50% {{ transform: scale(1.2) rotate(10deg); }}
|
117 |
-
100% {{ transform: scale(1) rotate(0deg); }}
|
118 |
-
}}
|
119 |
-
"""
|
120 |
|
121 |
letters = list(word)
|
122 |
styled_letters = []
|
@@ -135,36 +113,21 @@ def generate_movement_design(word):
|
|
135 |
'color': random_color,
|
136 |
'display': 'inline-block',
|
137 |
'margin': '0 1px',
|
138 |
-
'vertical-align': 'middle'
|
139 |
-
'animation': f'{animation_name} 0.5s ease-in-out',
|
140 |
-
'animation-delay': f'{i * 0.1}s'
|
141 |
}
|
142 |
|
143 |
style_str = '; '.join([f'{k}: {v}' for k, v in style.items()])
|
144 |
styled_letter = f'<span class="styled-letter" style="{style_str}">{letter}</span>'
|
145 |
styled_letters.append(styled_letter)
|
146 |
|
147 |
-
return f''
|
148 |
-
<style>
|
149 |
-
{keyframes}
|
150 |
-
.styled-letter {{
|
151 |
-
transition: all 0.3s ease;
|
152 |
-
}}
|
153 |
-
</style>
|
154 |
-
<span class="special-word" style="display: inline-flex;
|
155 |
-
align-items: baseline;
|
156 |
-
vertical-align: middle;
|
157 |
-
margin: 0 2px;">
|
158 |
-
{" ".join(styled_letters)}
|
159 |
-
</span>
|
160 |
-
'''
|
161 |
|
162 |
def typing_effect():
|
163 |
-
global initial_word_designs, special_words
|
164 |
|
165 |
paragraphs = [
|
166 |
-
'Proctors
|
167 |
-
'"Proctor, I hear you! Is that you?
|
168 |
]
|
169 |
|
170 |
# Process paragraphs to add styling
|
@@ -182,81 +145,45 @@ def typing_effect():
|
|
182 |
styled_paragraph = ' '.join(word if word != special_word else styled_word for word in words)
|
183 |
styled_paragraphs.append(styled_paragraph)
|
184 |
|
185 |
-
|
186 |
-
|
|
|
|
|
|
|
187 |
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
<
|
193 |
-
|
194 |
-
<link href="https://fonts.googleapis.com/css2?family=Rajdhani:wght@300&display=swap" rel="stylesheet">
|
195 |
-
<link href="https://fonts.googleapis.com/css2?family=Anton&display=swap" rel="stylesheet">
|
196 |
-
<link href="https://fonts.googleapis.com/css2?family=Caveat&display=swap" rel="stylesheet">
|
197 |
-
<link href="https://fonts.googleapis.com/css2?family=Patrick+Hand&display=swap" rel="stylesheet">
|
198 |
-
<link href="https://fonts.googleapis.com/css2?family=Nothing+You+Could+Do&display=swap" rel="stylesheet">
|
199 |
-
<link href="https://fonts.googleapis.com/css2?family=Reenie+Beanie&display=swap" rel="stylesheet">
|
200 |
-
<link href="https://fonts.googleapis.com/css2?family=Orbitron&display=swap" rel="stylesheet">
|
201 |
-
<link href="https://fonts.googleapis.com/css?family=Raleway:500" rel="stylesheet">
|
202 |
-
<style>
|
203 |
-
body {{
|
204 |
-
background-color: #fff;
|
205 |
-
color: #000;
|
206 |
-
font-size: 18px;
|
207 |
-
line-height: 1.6;
|
208 |
-
font-family: "Josefin Sans", sans-serif;
|
209 |
-
padding: 20px;
|
210 |
-
}}
|
211 |
-
.styled-letter {{
|
212 |
-
transition: all 0.3s ease;
|
213 |
-
}}
|
214 |
-
</style>
|
215 |
-
</head>
|
216 |
-
<body>
|
217 |
-
<div style='max-width: 800px; margin: auto;' id="text-content">
|
218 |
-
<!-- Content will be revealed here -->
|
219 |
</div>
|
220 |
-
|
221 |
-
function revealText() {{
|
222 |
-
const container = document.getElementById('text-content');
|
223 |
-
const fullText = `{all_text}`;
|
224 |
-
const words = fullText.split(' ');
|
225 |
-
container.innerHTML = '';
|
226 |
-
let i = 0;
|
227 |
-
|
228 |
-
function displayNextWord() {{
|
229 |
-
if (i < words.length) {{
|
230 |
-
container.innerHTML += words[i] + ' ';
|
231 |
-
i++;
|
232 |
-
setTimeout(displayNextWord, 200); // Adjust speed here
|
233 |
-
}}
|
234 |
-
}}
|
235 |
-
displayNextWord();
|
236 |
-
}}
|
237 |
-
|
238 |
-
// Start revealing text immediately
|
239 |
-
setTimeout(revealText, 500);
|
240 |
-
</script>
|
241 |
-
</body>
|
242 |
-
</html>
|
243 |
-
"""
|
244 |
|
245 |
-
return
|
|
|
|
|
|
|
|
|
246 |
|
247 |
-
def trigger_movement(
|
248 |
-
|
249 |
-
global initial_word_designs, special_words
|
250 |
|
251 |
if not initial_word_designs or not special_words:
|
252 |
-
return
|
253 |
|
254 |
-
|
255 |
for i, (initial_design, special_word) in enumerate(zip(initial_word_designs, special_words)):
|
256 |
movement_design = generate_movement_design(special_word)
|
257 |
-
|
|
|
|
|
258 |
|
259 |
-
return
|
|
|
|
|
|
|
|
|
260 |
|
261 |
# Create Gradio interface using Blocks
|
262 |
with gr.Blocks() as demo:
|
@@ -268,10 +195,7 @@ with gr.Blocks() as demo:
|
|
268 |
animate_btn = gr.Button("✨ Trigger Movement")
|
269 |
|
270 |
start_btn.click(typing_effect, inputs=[], outputs=output_html)
|
271 |
-
animate_btn.click(trigger_movement, inputs=
|
272 |
-
|
273 |
-
# Launch the app
|
274 |
-
demo.launch()
|
275 |
|
276 |
# Launch the app
|
277 |
demo.launch()
|
|
|
5 |
# Global variables
|
6 |
initial_word_designs = []
|
7 |
special_words = []
|
8 |
+
current_text = ""
|
9 |
|
10 |
def generate_initial_design(word):
|
11 |
"""Generate initial design for the special word in black color."""
|
|
|
19 |
"'Nothing You Could Do', cursive",
|
20 |
"'Reenie Beanie', cursive",
|
21 |
"'Orbitron', sans-serif",
|
22 |
+
"'Raleway', sans-serif"
|
|
|
|
|
|
|
|
|
|
|
23 |
]
|
24 |
font_sizes = ["18px", "19px", "20px"]
|
25 |
font_tops = ["0px", "1px", "-1px"]
|
|
|
61 |
styled_letter = f'<span class="styled-letter" style="{style_str}">{letter}</span>'
|
62 |
styled_letters.append(styled_letter)
|
63 |
|
64 |
+
return f'<span class="special-word">{" ".join(styled_letters)}</span>'
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
def generate_movement_design(word):
|
67 |
"""Generate a completely new random design for the movement animation."""
|
|
|
95 |
|
96 |
# Generate random color for the movement design
|
97 |
random_color = f'#{random.randint(0, 0xFFFFFF):06x}'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
letters = list(word)
|
100 |
styled_letters = []
|
|
|
113 |
'color': random_color,
|
114 |
'display': 'inline-block',
|
115 |
'margin': '0 1px',
|
116 |
+
'vertical-align': 'middle'
|
|
|
|
|
117 |
}
|
118 |
|
119 |
style_str = '; '.join([f'{k}: {v}' for k, v in style.items()])
|
120 |
styled_letter = f'<span class="styled-letter" style="{style_str}">{letter}</span>'
|
121 |
styled_letters.append(styled_letter)
|
122 |
|
123 |
+
return f'<span class="special-word">{" ".join(styled_letters)}</span>'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
|
125 |
def typing_effect():
|
126 |
+
global initial_word_designs, special_words, current_text
|
127 |
|
128 |
paragraphs = [
|
129 |
+
'Proctors voice quavered, "Where are we, Benshiro? This cant be real. We went full speed into that..."',
|
130 |
+
'"Proctor, I hear you! Is that you? Im so thankful, but where are you? I cant see you." Benshiros words echoed in the void.'
|
131 |
]
|
132 |
|
133 |
# Process paragraphs to add styling
|
|
|
145 |
styled_paragraph = ' '.join(word if word != special_word else styled_word for word in words)
|
146 |
styled_paragraphs.append(styled_paragraph)
|
147 |
|
148 |
+
current_text = '<br><br>'.join(styled_paragraphs)
|
149 |
+
|
150 |
+
# Simulate typing effect by yielding incremental text
|
151 |
+
words = current_text.split()
|
152 |
+
displayed_text = ""
|
153 |
|
154 |
+
for i, word in enumerate(words):
|
155 |
+
displayed_text += word + " "
|
156 |
+
time.sleep(0.1) # Small delay
|
157 |
+
yield f"""
|
158 |
+
<div style="font-family: 'Josefin Sans', sans-serif; font-size: 18px; line-height: 1.6; padding: 20px; max-width: 800px;">
|
159 |
+
{displayed_text}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
</div>
|
161 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
|
163 |
+
return f"""
|
164 |
+
<div style="font-family: 'Josefin Sans', sans-serif; font-size: 18px; line-height: 1.6; padding: 20px; max-width: 800px;">
|
165 |
+
{current_text}
|
166 |
+
</div>
|
167 |
+
"""
|
168 |
|
169 |
+
def trigger_movement():
|
170 |
+
global initial_word_designs, special_words, current_text
|
|
|
171 |
|
172 |
if not initial_word_designs or not special_words:
|
173 |
+
return current_text
|
174 |
|
175 |
+
updated_text = current_text
|
176 |
for i, (initial_design, special_word) in enumerate(zip(initial_word_designs, special_words)):
|
177 |
movement_design = generate_movement_design(special_word)
|
178 |
+
updated_text = updated_text.replace(initial_design, movement_design, 1)
|
179 |
+
|
180 |
+
current_text = updated_text
|
181 |
|
182 |
+
return f"""
|
183 |
+
<div style="font-family: 'Josefin Sans', sans-serif; font-size: 18px; line-height: 1.6; padding: 20px; max-width: 800px;">
|
184 |
+
{updated_text}
|
185 |
+
</div>
|
186 |
+
"""
|
187 |
|
188 |
# Create Gradio interface using Blocks
|
189 |
with gr.Blocks() as demo:
|
|
|
195 |
animate_btn = gr.Button("✨ Trigger Movement")
|
196 |
|
197 |
start_btn.click(typing_effect, inputs=[], outputs=output_html)
|
198 |
+
animate_btn.click(trigger_movement, inputs=[], outputs=output_html)
|
|
|
|
|
|
|
199 |
|
200 |
# Launch the app
|
201 |
demo.launch()
|