Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,15 @@ import os
|
|
| 5 |
import time
|
| 6 |
import soundfile as sf
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
# Define the list of target languages
|
| 9 |
languages = {
|
| 10 |
"English": "eng",
|
|
@@ -14,15 +23,33 @@ languages = {
|
|
| 14 |
"Spanish": "spa"
|
| 15 |
}
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
def speech_to_text(audio_data, tgt_lang):
|
| 18 |
-
|
|
|
|
| 19 |
s2t_model = torch.jit.load("unity_on_device_s2t.ptl")
|
| 20 |
with torch.no_grad():
|
| 21 |
text = s2t_model(audio_input, tgt_lang=languages[tgt_lang])
|
| 22 |
return text
|
| 23 |
|
| 24 |
def speech_to_speech_translation(audio_data, tgt_lang):
|
| 25 |
-
|
|
|
|
| 26 |
s2st_model = torch.jit.load("unity_on_device.ptl")
|
| 27 |
with torch.no_grad():
|
| 28 |
text, units, waveform = s2st_model(audio_input, tgt_lang=languages[tgt_lang])
|
|
@@ -31,6 +58,7 @@ def speech_to_speech_translation(audio_data, tgt_lang):
|
|
| 31 |
return text, output_file
|
| 32 |
|
| 33 |
def create_interface():
|
|
|
|
| 34 |
with gr.Blocks(theme='ParityError/Anime') as interface:
|
| 35 |
# Dropdown for language selection
|
| 36 |
input_language = gr.Dropdown(list(languages.keys()), label="Select Target Language", value="English")
|
|
|
|
| 5 |
import time
|
| 6 |
import soundfile as sf
|
| 7 |
|
| 8 |
+
welcome_message = """
|
| 9 |
+
# 👋🏻Welcome to 🔥Tonic's🗣️Unity On Device!🚀
|
| 10 |
+
|
| 11 |
+
🔥Tonic's🗣️Unity On Device!🚀 uses [facebook/seamless-m4t-unity-small](https://huggingface.co/facebook/seamless-m4t-unity-small) for audio translation & accessibility.
|
| 12 |
+
🔥Tonic's🗣️Unity On Device!🚀 on your own data & in your own way by cloning this space. 🧬🔬🔍 Simply click here: <a style="display:inline-block" href="https://huggingface.co/spaces/TeamTonic/SeamlessOnDevice?duplicate=true"><img src="https://img.shields.io/badge/-Duplicate%20Space-blue?labelColor=white&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAP5JREFUOE+lk7FqAkEURY+ltunEgFXS2sZGIbXfEPdLlnxJyDdYB62sbbUKpLbVNhyYFzbrrA74YJlh9r079973psed0cvUD4A+4HoCjsA85X0Dfn/RBLBgBDxnQPfAEJgBY+A9gALA4tcbamSzS4xq4FOQAJgCDwV2CPKV8tZAJcAjMMkUe1vX+U+SMhfAJEHasQIWmXNN3abzDwHUrgcRGmYcgKe0bxrblHEB4E/pndMazNpSZGcsZdBlYJcEL9Afo75molJyM2FxmPgmgPqlWNLGfwZGG6UiyEvLzHYDmoPkDDiNm9JR9uboiONcBXrpY1qmgs21x1QwyZcpvxt9NS09PlsPAAAAAElFTkSuQmCC&logoWidth=14" alt="Duplicate Space"></a></h3>
|
| 13 |
+
### Join us :
|
| 14 |
+
🌟TeamTonic🌟 is always making cool demos! Join our active builder's🛠️community on 👻Discord: [Discord](https://discord.gg/GWpVpekp) On 🤗Huggingface: [TeamTonic](https://huggingface.co/TeamTonic) & [MultiTransformer](https://huggingface.co/MultiTransformer) On 🌐Github: [Polytonic](https://github.com/tonic-ai) & contribute to 🌟 [PolyGPT](https://github.com/tonic-ai/polygpt-alpha)"
|
| 15 |
+
"""
|
| 16 |
+
|
| 17 |
# Define the list of target languages
|
| 18 |
languages = {
|
| 19 |
"English": "eng",
|
|
|
|
| 23 |
"Spanish": "spa"
|
| 24 |
}
|
| 25 |
|
| 26 |
+
def save_audio(audio_input, output_dir="saved_audio"):
|
| 27 |
+
if not os.path.exists(output_dir):
|
| 28 |
+
os.makedirs(output_dir)
|
| 29 |
+
|
| 30 |
+
# Extract sample rate and audio data
|
| 31 |
+
sample_rate, audio_data = audio_input
|
| 32 |
+
|
| 33 |
+
# Generate a unique file name
|
| 34 |
+
file_name = f"audio_{int(time.time())}.wav"
|
| 35 |
+
file_path = os.path.join(output_dir, file_name)
|
| 36 |
+
|
| 37 |
+
# Save the audio file
|
| 38 |
+
sf.write(file_path, audio_data, sample_rate)
|
| 39 |
+
|
| 40 |
+
return file_path
|
| 41 |
+
|
| 42 |
def speech_to_text(audio_data, tgt_lang):
|
| 43 |
+
file_path = save_audio(audio_data)
|
| 44 |
+
audio_input, _ = torchaudio.load(file_path)
|
| 45 |
s2t_model = torch.jit.load("unity_on_device_s2t.ptl")
|
| 46 |
with torch.no_grad():
|
| 47 |
text = s2t_model(audio_input, tgt_lang=languages[tgt_lang])
|
| 48 |
return text
|
| 49 |
|
| 50 |
def speech_to_speech_translation(audio_data, tgt_lang):
|
| 51 |
+
file_path = save_audio(audio_data)
|
| 52 |
+
audio_input, _ = torchaudio.load(file_path)
|
| 53 |
s2st_model = torch.jit.load("unity_on_device.ptl")
|
| 54 |
with torch.no_grad():
|
| 55 |
text, units, waveform = s2st_model(audio_input, tgt_lang=languages[tgt_lang])
|
|
|
|
| 58 |
return text, output_file
|
| 59 |
|
| 60 |
def create_interface():
|
| 61 |
+
with gr.Markdown(welcome_message)
|
| 62 |
with gr.Blocks(theme='ParityError/Anime') as interface:
|
| 63 |
# Dropdown for language selection
|
| 64 |
input_language = gr.Dropdown(list(languages.keys()), label="Select Target Language", value="English")
|