Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
|
|
2 |
import random
|
3 |
|
4 |
def generate_initial_design(word):
|
|
|
5 |
fonts = [
|
6 |
"'VT323', monospace",
|
7 |
"'Josefin Sans', sans-serif",
|
@@ -33,7 +34,7 @@ def generate_initial_design(word):
|
|
33 |
letters = list(word)
|
34 |
styled_letters = []
|
35 |
|
36 |
-
for
|
37 |
style = {
|
38 |
'font-family': random.choice(fonts),
|
39 |
'line-height': '1.6',
|
@@ -60,7 +61,7 @@ def generate_initial_design(word):
|
|
60 |
align-items: baseline;
|
61 |
vertical-align: middle;
|
62 |
margin: 0 2px;">
|
63 |
-
{"
|
64 |
</span>'''
|
65 |
|
66 |
def generate_output_html():
|
@@ -79,9 +80,7 @@ def generate_output_html():
|
|
79 |
result.append(styled_paragraph)
|
80 |
|
81 |
output_html = '<br><br>'.join(result)
|
82 |
-
return output_html
|
83 |
|
84 |
-
def create_html_with_script(output_text):
|
85 |
return f"""
|
86 |
<html>
|
87 |
<head>
|
@@ -97,63 +96,54 @@ def create_html_with_script(output_text):
|
|
97 |
}}
|
98 |
.styled-letter {{
|
99 |
transition: transform 0.3s ease;
|
100 |
-
}}
|
101 |
-
@keyframes wiggle {{
|
102 |
-
0% {{ transform: rotate(0deg); }}
|
103 |
-
50% {{ transform: rotate(5deg); }}
|
104 |
-
100% {{ transform: rotate(0deg); }}
|
105 |
-
}}
|
106 |
-
button {{
|
107 |
-
background-color: #4CAF50;
|
108 |
-
border: none;
|
109 |
-
color: white;
|
110 |
-
padding: 15px 32px;
|
111 |
-
text-align: center;
|
112 |
-
text-decoration: none;
|
113 |
display: inline-block;
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
border-radius: 8px;
|
118 |
}}
|
119 |
</style>
|
120 |
<script>
|
121 |
-
function
|
122 |
-
document.
|
123 |
-
|
124 |
-
}});
|
125 |
-
}}
|
126 |
-
|
127 |
-
function revealWords() {{
|
128 |
-
const container = document.getElementById('text-content');
|
129 |
-
const fullText = `{output_text}`;
|
130 |
-
const words = fullText.split(' ');
|
131 |
-
container.innerHTML = '';
|
132 |
let i = 0;
|
133 |
function displayWord() {{
|
134 |
if (i < words.length) {{
|
135 |
-
|
136 |
i++;
|
137 |
-
setTimeout(displayWord,
|
138 |
}}
|
139 |
}}
|
140 |
displayWord();
|
141 |
}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
</script>
|
143 |
</head>
|
144 |
<body>
|
145 |
-
<div style='max-width: 800px; margin: auto;'
|
146 |
-
|
147 |
-
|
|
|
|
|
|
|
148 |
</body>
|
149 |
</html>
|
150 |
"""
|
151 |
|
152 |
-
# Create Gradio interface using Blocks
|
153 |
with gr.Blocks() as demo:
|
154 |
-
gr.Markdown("# Styled Text with Animation")
|
155 |
output_html = gr.HTML()
|
156 |
-
demo.load(fn=
|
157 |
|
158 |
-
|
159 |
-
demo.launch()
|
|
|
2 |
import random
|
3 |
|
4 |
def generate_initial_design(word):
|
5 |
+
"""Generate initial design for the special word in black color."""
|
6 |
fonts = [
|
7 |
"'VT323', monospace",
|
8 |
"'Josefin Sans', sans-serif",
|
|
|
34 |
letters = list(word)
|
35 |
styled_letters = []
|
36 |
|
37 |
+
for letter in letters:
|
38 |
style = {
|
39 |
'font-family': random.choice(fonts),
|
40 |
'line-height': '1.6',
|
|
|
61 |
align-items: baseline;
|
62 |
vertical-align: middle;
|
63 |
margin: 0 2px;">
|
64 |
+
{"".join(styled_letters)}
|
65 |
</span>'''
|
66 |
|
67 |
def generate_output_html():
|
|
|
80 |
result.append(styled_paragraph)
|
81 |
|
82 |
output_html = '<br><br>'.join(result)
|
|
|
83 |
|
|
|
84 |
return f"""
|
85 |
<html>
|
86 |
<head>
|
|
|
96 |
}}
|
97 |
.styled-letter {{
|
98 |
transition: transform 0.3s ease;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
display: inline-block;
|
100 |
+
}}
|
101 |
+
.styled-letter.animate {{
|
102 |
+
transform: rotate(10deg) scale(1.3);
|
|
|
103 |
}}
|
104 |
</style>
|
105 |
<script>
|
106 |
+
function typeWriter(textContentId, words) {{
|
107 |
+
const textContent = document.getElementById(textContentId);
|
108 |
+
textContent.innerHTML = '';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
let i = 0;
|
110 |
function displayWord() {{
|
111 |
if (i < words.length) {{
|
112 |
+
textContent.innerHTML += words[i] + ' ';
|
113 |
i++;
|
114 |
+
setTimeout(displayWord, 60); // typing speed
|
115 |
}}
|
116 |
}}
|
117 |
displayWord();
|
118 |
}}
|
119 |
+
|
120 |
+
function triggerMovement() {{
|
121 |
+
document.querySelectorAll('.styled-letter').forEach(el => {{
|
122 |
+
el.classList.add('animate');
|
123 |
+
setTimeout(() => el.classList.remove('animate'), 300);
|
124 |
+
}});
|
125 |
+
}}
|
126 |
+
|
127 |
+
window.onload = function() {{
|
128 |
+
const words = document.getElementById('full-text').innerHTML.split(' ');
|
129 |
+
typeWriter('text-content', words);
|
130 |
+
}}
|
131 |
</script>
|
132 |
</head>
|
133 |
<body>
|
134 |
+
<div style='max-width: 800px; margin: auto;'>
|
135 |
+
<div id="full-text" style="display:none;">{output_html}</div>
|
136 |
+
<div id="text-content"></div>
|
137 |
+
<br>
|
138 |
+
<button onclick="triggerMovement()">Animate Letters</button>
|
139 |
+
</div>
|
140 |
</body>
|
141 |
</html>
|
142 |
"""
|
143 |
|
|
|
144 |
with gr.Blocks() as demo:
|
145 |
+
gr.Markdown("# Styled Text Display with Clickable Animation")
|
146 |
output_html = gr.HTML()
|
147 |
+
demo.load(fn=generate_output_html, outputs=output_html)
|
148 |
|
149 |
+
demo.launch()
|
|