File size: 7,057 Bytes
48706c6
 
 
 
4e61a3c
 
 
48706c6
 
 
 
47d69ec
48706c6
 
 
 
 
47d69ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48706c6
47d69ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48706c6
 
4e61a3c
 
 
 
 
 
 
 
 
 
 
023bed0
48706c6
 
023bed0
4e61a3c
48706c6
4e61a3c
 
023bed0
48706c6
4e61a3c
 
 
 
 
023bed0
4e61a3c
 
48706c6
 
47d69ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48706c6
47d69ec
 
48706c6
 
 
023bed0
4e61a3c
48706c6
 
 
 
 
023bed0
48706c6
4e61a3c
48706c6
 
 
4e61a3c
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
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']

def generate_circular_text_design(word):
    """Generate a styled design for a word by styling each letter individually."""
    # Controlled randomization parameters
    fonts = [
        "'Dosis', sans-serif",
        "'Josefin Sans', sans-serif",
        "'Orbitron', sans-serif",
        "'Roboto Condensed', sans-serif",
        "'VT323', monospace",
        "'Rajdhani', sans-serif",
        "'Anton', sans-serif",
        "'Caveat', cursive",
        "'Patrick Hand', cursive",
        "'Nothing You Could Do', cursive",
        "'Reenie Beanie', cursive",
        "'Patrick Hand', cursive",
        "'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 = [17, 19, 21, 23, 25, 27]
    font_tops = [11, 11, 13, 13, 15, 15]
    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 = [-10, -5, 0, 5, 10, 15, 20, 25, 30]

    # Create HTML for each letter with dynamic styling
    letters = list(word)
    styled_letters = []
    for i, letter in enumerate(letters):
        style = {
            'font-family': random.choice(fonts),
            'line-height': '110%',
            'font-size': f'{random.choice(font_sizes)}px',
            'letter-spacing': random.choice(letter_spacings),
            'text-shadow': random.choice(text_shadows),
            'transform': f'skew({random.choice(skew_angles)}deg)',
            'margin-top': f'{random.uniform(-0.1, 0.1):.2f}cm',
            'position': 'relative',
            'top': f'{random.choice(font_tops)}px',
            'color': f'#{random.randint(0, 0xFFFFFF):06x}',
            'display': 'inline-block',
            'margin': '0 1px'
        }

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

        # Assign a unique class name for possible future reference (if needed)
        styled_letter = f'<div class="styled-letter" style="{style_str}">{letter}</div>'
        styled_letters.append(styled_letter)

    # Wrap styled letters in a flex container
    return f'<div style="display: flex; align-items: baseline;">{" ".join(styled_letters)}</div>'

def process_text(input_text):
    """Process text and apply special styling to matching words."""
    # Limit input length to prevent long processing times
    max_input_length = 20  # Adjust as needed
    input_text = ' '.join(input_text.split()[:max_input_length])

    # 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 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:
            words[i] = generate_circular_text_design(word)
        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">
    </head>
    <body style='background-color: #000; color: #fff; font-size: 18px; line-height: 1.6; font-family: "Josefin Sans", sans-serif;'>
        <div style='max-width: 800px; margin: auto; padding: 20px;'>{output_html}</div>
    </body>
    </html>
    """

    return final_output

# Create Gradio interface
iface = gr.Interface(
    fn=process_text,
    inputs="text",
    outputs=gr.HTML(label="Generated Text"),
    title="Circular Text Styler",
    description="Enter a prompt to generate text with special word styling."
)

# Launch the interface
iface.launch()