concauu commited on
Commit
bfa419b
·
verified ·
1 Parent(s): d3399d2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -14
app.py CHANGED
@@ -104,9 +104,10 @@ def transcribe_speech(audio_file):
104
  audio = r.record(source)
105
  return r.recognize_google(audio)
106
 
107
- def get_font_size(size):
108
- sizes = {"Small": "12px", "Medium": "16px", "Large": "20px"}
109
- return sizes[size]
 
110
 
111
  @spaces.GPU(duration=75)
112
  def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, guidance_scale=3.5, num_inference_steps=28, progress=gr.Progress(track_tqdm=True)):
@@ -174,7 +175,11 @@ css = """
174
  """
175
  js_callback = """
176
  (fontSize) => {
177
- document.body.style.fontSize = fontSize;
 
 
 
 
178
  return "";
179
  }
180
  """
@@ -183,29 +188,28 @@ with gr.Blocks(css="""
183
  .user-msg { background: #e3f2fd; border-radius: 15px; padding: 10px; margin: 5px; }
184
  .bot-msg { background: #f5f5f5; border-radius: 15px; padding: 10px; margin: 5px; }
185
  """) as demo:
186
- # Global controls: font size and voice input
187
  font_choice = gr.Dropdown(
188
  choices=["Small", "Medium", "Large"],
189
  value="Medium",
190
  label="Font Size"
191
  )
192
- demo_markdown = gr.Markdown("### This text (and all other text) will change size dynamically.")
193
  sample_text = gr.Textbox(label="Try typing here:", value="The quick brown fox jumps over the lazy dog.")
194
- font_style = gr.HTML() # This will receive the injected CSS for font size
195
  font_choice.change(
196
- fn=get_font_size,
197
  inputs=font_choice,
198
- outputs=[], # No output component is updated by Python.
199
- js=js_callback # This JS code runs on the client to update the page.
200
  )
201
 
202
  gr.Markdown("## Voice Input: Record your prompt")
203
- audio_input = gr.Audio(sources="microphone", type="filepath", label="Record your voice")
 
204
  transcribe_button = gr.Button("Transcribe Voice")
205
  transcribed_text = gr.Textbox(label="Transcribed Text", lines=2)
206
  transcribe_button.click(fn=transcribe_speech, inputs=audio_input, outputs=transcribed_text)
207
-
208
- # Optionally, add a button to copy transcribed text to the prompt textbox.
209
  copy_transcribed = gr.Button("Copy Transcribed Text to Prompt")
210
 
211
  # Main interface for image generation
@@ -216,7 +220,6 @@ with gr.Blocks(css="""
216
  original_prompt = gr.Textbox(label="Original Prompt", lines=2)
217
  enhance_button = gr.Button("Enhance Prompt")
218
  enhanced_prompt = gr.Textbox(label="Enhanced Prompt (Editable)", lines=2)
219
- # Copy transcribed text into the original prompt
220
  copy_transcribed.click(fn=lambda txt: txt, inputs=transcribed_text, outputs=original_prompt)
221
  enhance_button.click(enhance_prompt, original_prompt, enhanced_prompt)
222
  gr.Markdown("### Step 2: Generate Image")
 
104
  audio = r.record(source)
105
  return r.recognize_google(audio)
106
 
107
+ def set_font_size(choice):
108
+ return gr.skip()
109
+
110
+
111
 
112
  @spaces.GPU(duration=75)
113
  def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, guidance_scale=3.5, num_inference_steps=28, progress=gr.Progress(track_tqdm=True)):
 
175
  """
176
  js_callback = """
177
  (fontSize) => {
178
+ const sizeMap = {"Small": "12px", "Medium": "16px", "Large": "20px"};
179
+ const newSize = sizeMap[fontSize];
180
+ if(newSize){
181
+ document.body.style.fontSize = newSize;
182
+ }
183
  return "";
184
  }
185
  """
 
188
  .user-msg { background: #e3f2fd; border-radius: 15px; padding: 10px; margin: 5px; }
189
  .bot-msg { background: #f5f5f5; border-radius: 15px; padding: 10px; margin: 5px; }
190
  """) as demo:
191
+ # Global controls: Font size adjuster and voice input
192
  font_choice = gr.Dropdown(
193
  choices=["Small", "Medium", "Large"],
194
  value="Medium",
195
  label="Font Size"
196
  )
197
+ gr.Markdown("### This text (and all other text) will change size dynamically.")
198
  sample_text = gr.Textbox(label="Try typing here:", value="The quick brown fox jumps over the lazy dog.")
199
+ # When font_choice changes, call set_font_size (returns gr.skip() so value remains unchanged)
200
  font_choice.change(
201
+ fn=set_font_size,
202
  inputs=font_choice,
203
+ outputs=[], # No output updated by Python.
204
+ js=js_callback # JS callback updates document's font size.
205
  )
206
 
207
  gr.Markdown("## Voice Input: Record your prompt")
208
+ # For Gradio 4.x, use source="microphone"
209
+ audio_input = gr.Audio(source="microphone", type="filepath", label="Record your voice")
210
  transcribe_button = gr.Button("Transcribe Voice")
211
  transcribed_text = gr.Textbox(label="Transcribed Text", lines=2)
212
  transcribe_button.click(fn=transcribe_speech, inputs=audio_input, outputs=transcribed_text)
 
 
213
  copy_transcribed = gr.Button("Copy Transcribed Text to Prompt")
214
 
215
  # Main interface for image generation
 
220
  original_prompt = gr.Textbox(label="Original Prompt", lines=2)
221
  enhance_button = gr.Button("Enhance Prompt")
222
  enhanced_prompt = gr.Textbox(label="Enhanced Prompt (Editable)", lines=2)
 
223
  copy_transcribed.click(fn=lambda txt: txt, inputs=transcribed_text, outputs=original_prompt)
224
  enhance_button.click(enhance_prompt, original_prompt, enhanced_prompt)
225
  gr.Markdown("### Step 2: Generate Image")