Varosa commited on
Commit
7576f76
1 Parent(s): 400a5aa

create app file

Browse files
Files changed (1) hide show
  1. app.py +64 -0
app.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import io
2
+ import os
3
+ import json
4
+ import subprocess
5
+ import mmap
6
+ import numpy
7
+ import soundfile
8
+ import torchaudio
9
+ import torch
10
+ import gradio as gr
11
+ from collections import defaultdict
12
+ from pathlib import Path
13
+ from pydub import AudioSegment
14
+ from seamless_communication.inference import Translator
15
+ from seamless_communication.streaming.dataloaders.s2tt import SileroVADSilenceRemover
16
+
17
+
18
+ # Mapping of language names to their respective codes
19
+ language_codes = {
20
+ "English": "eng",
21
+ "Spanish": "spa",
22
+ "French": "fra",
23
+ "German": "deu",
24
+ "Italian": "ita",
25
+ "Chinese": "cmn"
26
+ }
27
+
28
+ # Function to handle the translation
29
+ def translate_audio(audio_file, target_language):
30
+ language_code = language_codes[target_language]
31
+ output_file = "translated_audio.wav"
32
+
33
+ command = f"expressivity_predict {audio_file} --tgt_lang {language_code} \
34
+ --model_name seamless_expressivity --vocoder_name vocoder_pretssel \
35
+ --gated-model-dir seamlessmodel --output_path {output_file}"
36
+ subprocess.run(command, shell=True)
37
+
38
+ if os.path.exists(output_file):
39
+ print(f"File created successfully: {output_file}")
40
+ else:
41
+ print(f"File not found: {output_file}")
42
+
43
+ return output_file
44
+
45
+
46
+ # Define inputs
47
+ inputs = [
48
+ gr.Audio(type = "filepath", label = "Audio_file"),
49
+ gr.Dropdown(["English", "Spanish", "French", "German", "Italian", "Chinese"], label = "Target_Language")
50
+ ]
51
+
52
+
53
+ # Create Gradio interface
54
+ iface = gr.Interface(
55
+ fn=translate_audio,
56
+ inputs= inputs,
57
+ outputs=gr.Audio(label="Translated Audio"),
58
+ title="Seamless Expressive Audio Translator",
59
+ description="Translate your audio into different languages with expressive styles."
60
+ )
61
+
62
+ # Run the application
63
+ if __name__ == "__main__":
64
+ iface.launch()