XuminYu commited on
Commit
451de3c
1 Parent(s): 17ed520

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -24
app.py CHANGED
@@ -112,38 +112,35 @@ def predict(prompt, style, audio_file_pth, agree):
112
  response = requests.post(API_URL, json=data, headers=headers, timeout=60)
113
  print(f'Get response successfully within {time.time() - start}')
114
 
115
- # Check the response
116
- if response.status_code == 200:
117
- try:
118
- json_data = json.loads(response.content)
119
- text_hint += f"[ERROR] {json_data['error']} \n"
 
 
 
 
 
120
  gr.Warning(
121
- f"[ERROR] {json_data['error']} \n"
122
  )
123
  return (
124
  text_hint,
125
  None,
126
  None,
127
  )
128
- except:
 
129
  with open(save_path, 'wb') as f:
130
- f.write(response.content)
131
- else:
132
- text_hint += f"[HTTP ERROR] {response.status_code} - {response.text} \n"
133
- gr.Warning(
134
- f"[HTTP ERROR] {response.status_code} - {response.text} \n"
135
- )
136
- return (
137
- text_hint,
138
- None,
139
- None,
140
- )
141
- text_hint += f'''Get response successfully \n'''
142
- return (
143
- text_hint,
144
- save_path,
145
- speaker_wav,
146
- )
147
 
148
 
149
  title = "MyShell OpenVoice"
 
112
  response = requests.post(API_URL, json=data, headers=headers, timeout=60)
113
  print(f'Get response successfully within {time.time() - start}')
114
 
115
+ task_id = response.json()['task_id']
116
+ while True:
117
+ response = requests.post(API_URL.replace('run', 'get_result'), json={'task_id': task_id}, headers=headers)
118
+ json_data = response.json()
119
+ status = json_data['status']
120
+ if status in ["CREATED", "RUNNING"]:
121
+ time.sleep(1)
122
+ continue
123
+ if status == 'FAILED':
124
+ text_hint += f"[HTTP ERROR] {json_data['error']} \n"
125
  gr.Warning(
126
+ f"[HTTP ERROR] {json_data['error']} \n"
127
  )
128
  return (
129
  text_hint,
130
  None,
131
  None,
132
  )
133
+ else:
134
+ decoded_bytes = base64.b64decode(json_data['result']['base64'])
135
  with open(save_path, 'wb') as f:
136
+ f.write(decoded_bytes)
137
+
138
+ text_hint += f'''Get response successfully \n'''
139
+ return (
140
+ text_hint,
141
+ save_path,
142
+ speaker_wav,
143
+ )
 
 
 
 
 
 
 
 
 
144
 
145
 
146
  title = "MyShell OpenVoice"