Spaces:
Sleeping
Sleeping
Ubuntu
commited on
Commit
•
fc24fec
1
Parent(s):
0039eb7
revert the deisgn
Browse files
app.py
CHANGED
@@ -159,40 +159,31 @@ def check_password(password):
|
|
159 |
def run_speech_translation(audio, source_lang, target_lang, youtube_url):
|
160 |
transcription, translated_text, audio_url = transcribe_and_speak(audio, source_lang, target_lang, youtube_url)
|
161 |
|
|
|
|
|
162 |
return transcription, translated_text, audio_url, embedded_video
|
163 |
|
164 |
-
|
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 |
-
|
180 |
-
|
181 |
-
|
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(
|
189 |
-
|
190 |
-
|
191 |
-
|
|
|
|
|
192 |
user_audio_output = gr.Audio(label="Translated Speech")
|
193 |
|
194 |
-
|
195 |
-
user_video_output = gr.HTML(label="YouTube Video")
|
196 |
|
197 |
def update_button_state(audio, youtube_url):
|
198 |
print(audio, youtube_url)
|
@@ -219,16 +210,7 @@ with gr.Blocks(css=custom_css) as demo:
|
|
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 ""
|
|
|
159 |
def run_speech_translation(audio, source_lang, target_lang, youtube_url):
|
160 |
transcription, translated_text, audio_url = transcribe_and_speak(audio, source_lang, target_lang, youtube_url)
|
161 |
|
162 |
+
# Generate embedded video HTML if YouTube URL is prov
|
163 |
+
|
164 |
return transcription, translated_text, audio_url, embedded_video
|
165 |
|
166 |
+
with gr.Blocks() as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
gr.Markdown("# Speech Translation")
|
168 |
+
|
169 |
+
# with gr.Tab("User Mode"):
|
170 |
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.")
|
171 |
|
172 |
with gr.Row():
|
173 |
+
user_audio_input = gr.Audio(sources=["microphone", "upload"], type="filepath")
|
174 |
+
user_youtube_url = gr.Textbox(label="YouTube URL (optional)")
|
175 |
+
user_source_lang = gr.Dropdown(choices=["en", "ma", "ta", "zh"], label="Source Language", value="en")
|
176 |
+
user_target_lang = gr.Dropdown(choices=["en", "ma", "ta", "zh"], label="Target Language", value="zh")
|
|
|
|
|
|
|
|
|
177 |
|
178 |
+
with gr.Row():
|
179 |
+
user_button = gr.Button("Translate and Speak", interactive=False)
|
180 |
+
|
181 |
+
with gr.Row():
|
182 |
+
user_transcription_output = gr.Textbox(label="Transcription")
|
183 |
+
user_translation_output = gr.Textbox(label="Translation")
|
184 |
user_audio_output = gr.Audio(label="Translated Speech")
|
185 |
|
186 |
+
user_video_output = gr.HTML(label="YouTube Video")
|
|
|
187 |
|
188 |
def update_button_state(audio, youtube_url):
|
189 |
print(audio, youtube_url)
|
|
|
210 |
if youtube_url:
|
211 |
try:
|
212 |
video_id = fetch_youtube_id(youtube_url)
|
213 |
+
return f'<iframe width="560" height="315" src="https://www.youtube.com/embed/{video_id}" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
214 |
except Exception as e:
|
215 |
print(f"Error embedding video: {e}")
|
216 |
return ""
|