Pendrokar commited on
Commit
2ddb634
β€’
1 Parent(s): 222e3bd
Files changed (1) hide show
  1. app.py +56 -27
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
- try:
7
- # start the process without waiting for a response
8
- Popen(['python', 'server.py'], stdout=PIPE, stderr=PIPE)
9
- except:
10
- import logging
11
- logging.error(f'Could not run xVASynth.')
12
- sys.exit(0)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
- 'modelType': model_type,
26
- 'sequence': line,
27
- 'pace': pace,
28
- 'outfile': save_path,
29
- 'vocoder': 'n/a',
30
- 'base_lang': language,
31
- 'base_emb': base_speaker_emb,
32
- 'useSR': use_sr,
33
- 'useCleanup': use_cleanup,
34
  }
35
- requests.post('http://localhost:8008/synthesize', json=data)
36
  return 22100, os.open(save_path, "rb")
37
 
38
  input_textbox = gr.Textbox(
39
- label="Input Text",
40
- lines=1,
41
- autofocus=True
42
  )
43
  slider = gr.Slider(0.0, 2.0, value=1.0, step=0.1, label="Pacing")
44
 
45
  gradio_app = gr.Interface(
46
- predict,
47
- [
48
- input_textbox,
49
- slider
50
  ],
51
- outputs= "audio",
52
- title="xVASynth",
53
  )
54
 
 
55
  if __name__ == "__main__":
56
- gradio_app.launch()
 
 
 
 
 
 
 
 
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()