Spaces:
Sleeping
Sleeping
Update api_server.py
Browse files- api_server.py +7 -5
api_server.py
CHANGED
@@ -17,7 +17,8 @@ import torch
|
|
17 |
load_type = 'local'
|
18 |
|
19 |
MODEL_NAME = "yolo11_detect_best_241018_1.pt"
|
20 |
-
MODEL_DIR = "./artifacts/models"
|
|
|
21 |
#REPO_ID = "1vash/mnist_demo_model"
|
22 |
|
23 |
# Load the saved YOLO model into memory
|
@@ -73,12 +74,13 @@ def predict():
|
|
73 |
# 準備返回多張圖像
|
74 |
images_io = []
|
75 |
|
76 |
-
|
|
|
77 |
img_io = io.BytesIO()
|
78 |
-
|
|
|
79 |
img_io.seek(0)
|
80 |
-
images_io.append((f'image_{i}.png', img_io)) #
|
81 |
-
send_file(img_io, mimetype='image/png')
|
82 |
|
83 |
# 打包多張圖像為 ZIP 文件進行返回
|
84 |
zip_io = io.BytesIO()
|
|
|
17 |
load_type = 'local'
|
18 |
|
19 |
MODEL_NAME = "yolo11_detect_best_241018_1.pt"
|
20 |
+
MODEL_DIR = "./artifacts/models".
|
21 |
+
YOLO_DIR = "./artifacts/yolo"
|
22 |
#REPO_ID = "1vash/mnist_demo_model"
|
23 |
|
24 |
# Load the saved YOLO model into memory
|
|
|
74 |
# 準備返回多張圖像
|
75 |
images_io = []
|
76 |
|
77 |
+
# YOLOv5/YOLOv8 results have a .ims attribute that contains the rendered images
|
78 |
+
for i, img in enumerate(results.ims): # Assuming `ims` contains the rendered images
|
79 |
img_io = io.BytesIO()
|
80 |
+
img = Image.fromarray(img) # Convert numpy array back to PIL image if necessary
|
81 |
+
img.save(img_io, 'PNG') # Save YOLO-processed image to buffer
|
82 |
img_io.seek(0)
|
83 |
+
images_io.append((f'image_{i}.png', img_io)) # Store each image with its filename
|
|
|
84 |
|
85 |
# 打包多張圖像為 ZIP 文件進行返回
|
86 |
zip_io = io.BytesIO()
|