Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
threading
Browse files
app.py
CHANGED
@@ -1,15 +1,36 @@
|
|
1 |
import os
|
2 |
import requests
|
3 |
from subprocess import Popen, PIPE
|
|
|
|
|
4 |
import gradio as gr
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
def predict(input, pacing):
|
15 |
model_type = 'xVAPitch'
|
@@ -22,35 +43,43 @@ def predict(input, pacing):
|
|
22 |
use_cleanup = 0
|
23 |
|
24 |
data = {
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
}
|
35 |
-
requests.post('http://
|
36 |
return 22100, os.open(save_path, "rb")
|
37 |
|
38 |
input_textbox = gr.Textbox(
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
)
|
43 |
slider = gr.Slider(0.0, 2.0, value=1.0, step=0.1, label="Pacing")
|
44 |
|
45 |
gradio_app = gr.Interface(
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
],
|
51 |
-
|
52 |
-
|
53 |
)
|
54 |
|
|
|
55 |
if __name__ == "__main__":
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
import requests
|
3 |
from subprocess import Popen, PIPE
|
4 |
+
import time
|
5 |
+
import threading
|
6 |
import gradio as gr
|
7 |
|
8 |
+
|
9 |
+
def run_xvaserver():
|
10 |
+
try:
|
11 |
+
# start the process without waiting for a response
|
12 |
+
xvaserver = Popen(['python', 'server.py'], stdout=PIPE, stderr=PIPE, universal_newlines=True)
|
13 |
+
except:
|
14 |
+
import logging
|
15 |
+
logging.error(f'Could not run xVASynth.')
|
16 |
+
sys.exit(0)
|
17 |
+
|
18 |
+
# Read and print stdout and stderr of the subprocess
|
19 |
+
while True:
|
20 |
+
output = xvaserver.stdout.readline()
|
21 |
+
if output == '' and xvaserver.poll() is not None:
|
22 |
+
break
|
23 |
+
if output:
|
24 |
+
print(output.strip())
|
25 |
+
|
26 |
+
error = xvaserver.stderr.readline()
|
27 |
+
if error == '' and xvaserver.poll() is not None:
|
28 |
+
break
|
29 |
+
if error:
|
30 |
+
print(error.strip(), file=sys.stderr)
|
31 |
+
|
32 |
+
# Wait for the process to exit
|
33 |
+
xvaserver.wait()
|
34 |
|
35 |
def predict(input, pacing):
|
36 |
model_type = 'xVAPitch'
|
|
|
43 |
use_cleanup = 0
|
44 |
|
45 |
data = {
|
46 |
+
'modelType': model_type,
|
47 |
+
'sequence': line,
|
48 |
+
'pace': pace,
|
49 |
+
'outfile': save_path,
|
50 |
+
'vocoder': 'n/a',
|
51 |
+
'base_lang': language,
|
52 |
+
'base_emb': base_speaker_emb,
|
53 |
+
'useSR': use_sr,
|
54 |
+
'useCleanup': use_cleanup,
|
55 |
}
|
56 |
+
requests.post('http://0.0.0.0:8008/synthesize', json=data)
|
57 |
return 22100, os.open(save_path, "rb")
|
58 |
|
59 |
input_textbox = gr.Textbox(
|
60 |
+
label="Input Text",
|
61 |
+
lines=1,
|
62 |
+
autofocus=True
|
63 |
)
|
64 |
slider = gr.Slider(0.0, 2.0, value=1.0, step=0.1, label="Pacing")
|
65 |
|
66 |
gradio_app = gr.Interface(
|
67 |
+
predict,
|
68 |
+
[
|
69 |
+
input_textbox,
|
70 |
+
slider
|
71 |
],
|
72 |
+
outputs= "audio",
|
73 |
+
title="xVASynth",
|
74 |
)
|
75 |
|
76 |
+
|
77 |
if __name__ == "__main__":
|
78 |
+
# Run the web server in a separate thread
|
79 |
+
web_server_thread = threading.Thread(target=run_xvaserver)
|
80 |
+
web_server_thread.start()
|
81 |
+
|
82 |
+
gradio_app.launch()
|
83 |
+
|
84 |
+
# Wait for the web server thread to finish (shouldn't be reached in normal execution)
|
85 |
+
web_server_thread.join()
|