Update app.py
Browse files
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 |
-
#
|
108 |
-
|
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 |
-
#
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
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 (
|