Update app.py
Browse files
app.py
CHANGED
|
@@ -2,113 +2,107 @@ import gradio as gr
|
|
| 2 |
import random
|
| 3 |
import time
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
|
| 8 |
-
|
| 9 |
-
"
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
"0px 2px 0px",
|
| 32 |
-
"0px 1px 1px",
|
| 33 |
-
"1px 1px 0px",
|
| 34 |
-
"1px 0px 1px"
|
| 35 |
-
]
|
| 36 |
-
skew_angles = ["-25deg", "-20deg", "-15deg", "-10deg", "0deg", "10deg", "15deg", "20deg", "25deg"]
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
for letter in letters:
|
| 42 |
-
style = {
|
| 43 |
-
'font-family': random.choice(fonts),
|
| 44 |
-
'line-height': '1.6',
|
| 45 |
-
'font-size': random.choice(font_sizes),
|
| 46 |
-
'letter-spacing': random.choice(letter_spacings),
|
| 47 |
-
'text-shadow': random.choice(text_shadows),
|
| 48 |
-
'transform': f'skew({random.choice(skew_angles)})',
|
| 49 |
-
'margin-top': random.choice(["-0.02cm", "0.00cm", "0.02cm"]),
|
| 50 |
-
'position': 'relative',
|
| 51 |
-
'top': random.choice(font_tops),
|
| 52 |
-
'color': '#000000', # always black
|
| 53 |
-
'display': 'inline-block',
|
| 54 |
-
'margin': '0 1px',
|
| 55 |
-
'vertical-align': 'middle'
|
| 56 |
-
}
|
| 57 |
-
|
| 58 |
-
style_str = '; '.join([f'{k}: {v}' for k, v in style.items()])
|
| 59 |
-
styled_letter = f'<span style="{style_str}">{letter}</span>'
|
| 60 |
-
styled_letters.append(styled_letter)
|
| 61 |
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
-
def
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
'
|
| 69 |
-
'
|
| 70 |
-
'
|
| 71 |
-
'
|
| 72 |
-
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
-
def
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
|
| 80 |
-
for
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
styled_word = generate_sneak_style(chosen)
|
| 85 |
-
paragraph = ' '.join(styled_word if word == chosen else word for word in words)
|
| 86 |
-
styled_paragraphs.append(paragraph)
|
| 87 |
|
| 88 |
-
|
| 89 |
-
yield render_html('<br><br>'.join(styled_paragraphs))
|
| 90 |
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
</div>
|
| 102 |
-
"""
|
| 103 |
|
| 104 |
-
# Interface
|
| 105 |
with gr.Blocks() as demo:
|
| 106 |
-
gr.
|
| 107 |
-
output_html = gr.HTML()
|
| 108 |
with gr.Row():
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
|
| 114 |
demo.launch()
|
|
|
|
| 2 |
import random
|
| 3 |
import time
|
| 4 |
|
| 5 |
+
# Store original styles so we can return to them
|
| 6 |
+
original_styles = {}
|
| 7 |
|
| 8 |
+
fonts = [
|
| 9 |
+
"'VT323', monospace",
|
| 10 |
+
"'Josefin Sans', sans-serif",
|
| 11 |
+
"'Rajdhani', sans-serif",
|
| 12 |
+
"'Anton', sans-serif",
|
| 13 |
+
"'Caveat', cursive",
|
| 14 |
+
"'Patrick Hand', cursive",
|
| 15 |
+
"'Nothing You Could Do', cursive",
|
| 16 |
+
"'Reenie Beanie', cursive",
|
| 17 |
+
"'Orbitron', sans-serif",
|
| 18 |
+
"'Raleway', sans-serif"
|
| 19 |
+
]
|
| 20 |
+
font_sizes = ["16px", "17px", "18px", "19px", "20px"]
|
| 21 |
+
font_tops = ["0px", "1px", "-1px"]
|
| 22 |
+
letter_spacings = ["-3px", "-2px", "-1px", "0px", "1px"]
|
| 23 |
+
text_shadows = [
|
| 24 |
+
"0px 0px 1px #000000",
|
| 25 |
+
"0px 0px 2px #000000",
|
| 26 |
+
"1px 0px 0px #000000",
|
| 27 |
+
"0px 0px 0px #000000",
|
| 28 |
+
"0px 1px 0px #000000"
|
| 29 |
+
]
|
| 30 |
+
skew_angles = ["-25deg", "-15deg", "-10deg", "0deg", "10deg", "15deg", "25deg"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
+
def render_letter(letter, style):
|
| 33 |
+
style_str = '; '.join(f"{k}: {v}" for k, v in style.items())
|
| 34 |
+
return f'<span style="{style_str}">{letter}</span>'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
+
def make_base_style():
|
| 37 |
+
return {
|
| 38 |
+
'font-family': "'Josefin Sans', sans-serif",
|
| 39 |
+
'font-size': '16px',
|
| 40 |
+
'letter-spacing': '0px',
|
| 41 |
+
'text-shadow': '0px 0px 0px #000000',
|
| 42 |
+
'transform': 'skew(0deg)',
|
| 43 |
+
'margin-top': '0cm',
|
| 44 |
+
'position': 'relative',
|
| 45 |
+
'top': '0px',
|
| 46 |
+
'color': '#000000',
|
| 47 |
+
'display': 'inline-block',
|
| 48 |
+
'margin': '0 1px',
|
| 49 |
+
'vertical-align': 'middle',
|
| 50 |
+
'transition': 'all 0.5s ease' # Smooth transition
|
| 51 |
+
}
|
| 52 |
|
| 53 |
+
def make_sneaky_style():
|
| 54 |
+
return {
|
| 55 |
+
'font-family': random.choice(fonts),
|
| 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 |
+
'margin-top': random.choice(["-0.05cm", "0.00cm", "0.05cm"]),
|
| 61 |
+
'position': 'relative',
|
| 62 |
+
'top': random.choice(font_tops),
|
| 63 |
+
'color': '#000000',
|
| 64 |
+
'display': 'inline-block',
|
| 65 |
+
'margin': '0 1px',
|
| 66 |
+
'vertical-align': 'middle',
|
| 67 |
+
'transition': 'all 0.5s ease'
|
| 68 |
+
}
|
| 69 |
|
| 70 |
+
def show_normal():
|
| 71 |
+
text = "This is a sneaky text test."
|
| 72 |
+
styled_text = []
|
| 73 |
+
original_styles.clear()
|
| 74 |
|
| 75 |
+
for i, letter in enumerate(text):
|
| 76 |
+
style = make_base_style()
|
| 77 |
+
original_styles[i] = style
|
| 78 |
+
styled_text.append(render_letter(letter, style))
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
+
return f"<div>{''.join(styled_text)}</div>"
|
|
|
|
| 81 |
|
| 82 |
+
def sneak_then_back():
|
| 83 |
+
text = "This is a sneaky text test."
|
| 84 |
+
|
| 85 |
+
# Step 1: Apply sneaky style
|
| 86 |
+
sneaky_html = []
|
| 87 |
+
for i, letter in enumerate(text):
|
| 88 |
+
style = make_sneaky_style()
|
| 89 |
+
sneaky_html.append(render_letter(letter, style))
|
| 90 |
+
yield f"<div>{''.join(sneaky_html)}</div>"
|
| 91 |
|
| 92 |
+
# Step 2: Wait, then go back
|
| 93 |
+
time.sleep(1.5)
|
| 94 |
+
normal_html = []
|
| 95 |
+
for i, letter in enumerate(text):
|
| 96 |
+
style = make_base_style()
|
| 97 |
+
normal_html.append(render_letter(letter, style))
|
| 98 |
+
yield f"<div>{''.join(normal_html)}</div>"
|
|
|
|
| 99 |
|
|
|
|
| 100 |
with gr.Blocks() as demo:
|
| 101 |
+
output = gr.HTML()
|
|
|
|
| 102 |
with gr.Row():
|
| 103 |
+
btn_show = gr.Button("Show Normal")
|
| 104 |
+
btn_sneak = gr.Button("Sneak Then Back")
|
| 105 |
+
btn_show.click(show_normal, outputs=output)
|
| 106 |
+
btn_sneak.click(sneak_then_back, outputs=output)
|
| 107 |
|
| 108 |
demo.launch()
|