kunalpro379 commited on
Commit
e527a2b
·
verified ·
1 Parent(s): 7d09254

app.py creation

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import subprocess
3
+ import os
4
+ import uuid
5
+
6
+ MODEL = "en_US-amy-medium.onnx"
7
+ MODEL_PATH = f"./models/en_US/{MODEL}"
8
+ CONFIG_PATH = f"./models/en_US/en_US-amy-medium.onnx.json"
9
+
10
+ # Download model from Hugging Face if not present
11
+ if not os.path.exists(MODEL_PATH):
12
+ os.makedirs("./models/en_US", exist_ok=True)
13
+ subprocess.run(["wget", "-O", MODEL_PATH,
14
+ "https://huggingface.co/rhasspy/piper-voices/resolve/main/en/en_US/amy-medium.onnx"])
15
+ subprocess.run(["wget", "-O", CONFIG_PATH,
16
+ "https://huggingface.co/rhasspy/piper-voices/resolve/main/en/en_US/en_US-amy-medium.onnx.json"])
17
+
18
+ def tts_piper(text):
19
+ output_file = f"output_{uuid.uuid4().hex}.wav"
20
+ command = [
21
+ "piper",
22
+ "--model", MODEL_PATH,
23
+ "--config", CONFIG_PATH,
24
+ "--output_file", output_file,
25
+ "--text", text
26
+ ]
27
+ subprocess.run(command)
28
+ return output_file
29
+
30
+ demo = gr.Interface(fn=tts_piper, inputs="text", outputs="audio", title="Piper TTS - Hugging Face Demo")
31
+ demo.launch()