add src_lang and tgt_lang
Browse files
app.py
CHANGED
@@ -4,7 +4,8 @@ from huggingface_hub import InferenceClient
|
|
4 |
import gradio as gr
|
5 |
|
6 |
# Initialize the translation pipeline
|
7 |
-
|
|
|
8 |
|
9 |
# Initialize the text-to-speech client
|
10 |
# Make sure you have HF_TOKEN set as a secret in your Hugging Face Space
|
@@ -18,7 +19,8 @@ def translate_and_speak(chinese_text):
|
|
18 |
Translates Chinese text to English and generates speech.
|
19 |
"""
|
20 |
# Translate the text
|
21 |
-
|
|
|
22 |
|
23 |
# Generate speech from the translated text
|
24 |
# Use a try-except block to handle potential errors during speech generation
|
|
|
4 |
import gradio as gr
|
5 |
|
6 |
# Initialize the translation pipeline
|
7 |
+
# Specify the source and target languages for translation
|
8 |
+
translation_pipeline = pipeline("translation", model="facebook/nllb-200-distilled-600M", src_lang="zh", tgt_lang="en")
|
9 |
|
10 |
# Initialize the text-to-speech client
|
11 |
# Make sure you have HF_TOKEN set as a secret in your Hugging Face Space
|
|
|
19 |
Translates Chinese text to English and generates speech.
|
20 |
"""
|
21 |
# Translate the text
|
22 |
+
# Pass the input text as a list to the pipeline
|
23 |
+
translated_text = translation_pipeline([chinese_text])[0]['translation_text']
|
24 |
|
25 |
# Generate speech from the translated text
|
26 |
# Use a try-except block to handle potential errors during speech generation
|