Spaces:
Sleeping
Sleeping
Update api_server.py
Browse files- api_server.py +21 -16
api_server.py
CHANGED
@@ -135,6 +135,11 @@ def predict():
|
|
135 |
|
136 |
# 儲存辨識後的圖片到指定資料夾
|
137 |
for result in results:
|
|
|
|
|
|
|
|
|
|
|
138 |
# 保存圖片
|
139 |
result.save_crop(f"{YOLO_DIR}/{message_id}")
|
140 |
|
@@ -146,10 +151,6 @@ def predict():
|
|
146 |
|
147 |
element_counts = Counter(label_names)
|
148 |
|
149 |
-
encoded_images=[]
|
150 |
-
element_list =[]
|
151 |
-
top_k_words =[]
|
152 |
-
|
153 |
for element, count in element_counts.items():
|
154 |
|
155 |
yolo_path = f"{YOLO_DIR}/{message_id}/{element}"
|
@@ -157,6 +158,10 @@ def predict():
|
|
157 |
|
158 |
print(f"======YOLO result:{yolo_path}======")
|
159 |
|
|
|
|
|
|
|
|
|
160 |
element_list.append(element)
|
161 |
|
162 |
for yolo_img in yolo_file: # 每張切圖yolo_img
|
@@ -177,24 +182,24 @@ def predict():
|
|
177 |
# encoded_images.append(image_to_base64(yolo_path))
|
178 |
|
179 |
# 建立回應資料
|
180 |
-
response_data = {
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
}
|
191 |
# response_data = {
|
192 |
# 'message_id': message_id,
|
193 |
# 'images': encoded_images,
|
194 |
# 'description': element_list
|
195 |
# }
|
196 |
|
197 |
-
return jsonify(response_data)
|
198 |
|
199 |
# for label_name in label_names:
|
200 |
# yolo_file=f"{YOLO_DIR}/{message_id}/{label_name}/im.jpg.jpg"
|
|
|
135 |
|
136 |
# 儲存辨識後的圖片到指定資料夾
|
137 |
for result in results:
|
138 |
+
|
139 |
+
encoded_images=[]
|
140 |
+
element_list =[]
|
141 |
+
top_k_words =[]
|
142 |
+
|
143 |
# 保存圖片
|
144 |
result.save_crop(f"{YOLO_DIR}/{message_id}")
|
145 |
|
|
|
151 |
|
152 |
element_counts = Counter(label_names)
|
153 |
|
|
|
|
|
|
|
|
|
154 |
for element, count in element_counts.items():
|
155 |
|
156 |
yolo_path = f"{YOLO_DIR}/{message_id}/{element}"
|
|
|
158 |
|
159 |
print(f"======YOLO result:{yolo_path}======")
|
160 |
|
161 |
+
if len(yolo_file) == 0:
|
162 |
+
print(f"警告:{element} 沒有找到相關的 JPG 檔案")
|
163 |
+
continue
|
164 |
+
|
165 |
element_list.append(element)
|
166 |
|
167 |
for yolo_img in yolo_file: # 每張切圖yolo_img
|
|
|
182 |
# encoded_images.append(image_to_base64(yolo_path))
|
183 |
|
184 |
# 建立回應資料
|
185 |
+
# response_data = {
|
186 |
+
# 'message_id': message_id,
|
187 |
+
# 'description': element_list,
|
188 |
+
# 'images': [
|
189 |
+
# {
|
190 |
+
# 'encoded_image': encoded_image,
|
191 |
+
# 'description_list': top_k_words
|
192 |
+
# }
|
193 |
+
# for encoded_image, elements in zip(encoded_images, element_list)
|
194 |
+
# ]
|
195 |
+
# }
|
196 |
# response_data = {
|
197 |
# 'message_id': message_id,
|
198 |
# 'images': encoded_images,
|
199 |
# 'description': element_list
|
200 |
# }
|
201 |
|
202 |
+
return top_k_words#jsonify(response_data)
|
203 |
|
204 |
# for label_name in label_names:
|
205 |
# yolo_file=f"{YOLO_DIR}/{message_id}/{label_name}/im.jpg.jpg"
|