Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -1,104 +1,3 @@
|
|
1 |
-
# import os
|
2 |
-
# import gradio as gr
|
3 |
-
# from googletrans import Translator, LANGUAGES
|
4 |
-
# from TTS.api import TTS
|
5 |
-
|
6 |
-
# # Set environment variable to automatically accept the license terms
|
7 |
-
# os.environ["COQUI_TOS_AGREED"] = "1"
|
8 |
-
|
9 |
-
# # Load the TTS model once
|
10 |
-
# tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2", gpu=False)
|
11 |
-
# translator = Translator()
|
12 |
-
|
13 |
-
# # Define the list of supported languages
|
14 |
-
# SUPPORTED_LANGUAGES = {
|
15 |
-
# "English (en)": "en",
|
16 |
-
# "Spanish (es)": "es",
|
17 |
-
# "French (fr)": "fr",
|
18 |
-
# "German (de)": "de",
|
19 |
-
# "Italian (it)": "it",
|
20 |
-
# "Portuguese (pt)": "pt",
|
21 |
-
# "Polish (pl)": "pl",
|
22 |
-
# "Turkish (tr)": "tr",
|
23 |
-
# "Russian (ru)": "ru",
|
24 |
-
# "Dutch (nl)": "nl",
|
25 |
-
# "Czech (cs)": "cs",
|
26 |
-
# "Arabic (ar)": "ar",
|
27 |
-
# "Chinese (zh-cn)": "zh-cn",
|
28 |
-
# "Japanese (ja)": "ja",
|
29 |
-
# "Hungarian (hu)": "hu",
|
30 |
-
# "Korean (ko)": "ko",
|
31 |
-
# "Hindi (hi)": "hi"
|
32 |
-
# }
|
33 |
-
|
34 |
-
# def translate_text(text, input_lang, output_lang):
|
35 |
-
# try:
|
36 |
-
# translated = translator.translate(text, src=input_lang, dest=output_lang)
|
37 |
-
# return translated.text
|
38 |
-
# except Exception as e:
|
39 |
-
# return str(e)
|
40 |
-
|
41 |
-
# def generate_speech(input_text, voice_path, input_lang, output_lang, translation_enabled):
|
42 |
-
# try:
|
43 |
-
# # Check if translation is enabled
|
44 |
-
# if translation_enabled:
|
45 |
-
# # Translate text
|
46 |
-
# translated_text = translate_text(input_text, input_lang, output_lang)
|
47 |
-
# if 'ERROR' in translated_text:
|
48 |
-
# return translated_text, None
|
49 |
-
# else:
|
50 |
-
# translated_text = input_text
|
51 |
-
# output_lang = input_lang
|
52 |
-
|
53 |
-
# # Generate speech
|
54 |
-
# output_path = "output.wav"
|
55 |
-
# tts.tts_to_file(
|
56 |
-
# text=translated_text,
|
57 |
-
# file_path=output_path,
|
58 |
-
# speaker_wav=voice_path,
|
59 |
-
# language=output_lang,
|
60 |
-
# split_sentences=True
|
61 |
-
# )
|
62 |
-
# return translated_text, output_path
|
63 |
-
# except Exception as e:
|
64 |
-
# return str(e), None
|
65 |
-
|
66 |
-
# def update_output_lang_options(translation_enabled, input_lang):
|
67 |
-
# if not translation_enabled:
|
68 |
-
# return gr.update(choices=[input_lang], value=input_lang, interactive=False)
|
69 |
-
# return gr.update(choices=list(SUPPORTED_LANGUAGES.values()), value=input_lang, interactive=True)
|
70 |
-
|
71 |
-
# with gr.Blocks() as iface:
|
72 |
-
# with gr.Row():
|
73 |
-
# with gr.Column(scale=1):
|
74 |
-
# input_text = gr.Textbox(label="Input Text")
|
75 |
-
# voice_path = gr.Audio(type="filepath", label="Upload Voice")
|
76 |
-
# input_lang = gr.Dropdown(choices=list(SUPPORTED_LANGUAGES.values()), label="Input Language")
|
77 |
-
# output_lang = gr.Dropdown(choices=list(SUPPORTED_LANGUAGES.values()), label="Output Language")
|
78 |
-
# translation_enabled = gr.Checkbox(label="Enable Translation", value=True)
|
79 |
-
# generate_button = gr.Button("Generate Speech")
|
80 |
-
|
81 |
-
# with gr.Column(scale=1):
|
82 |
-
# translated_text = gr.Textbox(label="Translated Text")
|
83 |
-
# generated_speech = gr.Audio(label="Generated Speech")
|
84 |
-
|
85 |
-
# translation_enabled.change(
|
86 |
-
# update_output_lang_options,
|
87 |
-
# inputs=[translation_enabled, input_lang],
|
88 |
-
# outputs=output_lang
|
89 |
-
# )
|
90 |
-
|
91 |
-
# generate_button.click(
|
92 |
-
# generate_speech,
|
93 |
-
# inputs=[input_text, voice_path, input_lang, output_lang, translation_enabled],
|
94 |
-
# outputs=[translated_text, generated_speech]
|
95 |
-
# )
|
96 |
-
|
97 |
-
# iface.launch()
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
# v2:
|
102 |
import os
|
103 |
import gradio as gr
|
104 |
from googletrans import Translator, LANGUAGES
|
@@ -135,12 +34,9 @@ SUPPORTED_LANGUAGES = {
|
|
135 |
def translate_text(text, input_lang, output_lang):
|
136 |
try:
|
137 |
translated = translator.translate(text, src=input_lang, dest=output_lang)
|
138 |
-
|
139 |
-
return translated.text
|
140 |
-
else:
|
141 |
-
return "Translation failed: No text returned."
|
142 |
except Exception as e:
|
143 |
-
return
|
144 |
|
145 |
def generate_speech(input_text, voice_path, input_lang, output_lang, translation_enabled):
|
146 |
try:
|
@@ -148,7 +44,7 @@ def generate_speech(input_text, voice_path, input_lang, output_lang, translation
|
|
148 |
if translation_enabled:
|
149 |
# Translate text
|
150 |
translated_text = translate_text(input_text, input_lang, output_lang)
|
151 |
-
if '
|
152 |
return translated_text, None
|
153 |
else:
|
154 |
translated_text = input_text
|
@@ -199,3 +95,4 @@ with gr.Blocks() as iface:
|
|
199 |
)
|
200 |
|
201 |
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
from googletrans import Translator, LANGUAGES
|
|
|
34 |
def translate_text(text, input_lang, output_lang):
|
35 |
try:
|
36 |
translated = translator.translate(text, src=input_lang, dest=output_lang)
|
37 |
+
return translated.text
|
|
|
|
|
|
|
38 |
except Exception as e:
|
39 |
+
return str(e)
|
40 |
|
41 |
def generate_speech(input_text, voice_path, input_lang, output_lang, translation_enabled):
|
42 |
try:
|
|
|
44 |
if translation_enabled:
|
45 |
# Translate text
|
46 |
translated_text = translate_text(input_text, input_lang, output_lang)
|
47 |
+
if 'ERROR' in translated_text:
|
48 |
return translated_text, None
|
49 |
else:
|
50 |
translated_text = input_text
|
|
|
95 |
)
|
96 |
|
97 |
iface.launch()
|
98 |
+
|