Spaces:
Runtime error
Runtime error
ryanzhangfan
commited on
Commit
•
862c154
1
Parent(s):
505f63b
add more detailed error message and fix 1099 meets rsp.ok bug
Browse files- demo/chat_frontend.py +5 -5
- demo/generation_frontend.py +5 -4
demo/chat_frontend.py
CHANGED
@@ -6,7 +6,7 @@
|
|
6 |
# Email : zhangfan@baai.ac.cn
|
7 |
# Institute : Beijing Academy of Artificial Intelligence (BAAI)
|
8 |
# Create On : 2023-12-12 18:05
|
9 |
-
# Last Modified : 2023-12-20 05:
|
10 |
# File Name : chat_frontend.py
|
11 |
# Description :
|
12 |
#
|
@@ -102,7 +102,6 @@ def generate(
|
|
102 |
|
103 |
t0 = time.time()
|
104 |
try:
|
105 |
-
print(do_sample)
|
106 |
rsp = requests.post(
|
107 |
CONTROLLER_URL + "/v1/mmc",
|
108 |
files=image_list,
|
@@ -119,21 +118,22 @@ def generate(
|
|
119 |
"repetition_penalty": repetition_penalty,
|
120 |
},
|
121 |
)
|
122 |
-
except:
|
123 |
rsp = requests.Response()
|
124 |
rsp.status_code = 1099
|
|
|
125 |
t1 = time.time()
|
126 |
|
127 |
logging.info(f"{meta.log_id}: get response with status code: {rsp.status_code}, time: {(t1-t0)*1000:.3f}ms")
|
128 |
|
129 |
-
if rsp.ok:
|
130 |
content = json.loads(rsp.text)
|
131 |
if content["code"] == 0:
|
132 |
meta.append(Role.ASSISTANT, DataMeta.build(text=content["data"]))
|
133 |
else:
|
134 |
meta.append(Role.ASSISTANT, DataMeta.build(text=f"GENERATE FAILED: {content['data']}", is_error=True))
|
135 |
else:
|
136 |
-
meta.append(Role.ASSISTANT, DataMeta.build(text=f"GENERATE FAILED: http failed with code {rsp.status_code}", is_error=True))
|
137 |
|
138 |
return meta.format_chatbot(), meta
|
139 |
|
|
|
6 |
# Email : zhangfan@baai.ac.cn
|
7 |
# Institute : Beijing Academy of Artificial Intelligence (BAAI)
|
8 |
# Create On : 2023-12-12 18:05
|
9 |
+
# Last Modified : 2023-12-20 05:42
|
10 |
# File Name : chat_frontend.py
|
11 |
# Description :
|
12 |
#
|
|
|
102 |
|
103 |
t0 = time.time()
|
104 |
try:
|
|
|
105 |
rsp = requests.post(
|
106 |
CONTROLLER_URL + "/v1/mmc",
|
107 |
files=image_list,
|
|
|
118 |
"repetition_penalty": repetition_penalty,
|
119 |
},
|
120 |
)
|
121 |
+
except Exception as ex:
|
122 |
rsp = requests.Response()
|
123 |
rsp.status_code = 1099
|
124 |
+
rsp._content = str(ex).encode()
|
125 |
t1 = time.time()
|
126 |
|
127 |
logging.info(f"{meta.log_id}: get response with status code: {rsp.status_code}, time: {(t1-t0)*1000:.3f}ms")
|
128 |
|
129 |
+
if rsp.status_code == requests.codes.ok:
|
130 |
content = json.loads(rsp.text)
|
131 |
if content["code"] == 0:
|
132 |
meta.append(Role.ASSISTANT, DataMeta.build(text=content["data"]))
|
133 |
else:
|
134 |
meta.append(Role.ASSISTANT, DataMeta.build(text=f"GENERATE FAILED: {content['data']}", is_error=True))
|
135 |
else:
|
136 |
+
meta.append(Role.ASSISTANT, DataMeta.build(text=f"GENERATE FAILED: http failed with code {rsp.status_code}, msg: {rsp.text}", is_error=True))
|
137 |
|
138 |
return meta.format_chatbot(), meta
|
139 |
|
demo/generation_frontend.py
CHANGED
@@ -6,7 +6,7 @@
|
|
6 |
# Email : zhangfan@baai.ac.cn
|
7 |
# Institute : Beijing Academy of Artificial Intelligence (BAAI)
|
8 |
# Create On : 2023-12-11 15:35
|
9 |
-
# Last Modified : 2023-12-20 05:
|
10 |
# File Name : generation_frontend.py
|
11 |
# Description :
|
12 |
#
|
@@ -107,14 +107,15 @@ def generate(meta, classifier_free_guidance, steps):
|
|
107 |
"steps": steps,
|
108 |
},
|
109 |
)
|
110 |
-
except:
|
111 |
rsp = requests.Response()
|
112 |
rsp.status_code = 1099
|
|
|
113 |
t1 = time.time()
|
114 |
|
115 |
logging.info(f"{meta.log_id}: get response with status code: {rsp.status_code}, time: {(t1-t0)*1000:.3f}ms")
|
116 |
|
117 |
-
if rsp.ok:
|
118 |
content = json.loads(rsp.text)
|
119 |
if content["code"] == 0:
|
120 |
image = Image.open(io.BytesIO(base64.b64decode(content["data"])))
|
@@ -122,7 +123,7 @@ def generate(meta, classifier_free_guidance, steps):
|
|
122 |
else:
|
123 |
meta.append(Role.ASSISTANT, DataMeta.build(text=f"GENERATE FAILED: {content['data']}", is_error=True))
|
124 |
else:
|
125 |
-
meta.append(Role.ASSISTANT, DataMeta.build(text=f"GENERATE FAILED: http failed with code {rsp.status_code}", is_error=True))
|
126 |
|
127 |
return meta.format_chatbot(), meta
|
128 |
|
|
|
6 |
# Email : zhangfan@baai.ac.cn
|
7 |
# Institute : Beijing Academy of Artificial Intelligence (BAAI)
|
8 |
# Create On : 2023-12-11 15:35
|
9 |
+
# Last Modified : 2023-12-20 05:43
|
10 |
# File Name : generation_frontend.py
|
11 |
# Description :
|
12 |
#
|
|
|
107 |
"steps": steps,
|
108 |
},
|
109 |
)
|
110 |
+
except Exception as ex:
|
111 |
rsp = requests.Response()
|
112 |
rsp.status_code = 1099
|
113 |
+
rsp._content = str(ex).encode()
|
114 |
t1 = time.time()
|
115 |
|
116 |
logging.info(f"{meta.log_id}: get response with status code: {rsp.status_code}, time: {(t1-t0)*1000:.3f}ms")
|
117 |
|
118 |
+
if rsp.status_code == requests.codes.ok:
|
119 |
content = json.loads(rsp.text)
|
120 |
if content["code"] == 0:
|
121 |
image = Image.open(io.BytesIO(base64.b64decode(content["data"])))
|
|
|
123 |
else:
|
124 |
meta.append(Role.ASSISTANT, DataMeta.build(text=f"GENERATE FAILED: {content['data']}", is_error=True))
|
125 |
else:
|
126 |
+
meta.append(Role.ASSISTANT, DataMeta.build(text=f"GENERATE FAILED: http failed with code {rsp.status_code}, msg: {rsp.text}", is_error=True))
|
127 |
|
128 |
return meta.format_chatbot(), meta
|
129 |
|