Spaces:
Running
Running
File size: 7,871 Bytes
48706c6 4e61a3c b240e90 4e61a3c 48706c6 e8ff1c4 b240e90 48706c6 47d69ec 34d154f 47d69ec 34d154f b240e90 48706c6 b240e90 47d69ec b240e90 07e18fc a14b594 de5a24b b240e90 34d154f de5a24b 34d154f b240e90 07e18fc 47d69ec b240e90 34d154f 47d69ec 34d154f b240e90 47d69ec 34d154f 608768f b240e90 47d69ec de5a24b 47d69ec 36c4c2f 47d69ec 07e18fc 34d154f de5a24b 34d154f b240e90 de5a24b 36c4c2f 34d154f 48706c6 a14b594 de5a24b 4e61a3c b240e90 07e18fc 48706c6 b240e90 4e61a3c 023bed0 b240e90 4e61a3c b240e90 07e18fc b240e90 de5a24b 4e61a3c 48706c6 47d69ec de5a24b a14b594 de5a24b 07e18fc a14b594 48706c6 a14b594 de5a24b 34d154f 48706c6 de5a24b 4e61a3c 48706c6 a14b594 6f26936 b240e90 6f26936 b240e90 6f26936 a14b594 de5a24b a14b594 de5a24b a14b594 de5a24b 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 |
import gradio as gr
import random
from transformers import pipeline
# Load the model once when the app starts
generator = pipeline('text-generation', model='distilgpt2', max_length=25)
# Predefined words to check
SPECIAL_WORDS = [
'movie', 'excited', 'waiting', 'long', 'time', 'production', 'real', 'coded', 'digital', 'favorite',
'asking', 'doing', 'basketball', 'soccer', 'football', 'baseball', 'soup', 'food', 'burgers', 'pizza',
'fruit', 'pineapple', 'milk', 'jello', 'candy', 'rice', 'greens', 'lettuce', 'oatmeal', 'cereal',
'dogs', 'cats', 'animals', 'goats', 'sheep', 'movies', 'money', 'bank', 'account', 'keeping',
'looking', 'moving', 'boxes', 'elephants', 'movement', 'coding', 'developing', 'going', 'cruise',
'ship', 'boat', 'bahamas', 'foods', 'healthy', 'eating', 'important', 'pennsylvania', 'atlanta',
'north carolina', 'new york', 'france', 'paris', 'work', 'jobs', 'computers', 'computer', 'grocery',
'glamorous', 'version', 'truck', 'pickup', 'play', 'types', 'games', 'applications', 'quantum',
'speeds', 'advancements', 'technological', 'glimpse', 'countless', 'technology', 'future', 'walking',
'hello', 'jordan', 'season', 'superstar', 'nba', 'championship', 'leading', 'points', 'assist',
'career', 'chicago', 'scared', 'tongue', 'energy', 'disguise', 'business', 'older', 'grown', 'call',
'bills', 'garden', 'house', 'fallen', 'blossoms', 'lawn', 'love', 'forever', 'most', 'fan', 'clout',
'space', 'team', 'today', 'woke', 'work', 'relax', 'quicker', 'thicker', 'richer', 'data', 'ballet',
'dancer', 'goat', 'post', 'lebron', 'james', 'eagles', 'rockets', 'times', 'tank', 'pencil', 'watch',
'rolex', 'rappers', 'rockstar', 'rocket', 'rocks', 'tooth', 'teeth', 'pancake', 'breakfast', 'lunch',
'dinner', 'zoom', 'calling', 'talking', 'rule', 'ruler', 'rick', 'morty', 'martin', 'smith', 'wild',
'track', 'field', 'touchdown', 'basket', 'hope', 'yours', 'thank', 'olympics', 'sports', 'help',
'legal', 'law', 'firm', 'crowd', 'winner', 'winter', 'smoking', 'green', 'purple', 'blue', 'pink',
'orange', 'black', 'white', 'yellow', 'gold', 'weather', 'sun', 'middle', 'summer', 'heat', 'spring'
]
def generate_design(word, color='#000000', animate=False):
"""Generate design for the special word."""
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 = ["18px", "19px", "20px"]
letter_spacings = ["-1px", "0px", "1px"]
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 = ["-10deg", "0deg", "10deg"]
letters = list(word)
styled_letters = []
animation_name = f"animate_{random.randint(0, 10000)}" if animate else ""
keyframes = f"""
@keyframes {animation_name} {{
0% {{ transform: scale(1) rotate(0deg); }}
50% {{ transform: scale(1.2) rotate(10deg); }}
100% {{ transform: scale(1) rotate(0deg); }}
}}
""" if animate else ""
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)})',
'color': color,
'display': 'inline-block',
'margin': '0 1px',
'vertical-align': 'middle',
'animation': f'{animation_name} 0.5s ease-in-out' if animate else '',
'animation-delay': f'{i * 0.1}s' if animate else ''
}
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'''
<style>
{keyframes}
.styled-letter {{
transition: all 0.3s ease;
}}
</style>
<span style="display: inline-flex; align-items: baseline; vertical-align: middle; margin: 0 2px;">
{" ".join(styled_letters)}
</span>
'''
def process_text(input_text):
"""Process text and generate the initial output with special word styled in black."""
generated = generator(input_text, num_return_sequences=1)
generated_text = generated[0]['generated_text']
generated_text = generated_text[:200]
words = generated_text.split()
processed_words = []
for word in words:
clean_word = ''.join(filter(str.isalnum, word)).lower()
if clean_word in SPECIAL_WORDS:
processed_words.append(generate_design(word))
else:
processed_words.append(word)
output_html = ' '.join(processed_words)
final_output = f"""
<html>
<head>
<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">
<style>
body {{
background-color: #fff;
color: #000;
font-size: 18px;
line-height: 1.6;
font-family: "Josefin Sans", sans-serif;
padding: 20px;
}}
</style>
</head>
<body>
<div style='max-width: 800px; margin: auto;'>
{output_html}
</div>
</body>
</html>
"""
return final_output
def trigger_movement(input_html):
"""Function to trigger the movement animation for all special words."""
words = input_html.split()
updated_words = []
for word in words:
clean_word = ''.join(filter(str.isalnum, word)).lower()
if clean_word in SPECIAL_WORDS:
updated_words.append(generate_design(clean_word, color=f'#{random.randint(0, 0xFFFFFF):06x}', animate=True))
else:
updated_words.append(word)
updated_html = ' '.join(updated_words)
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")
submit_button.click(process_text, inputs=input_text, outputs=output_html)
animate_button.click(trigger_movement, inputs=output_html, outputs=output_html)
# Launch the app
demo.launch() |