Pendrokar commited on
Commit
dcbacca
β€’
1 Parent(s): d1ae927

xVASynth synthesize return JSON

Browse files
app.py CHANGED
@@ -200,11 +200,16 @@ def predict(
200
  response.raise_for_status() # If the response contains an HTTP error status code, raise an exception
201
  except requests.exceptions.RequestException as err:
202
  print('Failed to synthesize!')
 
 
 
 
 
203
  print('server.log contents:')
204
  with open('resources/app/server.log', 'r') as f:
205
  print(f.read())
206
 
207
- return save_path
208
 
209
  input_textbox = gr.Textbox(
210
  label="Input Text",
@@ -259,7 +264,10 @@ gradio_app = gr.Interface(
259
  sad_slider,
260
  surprise_slider
261
  ],
262
- outputs=gr.Audio(label="22kHz audio output", type="filepath"),
 
 
 
263
  title="xVASynth (WIP)",
264
  clear_btn=gr.Button(visible=False)
265
  # examples=[
 
200
  response.raise_for_status() # If the response contains an HTTP error status code, raise an exception
201
  except requests.exceptions.RequestException as err:
202
  print('Failed to synthesize!')
203
+ print('server.log contents:')
204
+ with open('resources/app/server.log', 'r') as f:
205
+ print(f.read())
206
+ return ['', err]
207
+
208
  print('server.log contents:')
209
  with open('resources/app/server.log', 'r') as f:
210
  print(f.read())
211
 
212
+ return [save_path, response]
213
 
214
  input_textbox = gr.Textbox(
215
  label="Input Text",
 
264
  sad_slider,
265
  surprise_slider
266
  ],
267
+ outputs=[
268
+ gr.Audio(label="22kHz audio output", type="filepath"),
269
+ "text"
270
+ ],
271
  title="xVASynth (WIP)",
272
  clear_btn=gr.Button(visible=False)
273
  # examples=[
resources/app/python/xvapitch/model.py CHANGED
@@ -753,17 +753,19 @@ class xVAPitch(object):
753
  em_sad_pred.squeeze().cpu().detach().numpy() if em_sad_pred is not None else [],
754
  em_surprise_pred.squeeze().cpu().detach().numpy() if em_surprise_pred is not None else [],
755
  ]
756
- editor_values_text = ",".join([str(v) for v in pitch]) + "\n" + \
757
- ",".join([str(v) for v in durations]) + "\n" + \
758
- ",".join([str(v) for v in energy]) + "\n" + \
759
- ",".join([str(v) for v in em_angry]) + "\n" + \
760
- ",".join([str(v) for v in em_happy]) + "\n" + \
761
- ",".join([str(v) for v in em_sad]) + "\n" + \
762
- ",".join([str(v) for v in em_surprise]) + "\n" + \
763
- json.dumps(editorStyles)
764
-
765
- del pitch_pred, dur_pred, energy_pred, em_angry, em_happy, em_sad, em_surprise, text, sequence
766
- return editor_values_text +"\n"+all_cleaned_text +"\n"+ f'{start_index}\n{end_index}'
 
 
767
 
768
  def set_device (self, device):
769
  self.device = device
 
753
  em_sad_pred.squeeze().cpu().detach().numpy() if em_sad_pred is not None else [],
754
  em_surprise_pred.squeeze().cpu().detach().numpy() if em_surprise_pred is not None else [],
755
  ]
756
+
757
+ del pitch_pred, dur_pred, energy_pred, text, sequence
758
+ return {
759
+ "pitch": pitch,
760
+ "durations": durations,
761
+ "energy": energy,
762
+ "em_angry": em_angry,
763
+ "em_happy": em_happy,
764
+ "em_sad": em_sad,
765
+ "em_surprise": em_surprise,
766
+ "editorStyles": json.dumps(editorStyles),
767
+ "arpabet": all_cleaned_text
768
+ }
769
 
770
  def set_device (self, device):
771
  self.device = device
resources/app/server.py CHANGED
@@ -131,7 +131,7 @@ if __name__ == '__main__':
131
  class Handler(BaseHTTPRequestHandler):
132
  def _set_response(self):
133
  self.send_response(200)
134
- self.send_header("Content-Type", "text/html")
135
  self.end_headers()
136
 
137
  def do_GET(self):
 
131
  class Handler(BaseHTTPRequestHandler):
132
  def _set_response(self):
133
  self.send_response(200)
134
+ self.send_header("Content-Type", "application/json")
135
  self.end_headers()
136
 
137
  def do_GET(self):