shanzaejaz commited on
Commit
9a756ca
Β·
verified Β·
1 Parent(s): fc7211d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -90,24 +90,24 @@ def translate_english_to_urdu(text, script_choice, tone_choice):
90
 
91
  # ─── 3. INTERFACE PROCESSING WRAPPERS ───────────────────────────────────────
92
  def handle_text_translation(text, script_choice, tone_choice):
93
- """Processes text translation and routes it only to the active script output box."""
94
  translated = translate_english_to_urdu(text, script_choice, tone_choice)
95
  if script_choice == "Arabic Script (Nastaliq)":
96
- return translated, "" # Clear out the hidden box
97
  else:
98
- return "", translated
99
 
100
  def handle_voice_translation(audio_path, script_choice, tone_choice):
101
- """Processes voice audio and routes the translation to the correct box layout."""
102
  transcribed = transcribe_audio(audio_path)
103
  if transcribed.startswith("⚠️"):
104
- return transcribed, transcribed, transcribed
105
 
106
  translated = translate_english_to_urdu(transcribed, script_choice, tone_choice)
107
  if script_choice == "Arabic Script (Nastaliq)":
108
- return transcribed, translated, ""
109
  else:
110
- return transcribed, "", translated
111
 
112
 
113
  custom_css = """
@@ -182,7 +182,7 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft(primary_hue="indigo", second
182
  outputs=[urdu_output_nastaliq, urdu_output_roman, urdu_voice_nastaliq, urdu_voice_roman]
183
  )
184
 
185
- # Fixed Multi-Output Text Handler
186
  translate_btn.click(
187
  fn=handle_text_translation,
188
  inputs=[english_input, script_choice, tone_choice],
@@ -190,7 +190,7 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft(primary_hue="indigo", second
190
  show_progress="full"
191
  )
192
 
193
- # Fixed Multi-Output Voice Handler
194
  voice_translate_btn.click(
195
  fn=handle_voice_translation,
196
  inputs=[audio_input, script_choice, tone_choice],
 
90
 
91
  # ─── 3. INTERFACE PROCESSING WRAPPERS ───────────────────────────────────────
92
  def handle_text_translation(text, script_choice, tone_choice):
93
+ """Processes text translation and dynamically updates component configurations."""
94
  translated = translate_english_to_urdu(text, script_choice, tone_choice)
95
  if script_choice == "Arabic Script (Nastaliq)":
96
+ return gr.update(value=translated, visible=True), gr.update(value="", visible=False)
97
  else:
98
+ return gr.update(value="", visible=False), gr.update(value=translated, visible=True)
99
 
100
  def handle_voice_translation(audio_path, script_choice, tone_choice):
101
+ """Processes voice audio and dynamically routes outputs alongside state metrics."""
102
  transcribed = transcribe_audio(audio_path)
103
  if transcribed.startswith("⚠️"):
104
+ return transcribed, gr.update(value=transcribed, visible=True), gr.update(value=transcribed, visible=False)
105
 
106
  translated = translate_english_to_urdu(transcribed, script_choice, tone_choice)
107
  if script_choice == "Arabic Script (Nastaliq)":
108
+ return transcribed, gr.update(value=translated, visible=True), gr.update(value="", visible=False)
109
  else:
110
+ return transcribed, gr.update(value="", visible=False), gr.update(value=translated, visible=True)
111
 
112
 
113
  custom_css = """
 
182
  outputs=[urdu_output_nastaliq, urdu_output_roman, urdu_voice_nastaliq, urdu_voice_roman]
183
  )
184
 
185
+ # Fixed Multi-Output Text Handler using gr.update parameters
186
  translate_btn.click(
187
  fn=handle_text_translation,
188
  inputs=[english_input, script_choice, tone_choice],
 
190
  show_progress="full"
191
  )
192
 
193
+ # Fixed Multi-Output Voice Handler using gr.update parameters
194
  voice_translate_btn.click(
195
  fn=handle_voice_translation,
196
  inputs=[audio_input, script_choice, tone_choice],