File size: 8,992 Bytes
46404cc
 
f5e26af
46404cc
c5fdd6c
 
 
9eab2ed
c5fdd6c
3571ebc
2daf147
46404cc
a299eb5
 
 
 
 
 
 
 
 
9eab2ed
46404cc
c50040b
a299eb5
c021433
a299eb5
 
 
 
 
 
 
 
 
 
f5e26af
a299eb5
 
3571ebc
 
2daf147
 
3571ebc
 
 
 
 
 
 
 
 
 
 
 
 
2daf147
 
 
 
 
 
 
9eab2ed
2daf147
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c50040b
2daf147
c021433
2daf147
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9eab2ed
3571ebc
2daf147
3571ebc
 
 
a299eb5
9eab2ed
3571ebc
f5e26af
9eab2ed
c5fdd6c
46404cc
6f1f2ad
 
 
 
46404cc
a299eb5
2daf147
 
c5fdd6c
 
 
46404cc
 
c5fdd6c
2daf147
c5fdd6c
2daf147
c5fdd6c
2daf147
 
a299eb5
9eab2ed
 
 
 
 
2daf147
9eab2ed
 
ff5dcd6
9eab2ed
c50040b
9eab2ed
2daf147
9eab2ed
2daf147
9eab2ed
c50040b
9eab2ed
 
 
a299eb5
9eab2ed
 
c5fdd6c
 
9eab2ed
c5fdd6c
9eab2ed
c5fdd6c
 
9eab2ed
 
 
c5fdd6c
9eab2ed
c50040b
9eab2ed
 
 
3571ebc
2daf147
46404cc
2daf147
 
46404cc
f5e26af
a299eb5
c5fdd6c
2daf147
 
9eab2ed
c5fdd6c
2daf147
 
1
2
3
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import gradio as gr
import random
import time

# Global variables
initial_word_designs = []
special_words = []
current_text = ""

def generate_initial_design(word):
    """Generate initial design for the special word in black color."""
    fonts = [
        "'VT323', monospace",
        "'Josefin Sans', sans-serif",
        "'Rajdhani', sans-serif",
        "'Anton', sans-serif",
        "'Caveat', cursive",
        "'Patrick Hand', cursive",
        "'Nothing You Could Do', cursive",
        "'Reenie Beanie', cursive",
        "'Orbitron', sans-serif",
        "'Raleway', sans-serif"
    ]
    font_sizes = ["16px", "17px", "18px" , "19px", "20px"]
    font_tops = ["0px", "1px", "-1px"]
    letter_spacings = ["-3px", "-2px", "-1px", "1px", "-2px", "-3px"]
    text_shadows = [
        "0px 0px 1px",
        "0px 0px 2px",
        "1px 0px 0px",
        "0px 0px 0px",
        "0px 1px 0px",
        "0px 2px 0px",
        "0px 1px 1px",
        "1px 1px 0px",
        "1px 0px 1px"
    ]
    skew_angles = ["-25deg", "-20deg", "-15deg", "-10deg", "0deg", "10deg", "15deg", "20deg", "25deg"]

    letters = list(word)
    styled_letters = []
    
    for i, letter in enumerate(letters):
        style = {
            'font-family': random.choice(fonts),
            'line-height': '1.6',
            'font-size': random.choice(font_sizes),
            'letter-spacing': random.choice(letter_spacings),
            'text-shadow': random.choice(text_shadows),
            'transform': f'skew({random.choice(skew_angles)})',
            'margin-top': random.choice(["-0.02cm", "0.00cm", "0.02cm"]),
            'position': 'relative',
            'top': random.choice(font_tops),
            'color': '#000000',
            'display': 'inline-block',
            'margin': '0 1px',
            'vertical-align': 'middle'
        }
        
        style_str = '; '.join([f'{k}: {v}' for k, v in style.items()])
        styled_letter = f'<span class="styled-letter" style="{style_str}">{letter}</span>'
        styled_letters.append(styled_letter)

    return f'<span class="special-word">{" ".join(styled_letters)}</span>'

def generate_movement_design(word):
    """Generate a completely new random design for the movement animation."""
    fonts = [
        "'VT323', monospace",
        "'Josefin Sans', sans-serif",
        "'Rajdhani', sans-serif",
        "'Anton', sans-serif",
        "'Caveat', cursive",
        "'Patrick Hand', cursive",
        "'Nothing You Could Do', cursive",
        "'Reenie Beanie', cursive",
        "'Orbitron', sans-serif",
        "'Raleway', sans-serif"
    ]
    font_sizes = ["16px", "17px", "18px" , "19px", "20px"]
    font_tops = ["0px", "1px", "-1px"]
    letter_spacings = ["-3px", "-2px", "-1px", "1px", "-2px", "-3px"]
    text_shadows = [
        "0px 0px 1px",
        "0px 0px 2px",
        "1px 0px 0px",
        "0px 0px 0px",
        "0px 1px 0px",
        "0px 2px 0px",
        "0px 1px 1px",
        "1px 1px 0px",
        "1px 0px 1px"
    ]
    skew_angles = ["-25deg", "-20deg", "-15deg", "-10deg", "0deg", "10deg", "15deg", "20deg", "25deg"]

    # Generate random color for the movement design
    random_color = f'#{random.randint(0, 0xFFFFFF):06x}'

    letters = list(word)
    styled_letters = []
    
    for i, letter in enumerate(letters):
        style = {
            'font-family': random.choice(fonts),
            'line-height': '1.6',
            'font-size': random.choice(font_sizes),
            'letter-spacing': random.choice(letter_spacings),
            'text-shadow': random.choice(text_shadows),
            'transform': f'skew({random.choice(skew_angles)})',
            'margin-top': random.choice(["-0.02cm", "0.00cm", "0.02cm"]),
            'position': 'relative',
            'top': random.choice(font_tops),
            'color': random_color,
            'display': 'inline-block',
            'margin': '0 1px',
            'vertical-align': 'middle'
        }
        
        style_str = '; '.join([f'{k}: {v}' for k, v in style.items()])
        styled_letter = f'<span class="styled-letter" style="{style_str}">{letter}</span>'
        styled_letters.append(styled_letter)

    return f'<span class="special-word">{" ".join(styled_letters)}</span>'

def typing_effect():
    global initial_word_designs, special_words, current_text
    
    paragraphs = [
    '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.',
    '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.',
    '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.',
    '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.'
    ]

    # Process paragraphs to add styling
    styled_paragraphs = []
    initial_word_designs = []
    special_words = []
    
    for paragraph in paragraphs:
        words = paragraph.split()
        if words:
            special_word = random.choice(words)
            special_words.append(special_word)
            styled_word = generate_initial_design(special_word)
            initial_word_designs.append(styled_word)
            styled_paragraph = ' '.join(word if word != special_word else styled_word for word in words)
            styled_paragraphs.append(styled_paragraph)

    current_text = '<br><br>'.join(styled_paragraphs)
    
    # Simulate typing effect by yielding incremental text
    words = current_text.split()
    displayed_text = ""
    
    for i, word in enumerate(words):
        displayed_text += word + " "
        time.sleep(0.01)  # Small delay
        yield f"""
        <div style="font-family: 'Josefin Sans', sans-serif; font-size: 16px; line-height: 1.6; padding: 20px; max-width: 800px;">
            {displayed_text}
        </div>
        """
    
    return f"""
    <div style="font-family: 'Josefin Sans', sans-serif; font-size: 16px; line-height: 1.6; padding: 20px; max-width: 800px;">
        {current_text}
    </div>
    """

def trigger_movement():
    global initial_word_designs, special_words, current_text
    
    if not initial_word_designs or not special_words:
        return current_text
    
    updated_text = current_text
    for i, (initial_design, special_word) in enumerate(zip(initial_word_designs, special_words)):
        movement_design = generate_movement_design(special_word)
        updated_text = updated_text.replace(initial_design, movement_design, 1)
    
    current_text = updated_text
    
    return f"""
    <div style="font-family: 'Josefin Sans', sans-serif; font-size: 16px; line-height: 1.6; padding: 20px; max-width: 800px;">
        {updated_text}
    </div>
    """

# Create Gradio interface using Blocks
with gr.Blocks() as demo:
    gr.Markdown("# CircularText Styler\nText with special word styling and animations.")
    
    output_html = gr.HTML()
    with gr.Row():
        start_btn = gr.Button("▶ Start Typing")
        animate_btn = gr.Button("✨ Trigger Movement")
    
    start_btn.click(typing_effect, inputs=[], outputs=output_html)
    animate_btn.click(trigger_movement, inputs=[], outputs=output_html)

# Launch the app
demo.launch()