Commit ·
f6eb9db
1
Parent(s): ce7947f
Add dedicated MP3 file download component and parallelize large text translation
Browse files- app.py +5 -4
- pipeline/translation.py +10 -6
app.py
CHANGED
|
@@ -323,16 +323,16 @@ def process_standard_pipeline(image, document, input_text, emotion_choice, proce
|
|
| 323 |
|
| 324 |
text_to_translate = text_to_translate.strip()
|
| 325 |
if not text_to_translate:
|
| 326 |
-
return "No text detected", "", None
|
| 327 |
|
| 328 |
tamil_translation = translate_to_tamil(text_to_translate, spicy=spicy_mode, mode=processing_mode)
|
| 329 |
sample_rate, audio_data = generate_tamil_speech(tamil_translation, emotion_choice, mode=processing_mode)
|
| 330 |
|
| 331 |
if sample_rate and audio_data is not None:
|
| 332 |
mp3_path = save_audio_to_mp3(sample_rate, audio_data)
|
| 333 |
-
return text_to_translate, tamil_translation, mp3_path
|
| 334 |
|
| 335 |
-
return text_to_translate, tamil_translation, None
|
| 336 |
|
| 337 |
def load_comic_page(pdf_path, page_num):
|
| 338 |
if not pdf_path:
|
|
@@ -672,6 +672,7 @@ with gr.Blocks(title="Maya: Immersive Manga AI", css=CUSTOM_CSS) as demo:
|
|
| 672 |
out_text = gr.Textbox(label="Original Text (Cleaned)", lines=5)
|
| 673 |
out_tamil = gr.Textbox(label="Tamil Translation", lines=5)
|
| 674 |
out_audio = gr.Audio(label="Audio Output")
|
|
|
|
| 675 |
|
| 676 |
|
| 677 |
with gr.Tab("📖 Custom Dictionary"):
|
|
@@ -884,7 +885,7 @@ with gr.Blocks(title="Maya: Immersive Manga AI", css=CUSTOM_CSS) as demo:
|
|
| 884 |
submit_std.click(
|
| 885 |
process_standard_pipeline,
|
| 886 |
inputs=[gr.State(None), gr.State(None), input_text, voice_style_std, processing_mode_std, spicy_mode_std],
|
| 887 |
-
outputs=[out_text, out_tamil, out_audio]
|
| 888 |
)
|
| 889 |
|
| 890 |
# URL Import Logic
|
|
|
|
| 323 |
|
| 324 |
text_to_translate = text_to_translate.strip()
|
| 325 |
if not text_to_translate:
|
| 326 |
+
return "No text detected", "", None, None
|
| 327 |
|
| 328 |
tamil_translation = translate_to_tamil(text_to_translate, spicy=spicy_mode, mode=processing_mode)
|
| 329 |
sample_rate, audio_data = generate_tamil_speech(tamil_translation, emotion_choice, mode=processing_mode)
|
| 330 |
|
| 331 |
if sample_rate and audio_data is not None:
|
| 332 |
mp3_path = save_audio_to_mp3(sample_rate, audio_data)
|
| 333 |
+
return text_to_translate, tamil_translation, mp3_path, mp3_path
|
| 334 |
|
| 335 |
+
return text_to_translate, tamil_translation, None, None
|
| 336 |
|
| 337 |
def load_comic_page(pdf_path, page_num):
|
| 338 |
if not pdf_path:
|
|
|
|
| 672 |
out_text = gr.Textbox(label="Original Text (Cleaned)", lines=5)
|
| 673 |
out_tamil = gr.Textbox(label="Tamil Translation", lines=5)
|
| 674 |
out_audio = gr.Audio(label="Audio Output")
|
| 675 |
+
out_download = gr.File(label="📥 Download Audio File (MP3)")
|
| 676 |
|
| 677 |
|
| 678 |
with gr.Tab("📖 Custom Dictionary"):
|
|
|
|
| 885 |
submit_std.click(
|
| 886 |
process_standard_pipeline,
|
| 887 |
inputs=[gr.State(None), gr.State(None), input_text, voice_style_std, processing_mode_std, spicy_mode_std],
|
| 888 |
+
outputs=[out_text, out_tamil, out_audio, out_download]
|
| 889 |
)
|
| 890 |
|
| 891 |
# URL Import Logic
|
pipeline/translation.py
CHANGED
|
@@ -394,12 +394,16 @@ class Translator:
|
|
| 394 |
return ""
|
| 395 |
|
| 396 |
# Chunk large inputs to prevent Google Translate / API timeouts and errors
|
| 397 |
-
if len(text) >
|
| 398 |
-
chunks = split_into_safe_chunks(text, max_chars=
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 403 |
return "\n\n".join(translated_chunks)
|
| 404 |
|
| 405 |
clean_text = " ".join([w for w in text.split() if len(w) > 1 or w.isalnum()]).strip()
|
|
|
|
| 394 |
return ""
|
| 395 |
|
| 396 |
# Chunk large inputs to prevent Google Translate / API timeouts and errors
|
| 397 |
+
if len(text) > 1500:
|
| 398 |
+
chunks = split_into_safe_chunks(text, max_chars=1500)
|
| 399 |
+
if "Cloud" in mode:
|
| 400 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 401 |
+
def _trans(c):
|
| 402 |
+
return self.translate(c, target_lang, spicy, colloquial, mode)
|
| 403 |
+
with ThreadPoolExecutor(max_workers=min(len(chunks), 10)) as executor:
|
| 404 |
+
translated_chunks = list(executor.map(_trans, chunks))
|
| 405 |
+
else:
|
| 406 |
+
translated_chunks = [self.translate(chunk, target_lang, spicy, colloquial, mode) for chunk in chunks]
|
| 407 |
return "\n\n".join(translated_chunks)
|
| 408 |
|
| 409 |
clean_text = " ".join([w for w in text.split() if len(w) > 1 or w.isalnum()]).strip()
|