File size: 11,592 Bytes
48706c6
 
 
 
4e61a3c
 
 
48706c6
 
 
07e18fc
 
 
 
a14b594
 
 
48706c6
 
47d69ec
34d154f
47d69ec
 
 
 
 
 
34d154f
47d69ec
 
 
 
 
 
 
 
 
 
48706c6
34d154f
07e18fc
47d69ec
 
 
 
 
 
 
 
 
 
 
 
34d154f
07e18fc
a14b594
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
07e18fc
a14b594
 
07e18fc
a14b594
 
 
07e18fc
a14b594
 
34d154f
a14b594
 
 
07e18fc
a14b594
 
 
 
 
07e18fc
 
 
 
a14b594
 
 
 
 
 
 
07e18fc
a14b594
 
07e18fc
34d154f
 
07e18fc
34d154f
 
 
a14b594
 
 
34d154f
 
07e18fc
a14b594
 
07e18fc
a14b594
47d69ec
 
 
 
 
 
34d154f
47d69ec
 
34d154f
a14b594
47d69ec
34d154f
a14b594
47d69ec
34d154f
a14b594
47d69ec
07e18fc
47d69ec
 
07e18fc
a14b594
 
47d69ec
07e18fc
a14b594
34d154f
 
 
 
a14b594
34d154f
48706c6
a14b594
 
07e18fc
 
4e61a3c
 
 
07e18fc
4e61a3c
 
07e18fc
48706c6
 
07e18fc
a14b594
48706c6
4e61a3c
 
023bed0
07e18fc
a14b594
 
 
4e61a3c
 
07e18fc
4e61a3c
 
07e18fc
4e61a3c
 
48706c6
 
47d69ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34d154f
47d69ec
a14b594
 
 
 
 
 
 
 
07e18fc
 
 
a14b594
48706c6
a14b594
34d154f
 
 
48706c6
 
 
07e18fc
4e61a3c
48706c6
a14b594
 
07e18fc
 
a14b594
07e18fc
a14b594
07e18fc
a14b594
 
07e18fc
a14b594
 
07e18fc
 
 
a14b594
07e18fc
 
 
 
a14b594
07e18fc
 
a14b594
 
07e18fc
 
 
 
a14b594
 
 
 
 
07e18fc
a14b594
 
 
07e18fc
a14b594
 
07e18fc
a14b594
 
 
07e18fc
 
a14b594
 
 
 
 
 
07e18fc
 
 
 
 
 
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
import gradio as gr
import random
from transformers import pipeline

# Load the model once when the app starts
generator = pipeline('text-generation', model='distilgpt2')  # Lightweight model

# Predefined words to check
SPECIAL_WORDS = ['weather', 'sun', 'middle', 'summer', 'heat']

# Global variable to store the initial design
initial_word_design = ""
special_word = ""

# Function to generate the initial design (black color)
def generate_initial_design(word):
    """Generate initial design for the special word in black color."""
    # Controlled randomization parameters
    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",
        "'Open Sans Condensed', sans-serif",
        "'Poiret One', cursive",
        "'Indie Flower', cursive",
        "'Pacifico', cursive",
        "'Teko', sans-serif",
        "'Abril Fatface', cursive",
        "'Gloria Hallelujah', cursive",
        "'Righteous', cursive",
        "'Annie Use Your Telescope', cursive"
    ]
    font_sizes = ["17px", "19px", "21px", "23px", "25px", "27px"]
    font_tops = ["11px", "13px", "15px"]
    letter_spacings = ["-6px", "-4px", "-3px", "-2px", "-1px", "0px", "1px", "2px"]
    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"]

    # Create HTML for each letter with random styling (black color)
    letters = list(word)
    styled_letters = []
    for i, letter in enumerate(letters):
        style = {
            'font-family': random.choice(fonts),
            'line-height': '110%',
            '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.06cm", "-0.03cm", "0.00cm", "0.03cm", "0.06cm"]),
            'position': 'relative',
            'top': random.choice(font_tops),
            'color': '#000000',  # Black color
            'display': 'inline-block',
            'margin': '0 1px'
        }

        # Convert style to inline CSS
        style_str = '; '.join([f'{k}: {v}' for k, v in style.items()])

        # Wrap the letter in a span
        styled_letter = f'<span class="styled-letter" style="{style_str}">{letter}</span>'
        styled_letters.append(styled_letter)

    # Combine letters into a container with inline display
    return f'<span>{" ".join(styled_letters)}</span>'

# Function to generate the movement design (random color)
def generate_movement_design(word):
    """Generate movement design for the special word in random color."""
    # Controlled randomization parameters
    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"
    ]
    font_sizes = ["20px", "22px", "24px", "26px", "28px", "30px"]
    font_tops = ["10px", "12px", "14px", "16px"]
    letter_spacings = ["-3px", "-2px", "-1px", "0px", "1px", "2px", "3px"]
    text_shadows = [
        "0px 0px 5px #ff0000",  # Red glow
        "0px 0px 5px #00ff00",  # Green glow
        "0px 0px 5px #0000ff"   # Blue glow
    ]
    skew_angles = ["-15deg", "-10deg", "0deg", "10deg", "15deg"]

    # Generate a unique animation name for CSS
    animation_name = f"animate_{random.randint(0, 10000)}"

    # Create CSS keyframes for the animation
    keyframes = f"""
    @keyframes {animation_name} {{
        0%   {{ transform: translateY(0px); }}
        50%  {{ transform: translateY(-10px); }}
        100% {{ transform: translateY(0px); }}
    }}
    """

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

    # Create HTML for each letter with random styling and animation (random color)
    letters = list(word)
    styled_letters = []
    for i, letter in enumerate(letters):
        style = {
            'font-family': random.choice(fonts),
            'line-height': '110%',
            '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.03cm", "0.00cm", "0.03cm"]),
            'position': 'relative',
            'top': random.choice(font_tops),
            'color': random_color,  # Random color
            'display': 'inline-block',
            'margin': '0 1px',
            'animation': f'{animation_name} 1s ease-in-out forwards'
        }

        # Convert style to inline CSS
        style_str = '; '.join([f'{k}: {v}' for k, v in style.items()])

        # Wrap the letter in a span
        styled_letter = f'<span class="styled-letter" style="{style_str}">{letter}</span>'
        styled_letters.append(styled_letter)

    # Combine letters into a container with inline display and include keyframes
    return f'''
    <style>
    {keyframes}
    </style>
    <span>{" ".join(styled_letters)}</span>
    '''

def process_text(input_text):
    """Process text and generate the initial output with special word styled in black."""
    global initial_word_design, special_word

    # Generate text with limited length
    generated = generator(input_text, max_length=50, num_return_sequences=1)
    generated_text = generated[0]['generated_text']

    # Limit output length to prevent overflow
    generated_text = generated_text[:300]  # Limit to first 300 characters

    # Split text into words
    words = generated_text.split()

    # Check for special words and apply initial styling
    for i, word in enumerate(words):
        # Clean the word for matching
        clean_word = ''.join(filter(str.isalnum, word)).lower()
        if clean_word in SPECIAL_WORDS:
            special_word = word  # Store the special word
            # Store the initial design
            initial_word_design = generate_initial_design(word)
            words[i] = initial_word_design
        else:
            words[i] = word

    # Combine words back into HTML-formatted text
    output_html = ' '.join(words)

    # Build the complete HTML
    final_output = f"""
    <html>
    <head>
        <!-- Include all necessary fonts -->
        <link href="https://fonts.googleapis.com/css2?family=VT323&display=swap" rel="stylesheet">
        <link href="https://fonts.googleapis.com/css2?family=Josefin+Sans:wght@100&display=swap" rel="stylesheet">
        <link href="https://fonts.googleapis.com/css2?family=Rajdhani:wght@300&display=swap" rel="stylesheet">
        <link href="https://fonts.googleapis.com/css2?family=Anton&display=swap" rel="stylesheet">
        <link href="https://fonts.googleapis.com/css2?family=Caveat&display=swap" rel="stylesheet">
        <link href="https://fonts.googleapis.com/css2?family=Patrick+Hand&display=swap" rel="stylesheet">
        <link href="https://fonts.googleapis.com/css2?family=Nothing+You+Could+Do&display=swap" rel="stylesheet">
        <link href="https://fonts.googleapis.com/css2?family=Reenie+Beanie&display=swap" rel="stylesheet">
        <link href="https://fonts.googleapis.com/css2?family=Orbitron&display=swap" rel="stylesheet">
        <link href="https://fonts.googleapis.com/css?family=Raleway:500" rel="stylesheet" type="text/css">
        <link href="https://fonts.googleapis.com/css?family=Open+Sans+Condensed:700|Oswald:300" rel="stylesheet" type="text/css">
        <link href="https://fonts.googleapis.com/css?family=Open+Sans+Condensed:700|Oswald:200" rel="stylesheet" type="text/css">
        <link href="https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300" rel="stylesheet" type="text/css">
        <link href="https://fonts.googleapis.com/css?family=Roboto+Condensed" rel="stylesheet" type="text/css">
        <link href="https://fonts.googleapis.com/css?family=Poiret+One|Dosis:300|Fjalla+One" rel="stylesheet" type="text/css">
        <link href="https://fonts.googleapis.com/css?family=Indie+Flower|Lobster" rel="stylesheet" type="text/css">
        <link href="https://fonts.googleapis.com/css?family=Pacifico|Shadows+Into+Light|Dancing+Script|Amatic+SC" rel="stylesheet" type="text/css">
        <link href="https://fonts.googleapis.com/css?family=Teko" rel="stylesheet" type="text/css">
        <link href="https://fonts.googleapis.com/css?family=Abril+Fatface|Josefin+Sans|Gloria+Hallelujah|Roboto+Slab|Righteous|Sacramento|Yellowtail" rel="stylesheet">
        <link href="https://fonts.googleapis.com/css?family=Annie+Use+Your+Telescope|Just+Me+Again+Down+Here|Nixie+One|Six+Caps|Unkempt" rel="stylesheet">
        <style>
        body {{
            background-color: #fff;
            color: #000;
            font-size: 18px;
            line-height: 1.6;
            font-family: "Josefin Sans", sans-serif;
        }}
        .styled-letter {{
            transition: all 1s ease;
        }}
        </style>
    </head>
    <body>
        <div style='max-width: 800px; margin: auto; padding: 20px;'>
            {output_html}
        </div>
    </body>
    </html>
    """

    return final_output

def trigger_movement(input_html):
    """Function to trigger the movement animation by updating the special word design."""
    global initial_word_design, special_word

    # Edge case: if initial_word_design is empty, return the input_html
    if not initial_word_design or not special_word:
        return input_html  # No special word was found previously

    # Generate the movement design
    movement_design = generate_movement_design(special_word)

    # Replace the initial design with the movement design in the input_html
    updated_html = input_html.replace(initial_word_design, movement_design, 1)

    # Append CSS to reset to initial design after animation
    css_reset = """
    <style>
    @keyframes reset_animation {
        from { color: inherit; }
        to { color: #000000; }
    }
    .styled-letter {
        animation: reset_animation 0s forwards;
        animation-delay: 1s;
    }
    </style>
    </head>
    """
    updated_html = updated_html.replace('</head>', css_reset)

    return updated_html

# Create Gradio interface using Blocks
with gr.Blocks() as demo:
    gr.Markdown("# Circular Text Styler\nEnter a prompt to generate text with special word styling.")

    with gr.Row():
        input_text = gr.Textbox(label="Input Prompt")
        submit_button = gr.Button("Generate")

    output_html = gr.HTML()
    animate_button = gr.Button("Trigger Movement")

    # Connect functions
    submit_button.click(process_text, inputs=input_text, outputs=output_html)
    animate_button.click(trigger_movement, inputs=output_html, outputs=output_html)

    # Add custom CSS
    gr.HTML("""
    <style>
    /* Center the buttons */
    .gradio-container .gr-button {
        margin-top: 10px;
        margin-bottom: 10px;
    }
    </style>
    """)

# Launch the app
demo.launch()