Pijush2023 commited on
Commit
2ea6305
·
verified ·
1 Parent(s): 624abad

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -0
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+
3
+ import os
4
+ import sys
5
+ import pathlib
6
+ import subprocess
7
+ import gradio as gr
8
+ from fam.llm.fast_inference import TTS
9
+
10
+ # Clone the repository
11
+ if not os.path.exists("metavoice-src"):
12
+ subprocess.run(["git", "clone", "https://github.com/metavoiceio/metavoice-src.git"])
13
+ os.chdir("metavoice-src")
14
+
15
+ # Install dependencies
16
+ subprocess.run(["sudo", "apt", "install", "pipx", "-y"])
17
+ subprocess.run(["pipx", "install", "poetry"])
18
+ subprocess.run(["pipx", "run", "poetry", "install"])
19
+ subprocess.run(["pipx", "run", "poetry", "run", "pip", "install", "torch==2.2.1", "torchaudio==2.2.1"])
20
+
21
+ # Get the poetry environment path
22
+ result = subprocess.run(["pipx", "run", "poetry", "env", "list"], capture_output=True, text=True)
23
+ venv = result.stdout.split()[0]
24
+ with open("poetry_env.txt", "w") as f:
25
+ f.write(venv)
26
+
27
+ # Add the virtual environment to the system path
28
+ venv_path = pathlib.Path("poetry_env.txt").read_text().strip("\n")
29
+ sys.path.append(f"{venv_path}/lib/python3.10/site-packages")
30
+
31
+ # Initialize TTS
32
+ tts = TTS()
33
+
34
+ def text_to_speech(text):
35
+ wav_file = tts.synthesise(
36
+ text=text,
37
+ spk_ref_path="assets/bria.mp3" # Specify your speaker reference file path
38
+ )
39
+ return wav_file
40
+
41
+ # Create Gradio interface
42
+ interface = gr.Interface(
43
+ fn=text_to_speech,
44
+ inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
45
+ outputs=gr.Audio(type="numpy", label="Generated Audio"),
46
+ title="MetaVoice-1B Text to Speech",
47
+ description="Enter text to convert it into speech using the MetaVoice-1B model."
48
+ )
49
+
50
+ # Launch the Gradio interface
51
+ interface.launch(share=True)