XuminYu commited on
Commit
25893d0
1 Parent(s): 0011011

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -33
app.py CHANGED
@@ -7,7 +7,6 @@ import json
7
  import time
8
 
9
  API_URL = os.environ.get("API_URL")
10
- LEPTON_API_TOKEN = os.environ.get('LEPTON_API_TOKEN')
11
 
12
  supported_languages = ['zh', 'en']
13
 
@@ -104,12 +103,8 @@ def predict(prompt, style, audio_file_pth, agree):
104
  }
105
 
106
  start = time.time()
107
- # # Send the data as a POST request
108
- # response = requests.post(API_URL, json=data, timeout=60)
109
-
110
- from leptonai.client import Client
111
- c = Client(API_URL, token=LEPTON_API_TOKEN)
112
- response = c.run(**data)
113
 
114
  print(f'Get response successfully within {time.time() - start}')
115
 
@@ -128,32 +123,32 @@ def predict(prompt, style, audio_file_pth, agree):
128
  with open(save_path, 'wb') as f:
129
  f.write(response)
130
 
131
- # # Check the response
132
- # if response.status_code == 200:
133
- # try:
134
- # json_data = json.loads(response.content)
135
- # text_hint += f"[ERROR] {json_data['error']} \n"
136
- # gr.Warning(
137
- # f"[ERROR] {json_data['error']} \n"
138
- # )
139
- # return (
140
- # text_hint,
141
- # None,
142
- # None,
143
- # )
144
- # except:
145
- # with open(save_path, 'wb') as f:
146
- # f.write(response.content)
147
- # else:
148
- # text_hint += f"[HTTP ERROR] {response.status_code} - {response.text} \n"
149
- # gr.Warning(
150
- # f"[HTTP ERROR] {response.status_code} - {response.text} \n"
151
- # )
152
- # return (
153
- # text_hint,
154
- # None,
155
- # None,
156
- # )
157
 
158
  text_hint += f'''Get response successfully \n'''
159
  return (
 
7
  import time
8
 
9
  API_URL = os.environ.get("API_URL")
 
10
 
11
  supported_languages = ['zh', 'en']
12
 
 
103
  }
104
 
105
  start = time.time()
106
+ # Send the data as a POST request
107
+ response = requests.post(API_URL, json=data, timeout=60)
 
 
 
 
108
 
109
  print(f'Get response successfully within {time.time() - start}')
110
 
 
123
  with open(save_path, 'wb') as f:
124
  f.write(response)
125
 
126
+ # Check the response
127
+ if response.status_code == 200:
128
+ try:
129
+ json_data = json.loads(response.content)
130
+ text_hint += f"[ERROR] {json_data['error']} \n"
131
+ gr.Warning(
132
+ f"[ERROR] {json_data['error']} \n"
133
+ )
134
+ return (
135
+ text_hint,
136
+ None,
137
+ None,
138
+ )
139
+ except:
140
+ with open(save_path, 'wb') as f:
141
+ f.write(response.content)
142
+ else:
143
+ text_hint += f"[HTTP ERROR] {response.status_code} - {response.text} \n"
144
+ gr.Warning(
145
+ f"[HTTP ERROR] {response.status_code} - {response.text} \n"
146
+ )
147
+ return (
148
+ text_hint,
149
+ None,
150
+ None,
151
+ )
152
 
153
  text_hint += f'''Get response successfully \n'''
154
  return (