Update app.py
Browse files6 unmodified lines7891011121390 unmodified lines10410510610710810911011111211311411512 unmodified lines1281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581596 unmodified linesimport timeAPI_URL = os.environ.get("API_URL")LEPTON_API_TOKEN = os.environ.get('LEPTON_API_TOKEN')supported_languages = ['zh', 'en']90 unmodified lines}start = time.time()# # Send the data as a POST request# response = requests.post(API_URL, json=data, timeout=60)from leptonai.client import Clientc = Client(API_URL, token=LEPTON_API_TOKEN)response = c.run(**data)print(f'Get response successfully within {time.time() - start}')12 unmodified lineswith open(save_path, 'wb') as f:f.write(response)# # Check the response# if response.status_code == 200:# try:# json_data = json.loads(response.content)# text_hint += f"[ERROR] {json_data['error']} \n"# gr.Warning(# f"[ERROR] {json_data['error']} \n"# )# return (# text_hint,# None,# None,# )# except:# with open(save_path, 'wb') as f:# f.write(response.content)# else:# text_hint += f"[HTTP ERROR] {response.status_code} - {response.text} \n"# gr.Warning(# f"[HTTP ERROR] {response.status_code} - {response.text} \n"# )# return (# text_hint,# None,# None,# )text_hint += f'''Get response successfully \n'''return (6 unmodified lines78910111290 unmodified lines10310410510610710810911012 unmodified lines1231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531546 unmodified linesimport timeAPI_URL = os.environ.get("API_URL")supported_languages = ['zh', 'en']90 unmodified lines}start = time.time()# Send the data as a POST requestresponse = requests.post(API_URL, json=data, timeout=60)print(f'Get response successfully within {time.time() - start}')12 unmodified lineswith open(save_path, 'wb') as f:f.write(response)# Check the responseif response.status_code == 200:try:json_data = json.loads(response.content)text_hint += f"[ERROR] {json_data['error']} \n"gr.Warning(f"[ERROR] {json_data['error']} \n")return (text_hint,None,None,)except:with open(save_path, 'wb') as f:f.write(response.content)else:text_hint += f"[HTTP ERROR] {response.status_code} - {response.text} \n"gr.Warning(f"[HTTP ERROR] {response.status_code} - {response.text} \n")return (text_hint,None,None,)text_hint += f'''Get response successfully \n'''return (
app.py+28-33