Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,21 +9,18 @@ generator = pipeline('text-generation', model='distilgpt2') # Lightweight model
|
|
9 |
SPECIAL_WORDS = ['weather', 'sun', 'middle', 'summer', 'heat']
|
10 |
|
11 |
def generate_circular_text_design(word):
|
12 |
-
"""Generate a styled design for a word by styling each letter individually."""
|
13 |
# Controlled randomization parameters
|
14 |
fonts = [
|
15 |
-
"'Dosis', sans-serif",
|
16 |
-
"'Josefin Sans', sans-serif",
|
17 |
-
"'Orbitron', sans-serif",
|
18 |
-
"'Roboto Condensed', sans-serif",
|
19 |
"'VT323', monospace",
|
|
|
20 |
"'Rajdhani', sans-serif",
|
21 |
"'Anton', sans-serif",
|
22 |
"'Caveat', cursive",
|
23 |
"'Patrick Hand', cursive",
|
24 |
"'Nothing You Could Do', cursive",
|
25 |
"'Reenie Beanie', cursive",
|
26 |
-
"'
|
27 |
"'Raleway', sans-serif",
|
28 |
"'Open Sans Condensed', sans-serif",
|
29 |
"'Poiret One', cursive",
|
@@ -35,8 +32,8 @@ def generate_circular_text_design(word):
|
|
35 |
"'Righteous', cursive",
|
36 |
"'Annie Use Your Telescope', cursive"
|
37 |
]
|
38 |
-
font_sizes = [
|
39 |
-
font_tops = [
|
40 |
letter_spacings = ["-6px", "-4px", "-3px", "-2px", "-1px", "0px", "1px", "2px"]
|
41 |
text_shadows = [
|
42 |
"0px 0px 1px",
|
@@ -49,36 +46,56 @@ def generate_circular_text_design(word):
|
|
49 |
"1px 1px 0px",
|
50 |
"1px 0px 1px"
|
51 |
]
|
52 |
-
skew_angles = [-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
|
54 |
-
# Create HTML for each letter with dynamic styling
|
55 |
letters = list(word)
|
56 |
styled_letters = []
|
57 |
for i, letter in enumerate(letters):
|
58 |
style = {
|
59 |
'font-family': random.choice(fonts),
|
60 |
'line-height': '110%',
|
61 |
-
'font-size':
|
62 |
'letter-spacing': random.choice(letter_spacings),
|
63 |
'text-shadow': random.choice(text_shadows),
|
64 |
-
'transform': f'skew({random.choice(skew_angles)}
|
65 |
-
'margin-top': f'{random.
|
66 |
'position': 'relative',
|
67 |
-
'top':
|
68 |
'color': f'#{random.randint(0, 0xFFFFFF):06x}',
|
69 |
'display': 'inline-block',
|
70 |
-
'margin': '0 1px'
|
|
|
71 |
}
|
72 |
|
73 |
# Convert style to inline CSS
|
74 |
style_str = '; '.join([f'{k}: {v}' for k, v in style.items()])
|
75 |
|
76 |
-
# Assign a unique
|
77 |
styled_letter = f'<div class="styled-letter" style="{style_str}">{letter}</div>'
|
78 |
styled_letters.append(styled_letter)
|
79 |
|
80 |
-
#
|
81 |
-
return f'
|
|
|
|
|
|
|
|
|
|
|
82 |
|
83 |
def process_text(input_text):
|
84 |
"""Process text and apply special styling to matching words."""
|
@@ -131,11 +148,13 @@ def process_text(input_text):
|
|
131 |
<link href="https://fonts.googleapis.com/css?family=Indie+Flower|Lobster" rel="stylesheet" type="text/css">
|
132 |
<link href="https://fonts.googleapis.com/css?family=Pacifico|Shadows+Into+Light|Dancing+Script|Amatic+SC" rel="stylesheet" type="text/css">
|
133 |
<link href="https://fonts.googleapis.com/css?family=Teko" rel="stylesheet" type="text/css">
|
134 |
-
<link href="https://fonts.googleapis.com/css?family=Abril+Fatface|Josefin+Sans|Gloria+Hallelujah|
|
135 |
<link href="https://fonts.googleapis.com/css?family=Annie+Use+Your+Telescope|Just+Me+Again+Down+Here|Nixie+One|Six+Caps|Unkempt" rel="stylesheet">
|
136 |
</head>
|
137 |
<body style='background-color: #000; color: #fff; font-size: 18px; line-height: 1.6; font-family: "Josefin Sans", sans-serif;'>
|
138 |
-
<div style='max-width: 800px; margin: auto; padding: 20px;'>
|
|
|
|
|
139 |
</body>
|
140 |
</html>
|
141 |
"""
|
@@ -150,6 +169,4 @@ iface = gr.Interface(
|
|
150 |
title="Circular Text Styler",
|
151 |
description="Enter a prompt to generate text with special word styling."
|
152 |
)
|
153 |
-
|
154 |
-
# Launch the interface
|
155 |
iface.launch()
|
|
|
9 |
SPECIAL_WORDS = ['weather', 'sun', 'middle', 'summer', 'heat']
|
10 |
|
11 |
def generate_circular_text_design(word):
|
12 |
+
"""Generate a styled design for a word by styling each letter individually, including animations."""
|
13 |
# Controlled randomization parameters
|
14 |
fonts = [
|
|
|
|
|
|
|
|
|
15 |
"'VT323', monospace",
|
16 |
+
"'Josefin Sans', sans-serif",
|
17 |
"'Rajdhani', sans-serif",
|
18 |
"'Anton', sans-serif",
|
19 |
"'Caveat', cursive",
|
20 |
"'Patrick Hand', cursive",
|
21 |
"'Nothing You Could Do', cursive",
|
22 |
"'Reenie Beanie', cursive",
|
23 |
+
"'Orbitron', sans-serif",
|
24 |
"'Raleway', sans-serif",
|
25 |
"'Open Sans Condensed', sans-serif",
|
26 |
"'Poiret One', cursive",
|
|
|
32 |
"'Righteous', cursive",
|
33 |
"'Annie Use Your Telescope', cursive"
|
34 |
]
|
35 |
+
font_sizes = ["17px", "19px", "21px", "23px", "25px", "27px"]
|
36 |
+
font_tops = ["11px", "11px", "13px", "13px", "15px", "15px"]
|
37 |
letter_spacings = ["-6px", "-4px", "-3px", "-2px", "-1px", "0px", "1px", "2px"]
|
38 |
text_shadows = [
|
39 |
"0px 0px 1px",
|
|
|
46 |
"1px 1px 0px",
|
47 |
"1px 0px 1px"
|
48 |
]
|
49 |
+
skew_angles = ["-25deg", "-20deg", "-15deg", "-10deg", "0deg", "10deg", "15deg", "20deg", "25deg"]
|
50 |
+
|
51 |
+
# Generate a unique animation name for CSS
|
52 |
+
animation_name = f"animate_{random.randint(0, 10000)}"
|
53 |
+
|
54 |
+
# Create CSS keyframes for the animation
|
55 |
+
keyframes = f"""
|
56 |
+
@keyframes {animation_name} {{
|
57 |
+
0% {{ transform: scale(1) rotate(0deg); }}
|
58 |
+
25% {{ transform: scale(1.2) rotate(10deg); }}
|
59 |
+
50% {{ transform: scale(1) rotate(0deg); }}
|
60 |
+
75% {{ transform: scale(1.2) rotate(-10deg); }}
|
61 |
+
100% {{ transform: scale(1) rotate(0deg); }}
|
62 |
+
}}
|
63 |
+
"""
|
64 |
|
65 |
+
# Create HTML for each letter with dynamic styling and animation
|
66 |
letters = list(word)
|
67 |
styled_letters = []
|
68 |
for i, letter in enumerate(letters):
|
69 |
style = {
|
70 |
'font-family': random.choice(fonts),
|
71 |
'line-height': '110%',
|
72 |
+
'font-size': random.choice(font_sizes),
|
73 |
'letter-spacing': random.choice(letter_spacings),
|
74 |
'text-shadow': random.choice(text_shadows),
|
75 |
+
'transform': f'skew({random.choice(skew_angles)})',
|
76 |
+
'margin-top': f'{random.choice(["-0.06cm", "-0.03cm", "0.00cm", "0.03cm", "0.06cm"])}',
|
77 |
'position': 'relative',
|
78 |
+
'top': random.choice(font_tops),
|
79 |
'color': f'#{random.randint(0, 0xFFFFFF):06x}',
|
80 |
'display': 'inline-block',
|
81 |
+
'margin': '0 1px',
|
82 |
+
'animation': f'{animation_name} 2s infinite'
|
83 |
}
|
84 |
|
85 |
# Convert style to inline CSS
|
86 |
style_str = '; '.join([f'{k}: {v}' for k, v in style.items()])
|
87 |
|
88 |
+
# Assign a unique ID for possible future reference
|
89 |
styled_letter = f'<div class="styled-letter" style="{style_str}">{letter}</div>'
|
90 |
styled_letters.append(styled_letter)
|
91 |
|
92 |
+
# Combine letters into a container with flex display
|
93 |
+
return f'''
|
94 |
+
<style>
|
95 |
+
{keyframes}
|
96 |
+
</style>
|
97 |
+
<div style="display: flex; align-items: baseline;">{" ".join(styled_letters)}</div>
|
98 |
+
'''
|
99 |
|
100 |
def process_text(input_text):
|
101 |
"""Process text and apply special styling to matching words."""
|
|
|
148 |
<link href="https://fonts.googleapis.com/css?family=Indie+Flower|Lobster" rel="stylesheet" type="text/css">
|
149 |
<link href="https://fonts.googleapis.com/css?family=Pacifico|Shadows+Into+Light|Dancing+Script|Amatic+SC" rel="stylesheet" type="text/css">
|
150 |
<link href="https://fonts.googleapis.com/css?family=Teko" rel="stylesheet" type="text/css">
|
151 |
+
<link href="https://fonts.googleapis.com/css?family=Abril+Fatface|Josefin+Sans|Gloria+Hallelujah|Roboto+Slab|Righteous|Sacramento|Yellowtail" rel="stylesheet">
|
152 |
<link href="https://fonts.googleapis.com/css?family=Annie+Use+Your+Telescope|Just+Me+Again+Down+Here|Nixie+One|Six+Caps|Unkempt" rel="stylesheet">
|
153 |
</head>
|
154 |
<body style='background-color: #000; color: #fff; font-size: 18px; line-height: 1.6; font-family: "Josefin Sans", sans-serif;'>
|
155 |
+
<div style='max-width: 800px; margin: auto; padding: 20px;'>
|
156 |
+
{output_html}
|
157 |
+
</div>
|
158 |
</body>
|
159 |
</html>
|
160 |
"""
|
|
|
169 |
title="Circular Text Styler",
|
170 |
description="Enter a prompt to generate text with special word styling."
|
171 |
)
|
|
|
|
|
172 |
iface.launch()
|