Ubuntu commited on
Commit
0039eb7
1 Parent(s): 795f06e

enhance UI

Browse files
Files changed (1) hide show
  1. app.py +35 -15
app.py CHANGED
@@ -161,27 +161,38 @@ def run_speech_translation(audio, source_lang, target_lang, youtube_url):
161
 
162
  return transcription, translated_text, audio_url, embedded_video
163
 
164
- with gr.Blocks() as demo:
 
 
 
 
 
 
 
 
 
 
165
  gr.Markdown("# Speech Translation")
166
-
167
- # with gr.Tab("User Mode"):
168
  gr.Markdown("Speak into the microphone, upload an audio file, or provide a YouTube URL. The app will translate and speak it back to you.")
169
 
170
  with gr.Row():
171
- user_audio_input = gr.Audio(sources=["microphone", "upload"], type="filepath")
172
- user_youtube_url = gr.Textbox(label="YouTube URL (optional)")
173
- user_source_lang = gr.Dropdown(choices=["en", "ma", "ta", "zh"], label="Source Language", value="en")
174
- user_target_lang = gr.Dropdown(choices=["en", "ma", "ta", "zh"], label="Target Language", value="zh")
175
-
176
- with gr.Row():
177
- user_button = gr.Button("Translate and Speak", interactive=False)
 
178
 
179
- with gr.Row():
180
- user_transcription_output = gr.Textbox(label="Transcription")
181
- user_translation_output = gr.Textbox(label="Translation")
 
182
  user_audio_output = gr.Audio(label="Translated Speech")
183
 
184
- user_video_output = gr.HTML(label="YouTube Video")
 
185
 
186
  def update_button_state(audio, youtube_url):
187
  print(audio, youtube_url)
@@ -208,7 +219,16 @@ with gr.Blocks() as demo:
208
  if youtube_url:
209
  try:
210
  video_id = fetch_youtube_id(youtube_url)
211
- return f'<iframe width="560" height="315" src="https://www.youtube.com/embed/{video_id}" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>'
 
 
 
 
 
 
 
 
 
212
  except Exception as e:
213
  print(f"Error embedding video: {e}")
214
  return ""
 
161
 
162
  return transcription, translated_text, audio_url, embedded_video
163
 
164
+ custom_css = """
165
+ .container { max-width: 800px; margin: auto; padding: 20px; }
166
+ h1 { color: #2c3e50; text-align: center; margin-bottom: 30px; }
167
+ .gr-form { background-color: #f7f9fc; border-radius: 10px; padding: 20px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); }
168
+ .gr-button { background-color: #3498db; color: white; }
169
+ .gr-button:hover { background-color: #2980b9; }
170
+ .output-row { margin-top: 30px; }
171
+ .video-container { display: flex; justify-content: center; margin-top: 20px; }
172
+ """
173
+
174
+ with gr.Blocks(css=custom_css) as demo:
175
  gr.Markdown("# Speech Translation")
 
 
176
  gr.Markdown("Speak into the microphone, upload an audio file, or provide a YouTube URL. The app will translate and speak it back to you.")
177
 
178
  with gr.Row():
179
+ with gr.Column(scale=2):
180
+ user_audio_input = gr.Audio(sources=["microphone", "upload"], type="filepath", label="Audio Input")
181
+ user_youtube_url = gr.Textbox(label="YouTube URL (optional)")
182
+
183
+ with gr.Column(scale=1):
184
+ user_source_lang = gr.Dropdown(choices=["en", "ma", "ta", "zh"], label="Source Language", value="en")
185
+ user_target_lang = gr.Dropdown(choices=["en", "ma", "ta", "zh"], label="Target Language", value="zh")
186
+ user_button = gr.Button("Translate and Speak", interactive=False)
187
 
188
+ with gr.Row(class_name="output-row"):
189
+ with gr.Column():
190
+ user_transcription_output = gr.Textbox(label="Transcription")
191
+ user_translation_output = gr.Textbox(label="Translation")
192
  user_audio_output = gr.Audio(label="Translated Speech")
193
 
194
+ with gr.Row(class_name="video-container"):
195
+ user_video_output = gr.HTML(label="YouTube Video")
196
 
197
  def update_button_state(audio, youtube_url):
198
  print(audio, youtube_url)
 
219
  if youtube_url:
220
  try:
221
  video_id = fetch_youtube_id(youtube_url)
222
+ return f'''
223
+ <div style="position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden; max-width: 100%;">
224
+ <iframe style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"
225
+ src="https://www.youtube.com/embed/{video_id}"
226
+ frameborder="0"
227
+ allow="autoplay; encrypted-media"
228
+ allowfullscreen>
229
+ </iframe>
230
+ </div>
231
+ '''
232
  except Exception as e:
233
  print(f"Error embedding video: {e}")
234
  return ""