Update app.py
Browse files
app.py
CHANGED
@@ -8,16 +8,11 @@ import asyncio
|
|
8 |
import os
|
9 |
import tempfile
|
10 |
from pathlib import Path
|
11 |
-
|
12 |
|
13 |
-
#
|
14 |
-
|
15 |
-
|
16 |
-
UPLOAD_DIR = Path(__file__).parent / "uploaded"
|
17 |
-
|
18 |
-
# Ensure directories exist
|
19 |
-
for directory in [OUTPUTS_DIR, TEMP_DIR, UPLOAD_DIR]:
|
20 |
-
directory.mkdir(exist_ok=True)
|
21 |
|
22 |
async def convert_tts(model_name, audio_file, slang_rate):
|
23 |
if audio_file is None:
|
@@ -40,9 +35,9 @@ async def convert_tts(model_name, audio_file, slang_rate):
|
|
40 |
if audio_output is None:
|
41 |
return {"error": "No audio output generated"}, None
|
42 |
|
43 |
-
# Save output to
|
44 |
output_filename = f"output_{os.urandom(4).hex()}.wav"
|
45 |
-
output_path =
|
46 |
|
47 |
try:
|
48 |
if isinstance(audio_output, np.ndarray):
|
@@ -72,7 +67,7 @@ iface = gr.Interface(
|
|
72 |
fn=convert_tts,
|
73 |
inputs=[
|
74 |
gr.Dropdown(choices=get_models(), label="Model", interactive=True),
|
75 |
-
gr.Audio(label="Upload Audio", type="filepath"),
|
76 |
gr.Slider(minimum=0, maximum=1, step=0.01, label="Slang Rate"),
|
77 |
],
|
78 |
outputs=[
|
@@ -90,5 +85,5 @@ if __name__ == "__main__":
|
|
90 |
debug=True,
|
91 |
show_error=True,
|
92 |
max_threads=10,
|
93 |
-
share=False
|
94 |
)
|
|
|
8 |
import os
|
9 |
import tempfile
|
10 |
from pathlib import Path
|
11 |
+
import shutil
|
12 |
|
13 |
+
# Ensure upload directory exists
|
14 |
+
UPLOAD_DIR = os.path.join(os.path.dirname(__file__), "upload")
|
15 |
+
os.makedirs(UPLOAD_DIR, exist_ok=True)
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
async def convert_tts(model_name, audio_file, slang_rate):
|
18 |
if audio_file is None:
|
|
|
35 |
if audio_output is None:
|
36 |
return {"error": "No audio output generated"}, None
|
37 |
|
38 |
+
# Save output to temporary file
|
39 |
output_filename = f"output_{os.urandom(4).hex()}.wav"
|
40 |
+
output_path = os.path.join(UPLOAD_DIR, output_filename)
|
41 |
|
42 |
try:
|
43 |
if isinstance(audio_output, np.ndarray):
|
|
|
67 |
fn=convert_tts,
|
68 |
inputs=[
|
69 |
gr.Dropdown(choices=get_models(), label="Model", interactive=True),
|
70 |
+
gr.Audio(label="Upload Audio", type="filepath"),
|
71 |
gr.Slider(minimum=0, maximum=1, step=0.01, label="Slang Rate"),
|
72 |
],
|
73 |
outputs=[
|
|
|
85 |
debug=True,
|
86 |
show_error=True,
|
87 |
max_threads=10,
|
88 |
+
share=False
|
89 |
)
|