'''
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, num_return_sequences=1)
generated_text = generated[0]['generated_text']
generated_text = generated_text[:200] # Limit output length
words = generated_text.split()
for i, word in enumerate(words):
clean_word = ''.join(filter(str.isalnum, word)).lower()
if clean_word in SPECIAL_WORDS:
special_word = word
initial_word_design = generate_initial_design(word)
words[i] = initial_word_design
else:
words[i] = word
output_html = ' '.join(words)
final_output = f"""
{output_html}
"""
return final_output
def trigger_movement(input_html):
"""Function to trigger the movement animation."""
global initial_word_design, special_word
if not initial_word_design or not special_word:
return input_html
movement_design = generate_movement_design(special_word)
updated_html = input_html.replace(initial_word_design, movement_design, 1)
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()