circulartext commited on
Commit
9e972ca
·
verified ·
1 Parent(s): 35d16ae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -10
app.py CHANGED
@@ -1,11 +1,12 @@
1
  import gradio as gr
2
  import random
3
  import time
 
4
 
5
  # Global variables
6
  current_text = ""
7
  special_words = []
8
- special_word_positions = []
9
 
10
  def generate_random_style(word):
11
  """Generate random styling for a word but keep it black."""
@@ -65,7 +66,7 @@ def generate_random_style(word):
65
 
66
  def display_normal_text():
67
  """Display the text normally without any styling."""
68
- global current_text, special_words, special_word_positions
69
 
70
  paragraphs = [
71
  'How did we get here December 30th 2124 "Good morning, Benshiro. Wake up! We\'ve got A.I. training ahead," urged Benshiro\'s partner as they prepared for their day in sector A1 - A1000, one of the elite development sectors serving the World One government. It was the year 2124.',
@@ -74,7 +75,7 @@ def display_normal_text():
74
  '2036 By 2036, the government implemented a new policy for One Country accounts. If individuals committed a crime and did not turn themselves in, their accounts would be frozen. This rule was highly controversial, as it curtailed personal freedoms. In a bold initiative, the One Country President announced plans to establish a 99% robotic police force by 2045. The program will begin immediately, aiming to have 30% of the force composed of active robots within the first phase. Human officers would collaborate with these machines in decision-making processes. To support this vision, a vast 10,000-acre automation facility—equivalent to the size of Manhattan—was constructed. This facility aimed to produce advanced robots and flying vehicles, initially reserved for government officials and the wealthy, signaling a significant shift towards automation in society.'
75
  ]
76
 
77
- # Select one random word from each paragraph
78
  special_words = []
79
  for paragraph in paragraphs:
80
  words = paragraph.split()
@@ -90,8 +91,8 @@ def display_normal_text():
90
  </div>
91
  """
92
 
93
- def trigger_movement():
94
- """Apply random styling to the selected words."""
95
  global current_text, special_words
96
 
97
  if not special_words:
@@ -110,23 +111,51 @@ def trigger_movement():
110
  else:
111
  styled_paragraphs.append(paragraph)
112
 
113
- updated_text = '<br><br>'.join(styled_paragraphs)
114
- current_text = updated_text
115
 
116
  return f"""
117
  <div style="font-family: 'Josefin Sans', sans-serif; font-size: 16px; line-height: 1.6; padding: 20px; max-width: 800px;">
118
- {updated_text}
119
  </div>
120
  """
121
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  # Create Gradio interface using Blocks
123
  with gr.Blocks() as demo:
124
- gr.Markdown("# CircularText Styler\nText with special word styling and animations.")
125
 
126
  output_html = gr.HTML()
127
  with gr.Row():
128
  start_btn = gr.Button("▶ Show Text")
129
- animate_btn = gr.Button("✨ Trigger Movement")
130
 
131
  start_btn.click(display_normal_text, inputs=[], outputs=output_html)
132
  animate_btn.click(trigger_movement, inputs=[], outputs=output_html)
 
1
  import gradio as gr
2
  import random
3
  import time
4
+ import threading
5
 
6
  # Global variables
7
  current_text = ""
8
  special_words = []
9
+ is_styling = False
10
 
11
  def generate_random_style(word):
12
  """Generate random styling for a word but keep it black."""
 
66
 
67
  def display_normal_text():
68
  """Display the text normally without any styling."""
69
+ global current_text, special_words
70
 
71
  paragraphs = [
72
  'How did we get here December 30th 2124 "Good morning, Benshiro. Wake up! We\'ve got A.I. training ahead," urged Benshiro\'s partner as they prepared for their day in sector A1 - A1000, one of the elite development sectors serving the World One government. It was the year 2124.',
 
75
  '2036 By 2036, the government implemented a new policy for One Country accounts. If individuals committed a crime and did not turn themselves in, their accounts would be frozen. This rule was highly controversial, as it curtailed personal freedoms. In a bold initiative, the One Country President announced plans to establish a 99% robotic police force by 2045. The program will begin immediately, aiming to have 30% of the force composed of active robots within the first phase. Human officers would collaborate with these machines in decision-making processes. To support this vision, a vast 10,000-acre automation facility—equivalent to the size of Manhattan—was constructed. This facility aimed to produce advanced robots and flying vehicles, initially reserved for government officials and the wealthy, signaling a significant shift towards automation in society.'
76
  ]
77
 
78
+ # Select one random word from each paragraph for future styling
79
  special_words = []
80
  for paragraph in paragraphs:
81
  words = paragraph.split()
 
91
  </div>
92
  """
93
 
94
+ def get_styled_text():
95
+ """Get the styled version of the text."""
96
  global current_text, special_words
97
 
98
  if not special_words:
 
111
  else:
112
  styled_paragraphs.append(paragraph)
113
 
114
+ styled_text = '<br><br>'.join(styled_paragraphs)
 
115
 
116
  return f"""
117
  <div style="font-family: 'Josefin Sans', sans-serif; font-size: 16px; line-height: 1.6; padding: 20px; max-width: 800px;">
118
+ {styled_text}
119
  </div>
120
  """
121
 
122
+ def get_normal_text():
123
+ """Get the normal version of the text."""
124
+ global current_text
125
+
126
+ return f"""
127
+ <div style="font-family: 'Josefin Sans', sans-serif; font-size: 16px; line-height: 1.6; padding: 20px; max-width: 800px;">
128
+ {current_text}
129
+ </div>
130
+ """
131
+
132
+ def trigger_movement():
133
+ """Apply styling then revert back to normal - creates sneaking effect."""
134
+ global is_styling
135
+
136
+ if is_styling:
137
+ return get_normal_text()
138
+
139
+ # Show styled version first
140
+ styled_output = get_styled_text()
141
+ is_styling = True
142
+
143
+ # Use generator to show styled then normal
144
+ yield styled_output
145
+
146
+ # Wait a moment then show normal text
147
+ time.sleep(1.5) # Show styled text for 1.5 seconds
148
+ is_styling = False
149
+ yield get_normal_text()
150
+
151
  # Create Gradio interface using Blocks
152
  with gr.Blocks() as demo:
153
+ gr.Markdown("# CircularText Styler\nText with sneaking style effect - words style briefly then return to normal.")
154
 
155
  output_html = gr.HTML()
156
  with gr.Row():
157
  start_btn = gr.Button("▶ Show Text")
158
+ animate_btn = gr.Button("✨ Sneak Style")
159
 
160
  start_btn.click(display_normal_text, inputs=[], outputs=output_html)
161
  animate_btn.click(trigger_movement, inputs=[], outputs=output_html)