Spaces:
Sleeping
Sleeping
Update api_server.py
Browse files- api_server.py +19 -19
api_server.py
CHANGED
|
@@ -176,7 +176,7 @@ def predict():
|
|
| 176 |
api_name="/predict"
|
| 177 |
)
|
| 178 |
top_k_words.append(clip_result) # CLIP預測3個結果(top_k_words)
|
| 179 |
-
|
| 180 |
print(f"===== CLIP result:{top_k_words} =====\n")
|
| 181 |
|
| 182 |
# if element_counts[element] > 1: #某隻角色的數量>1
|
|
@@ -190,25 +190,25 @@ def predict():
|
|
| 190 |
# yolo_path = f"{YOLO_DIR}/{message_id}/{element}/im.jpg.jpg"
|
| 191 |
# encoded_images.append(image_to_base64(yolo_path))
|
| 192 |
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
|
| 211 |
-
return jsonify(
|
| 212 |
|
| 213 |
# for label_name in label_names:
|
| 214 |
# yolo_file=f"{YOLO_DIR}/{message_id}/{label_name}/im.jpg.jpg"
|
|
|
|
| 176 |
api_name="/predict"
|
| 177 |
)
|
| 178 |
top_k_words.append(clip_result) # CLIP預測3個結果(top_k_words)
|
| 179 |
+
encoded_images.append(image_to_base64(yolo_img))
|
| 180 |
print(f"===== CLIP result:{top_k_words} =====\n")
|
| 181 |
|
| 182 |
# if element_counts[element] > 1: #某隻角色的數量>1
|
|
|
|
| 190 |
# yolo_path = f"{YOLO_DIR}/{message_id}/{element}/im.jpg.jpg"
|
| 191 |
# encoded_images.append(image_to_base64(yolo_path))
|
| 192 |
|
| 193 |
+
# 建立回應資料
|
| 194 |
+
response_data = {
|
| 195 |
+
'message_id': message_id,
|
| 196 |
+
'objects': [
|
| 197 |
+
{
|
| 198 |
+
'element': element,
|
| 199 |
+
'images': [
|
| 200 |
+
{
|
| 201 |
+
'encoded_image': encoded_image,
|
| 202 |
+
'description_list': description_list
|
| 203 |
+
}
|
| 204 |
+
for encoded_image, description_list in zip(encoded_images, top_k_words)
|
| 205 |
+
]
|
| 206 |
+
}
|
| 207 |
+
for element, encoded_images, top_k_words in zip(element_list, encoded_images, top_k_words)
|
| 208 |
+
]
|
| 209 |
+
}
|
| 210 |
|
| 211 |
+
return jsonify(response_data), 200 #jsonify(response_data)
|
| 212 |
|
| 213 |
# for label_name in label_names:
|
| 214 |
# yolo_file=f"{YOLO_DIR}/{message_id}/{label_name}/im.jpg.jpg"
|