Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,8 @@ import json
|
|
7 |
import time
|
8 |
|
9 |
API_URL = os.environ.get("API_URL")
|
|
|
|
|
10 |
supported_languages = ['zh', 'en']
|
11 |
|
12 |
output_dir = 'outputs'
|
@@ -102,36 +104,57 @@ def predict(prompt, style, audio_file_pth, agree):
|
|
102 |
}
|
103 |
|
104 |
start = time.time()
|
105 |
-
# Send the data as a POST request
|
106 |
-
response = requests.post(API_URL, json=data, timeout=60)
|
|
|
|
|
|
|
|
|
|
|
107 |
print(f'Get response successfully within {time.time() - start}')
|
108 |
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
json_data = json.loads(response.content)
|
113 |
-
text_hint += f"[ERROR] {json_data['error']} \n"
|
114 |
-
gr.Warning(
|
115 |
-
f"[ERROR] {json_data['error']} \n"
|
116 |
-
)
|
117 |
-
return (
|
118 |
-
text_hint,
|
119 |
-
None,
|
120 |
-
None,
|
121 |
-
)
|
122 |
-
except:
|
123 |
-
with open(save_path, 'wb') as f:
|
124 |
-
f.write(response.content)
|
125 |
-
else:
|
126 |
-
text_hint += f"[HTTP ERROR] {response.status_code} - {response.text} \n"
|
127 |
gr.Warning(
|
128 |
-
f"[
|
129 |
)
|
130 |
return (
|
131 |
text_hint,
|
132 |
None,
|
133 |
None,
|
134 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
text_hint += f'''Get response successfully \n'''
|
136 |
return (
|
137 |
text_hint,
|
|
|
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 |
|
14 |
output_dir = 'outputs'
|
|
|
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 |
|
116 |
+
try:
|
117 |
+
json_data = json.loads(response)
|
118 |
+
text_hint += f"[ERROR] {json_data['error']} \n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
gr.Warning(
|
120 |
+
f"[ERROR] {json_data['error']} \n"
|
121 |
)
|
122 |
return (
|
123 |
text_hint,
|
124 |
None,
|
125 |
None,
|
126 |
)
|
127 |
+
except:
|
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 (
|
160 |
text_hint,
|