Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,10 @@ import gradio as gr
|
|
2 |
import random
|
3 |
import time
|
4 |
|
|
|
|
|
|
|
|
|
5 |
def generate_initial_design(word):
|
6 |
"""Generate initial design for the special word in black color."""
|
7 |
fonts = [
|
@@ -14,7 +18,12 @@ def generate_initial_design(word):
|
|
14 |
"'Nothing You Could Do', cursive",
|
15 |
"'Reenie Beanie', cursive",
|
16 |
"'Orbitron', sans-serif",
|
17 |
-
"'Raleway', sans-serif"
|
|
|
|
|
|
|
|
|
|
|
18 |
]
|
19 |
font_sizes = ["18px", "19px", "20px"]
|
20 |
font_tops = ["0px", "1px", "-1px"]
|
@@ -57,7 +66,7 @@ def generate_initial_design(word):
|
|
57 |
styled_letters.append(styled_letter)
|
58 |
|
59 |
return f'''
|
60 |
-
<span style="display: inline-flex;
|
61 |
align-items: baseline;
|
62 |
vertical-align: middle;
|
63 |
margin: 0 2px;">
|
@@ -142,7 +151,7 @@ def generate_movement_design(word):
|
|
142 |
transition: all 0.3s ease;
|
143 |
}}
|
144 |
</style>
|
145 |
-
<span style="display: inline-flex;
|
146 |
align-items: baseline;
|
147 |
vertical-align: middle;
|
148 |
margin: 0 2px;">
|
@@ -151,6 +160,8 @@ def generate_movement_design(word):
|
|
151 |
'''
|
152 |
|
153 |
def typing_effect():
|
|
|
|
|
154 |
paragraphs = [
|
155 |
'Proctors\'s voice quavered, "Where are we, Benshiro? This can\'t be real. We went full speed into that..."',
|
156 |
'"Proctor, I hear you! Is that you? I\'m so thankful, but where are you? I can\'t see you." Benshiro\'s words echoed in the void.'
|
@@ -158,17 +169,23 @@ def typing_effect():
|
|
158 |
|
159 |
# Process paragraphs to add styling
|
160 |
styled_paragraphs = []
|
|
|
|
|
|
|
161 |
for paragraph in paragraphs:
|
162 |
words = paragraph.split()
|
163 |
-
if words:
|
164 |
special_word = random.choice(words)
|
|
|
165 |
styled_word = generate_initial_design(special_word)
|
|
|
166 |
styled_paragraph = ' '.join(word if word != special_word else styled_word for word in words)
|
167 |
styled_paragraphs.append(styled_paragraph)
|
168 |
|
169 |
-
#
|
170 |
-
|
171 |
|
|
|
172 |
final_output = f"""
|
173 |
<html>
|
174 |
<head>
|
@@ -191,12 +208,36 @@ def typing_effect():
|
|
191 |
font-family: "Josefin Sans", sans-serif;
|
192 |
padding: 20px;
|
193 |
}}
|
|
|
|
|
|
|
194 |
</style>
|
195 |
</head>
|
196 |
<body>
|
197 |
-
<div style='max-width: 800px; margin: auto;'>
|
198 |
-
|
199 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
200 |
</body>
|
201 |
</html>
|
202 |
"""
|
@@ -205,12 +246,17 @@ def typing_effect():
|
|
205 |
|
206 |
def trigger_movement(input_html):
|
207 |
"""Function to trigger the movement animation."""
|
208 |
-
|
|
|
|
|
209 |
return input_html
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
|
|
|
|
|
|
214 |
|
215 |
# Create Gradio interface using Blocks
|
216 |
with gr.Blocks() as demo:
|
@@ -219,10 +265,13 @@ with gr.Blocks() as demo:
|
|
219 |
output_html = gr.HTML()
|
220 |
with gr.Row():
|
221 |
start_btn = gr.Button("▶ Start Typing")
|
222 |
-
animate_btn = gr.Button("✨
|
223 |
|
224 |
start_btn.click(typing_effect, inputs=[], outputs=output_html)
|
225 |
animate_btn.click(trigger_movement, inputs=output_html, outputs=output_html)
|
226 |
|
|
|
|
|
|
|
227 |
# Launch the app
|
228 |
demo.launch()
|
|
|
2 |
import random
|
3 |
import time
|
4 |
|
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."""
|
11 |
fonts = [
|
|
|
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"]
|
|
|
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;">
|
|
|
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;">
|
|
|
160 |
'''
|
161 |
|
162 |
def typing_effect():
|
163 |
+
global initial_word_designs, special_words
|
164 |
+
|
165 |
paragraphs = [
|
166 |
'Proctors\'s voice quavered, "Where are we, Benshiro? This can\'t be real. We went full speed into that..."',
|
167 |
'"Proctor, I hear you! Is that you? I\'m so thankful, but where are you? I can\'t see you." Benshiro\'s words echoed in the void.'
|
|
|
169 |
|
170 |
# Process paragraphs to add styling
|
171 |
styled_paragraphs = []
|
172 |
+
initial_word_designs = []
|
173 |
+
special_words = []
|
174 |
+
|
175 |
for paragraph in paragraphs:
|
176 |
words = paragraph.split()
|
177 |
+
if words:
|
178 |
special_word = random.choice(words)
|
179 |
+
special_words.append(special_word)
|
180 |
styled_word = generate_initial_design(special_word)
|
181 |
+
initial_word_designs.append(styled_word)
|
182 |
styled_paragraph = ' '.join(word if word != special_word else styled_word for word in words)
|
183 |
styled_paragraphs.append(styled_paragraph)
|
184 |
|
185 |
+
# Join paragraphs with proper spacing
|
186 |
+
all_text = ' '.join(styled_paragraphs)
|
187 |
|
188 |
+
# Create HTML with chatbot-style reveal animation
|
189 |
final_output = f"""
|
190 |
<html>
|
191 |
<head>
|
|
|
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 |
+
<script>
|
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 |
"""
|
|
|
246 |
|
247 |
def trigger_movement(input_html):
|
248 |
"""Function to trigger the movement animation."""
|
249 |
+
global initial_word_designs, special_words
|
250 |
+
|
251 |
+
if not initial_word_designs or not special_words:
|
252 |
return input_html
|
253 |
+
|
254 |
+
updated_html = input_html
|
255 |
+
for i, (initial_design, special_word) in enumerate(zip(initial_word_designs, special_words)):
|
256 |
+
movement_design = generate_movement_design(special_word)
|
257 |
+
updated_html = updated_html.replace(initial_design, movement_design, 1)
|
258 |
+
|
259 |
+
return updated_html
|
260 |
|
261 |
# Create Gradio interface using Blocks
|
262 |
with gr.Blocks() as demo:
|
|
|
265 |
output_html = gr.HTML()
|
266 |
with gr.Row():
|
267 |
start_btn = gr.Button("▶ Start Typing")
|
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=output_html, outputs=output_html)
|
272 |
|
273 |
+
# Launch the app
|
274 |
+
demo.launch()
|
275 |
+
|
276 |
# Launch the app
|
277 |
demo.launch()
|