Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import random
|
| 3 |
+
import time
|
| 4 |
+
|
| 5 |
+
# Global variables
|
| 6 |
+
original_paragraphs = []
|
| 7 |
+
|
| 8 |
+
def generate_sneak_style(word):
|
| 9 |
+
"""Generate styled version of the word in black color."""
|
| 10 |
+
fonts = [
|
| 11 |
+
"'VT323', monospace",
|
| 12 |
+
"'Josefin Sans', sans-serif",
|
| 13 |
+
"'Rajdhani', sans-serif",
|
| 14 |
+
"'Anton', sans-serif",
|
| 15 |
+
"'Caveat', cursive",
|
| 16 |
+
"'Patrick Hand', cursive",
|
| 17 |
+
"'Nothing You Could Do', cursive",
|
| 18 |
+
"'Reenie Beanie', cursive",
|
| 19 |
+
"'Orbitron', sans-serif",
|
| 20 |
+
"'Raleway', sans-serif"
|
| 21 |
+
]
|
| 22 |
+
font_sizes = ["16px", "17px", "18px" , "19px", "20px"]
|
| 23 |
+
font_tops = ["0px", "1px", "-1px"]
|
| 24 |
+
letter_spacings = ["-3px", "-2px", "-1px", "1px", "-2px", "-3px"]
|
| 25 |
+
text_shadows = [
|
| 26 |
+
"0px 0px 1px",
|
| 27 |
+
"0px 0px 2px",
|
| 28 |
+
"1px 0px 0px",
|
| 29 |
+
"0px 0px 0px",
|
| 30 |
+
"0px 1px 0px",
|
| 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 |
+
letters = list(word)
|
| 39 |
+
styled_letters = []
|
| 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 |
+
return f'<span>{" ".join(styled_letters)}</span>'
|
| 63 |
+
|
| 64 |
+
def show_text_normal():
|
| 65 |
+
"""Show all paragraphs with no styling."""
|
| 66 |
+
global original_paragraphs
|
| 67 |
+
original_paragraphs = [
|
| 68 |
+
'How did we get here December 30th 2124 "Good morning, Benshiro. Wake up! We\'ve got A.I. training ahead," urged Benshiro\'s partner as they prepared for their day in sector A1 - A1000, one of the elite development sectors serving the World One government. It was the year 2124.',
|
| 69 |
+
'2033 The police were targeting the economically disadvantaged community, and if you were living in poverty in One Country, you were looked down upon. In 2033, a civil war broke out in Philadelphia, New York, Chicago, and a few other big cities. Citizens, fed up with losing jobs to A.I. and enduring systemic mistreatment, initiated the conflict. After the long fight, substantial changes and more restrictive rules were implemented in communities, along with increased travel restrictions for all citizens. Although schools and other institutions remained, life had fundamentally changed for everyone in America.',
|
| 70 |
+
'2034 In 2034, Anonymous developed an A.I. hack that no bank or institution could counter. This forced all American citizens to join One Country and secure their finances through One Country banking accounts. These accounts were managed by the One Country government and intended to provide security and fairness. Some even thought that the government was behind the attack in the first place.',
|
| 71 |
+
'2036 By 2036, the government implemented a new policy for One Country accounts. If individuals committed a crime and did not turn themselves in, their accounts would be frozen. This rule was highly controversial, as it curtailed personal freedoms. In a bold initiative, the One Country President announced plans to establish a 99% robotic police force by 2045. The program will begin immediately, aiming to have 30% of the force composed of active robots within the first phase. Human officers would collaborate with these machines in decision-making processes. To support this vision, a vast 10,000-acre automation facility—equivalent to the size of Manhattan—was constructed. This facility aimed to produce advanced robots and flying vehicles, initially reserved for government officials and the wealthy, signaling a significant shift towards automation in society.'
|
| 72 |
+
]
|
| 73 |
+
return render_html('<br><br>'.join(original_paragraphs))
|
| 74 |
+
|
| 75 |
+
def sneak_style_then_reset():
|
| 76 |
+
"""Apply sneak style to one random word per paragraph, then revert."""
|
| 77 |
+
paragraphs = original_paragraphs.copy()
|
| 78 |
+
styled_paragraphs = []
|
| 79 |
+
|
| 80 |
+
for paragraph in paragraphs:
|
| 81 |
+
words = paragraph.split()
|
| 82 |
+
if words:
|
| 83 |
+
chosen = random.choice(words)
|
| 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 |
+
# Show sneaky style
|
| 89 |
+
yield render_html('<br><br>'.join(styled_paragraphs))
|
| 90 |
+
|
| 91 |
+
# Wait and revert
|
| 92 |
+
time.sleep(1.5)
|
| 93 |
+
yield render_html('<br><br>'.join(original_paragraphs))
|
| 94 |
+
|
| 95 |
+
def render_html(text):
|
| 96 |
+
"""Wrap text in simple HTML."""
|
| 97 |
+
return f"""
|
| 98 |
+
<div style="font-family: 'Josefin Sans', sans-serif; font-size: 16px;
|
| 99 |
+
line-height: 1.6; padding: 20px; max-width: 800px;">
|
| 100 |
+
{text}
|
| 101 |
+
</div>
|
| 102 |
+
"""
|
| 103 |
+
|
| 104 |
+
# Interface
|
| 105 |
+
with gr.Blocks() as demo:
|
| 106 |
+
gr.Markdown("# Sneaky Text Styler")
|
| 107 |
+
output_html = gr.HTML()
|
| 108 |
+
with gr.Row():
|
| 109 |
+
show_btn = gr.Button("📄 Show Normal")
|
| 110 |
+
sneak_btn = gr.Button("✨ Sneak Style")
|
| 111 |
+
show_btn.click(show_text_normal, outputs=output_html)
|
| 112 |
+
sneak_btn.click(sneak_style_then_reset, outputs=output_html)
|
| 113 |
+
|
| 114 |
+
demo.launch()
|