Skip to content

Commit 254651d

Browse files
authored
fix: Update for --files instead of --input, make accept option with default application/json
1 parent dd7c6ee commit 254651d

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

api/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,12 @@ def main():
268268
logger.debug("Calling method with args: %s", args)
269269
del vars(args)["method"]
270270
if hasattr(args, "files"):
271-
file_extension = os.path.splitext(args.input)[1]
271+
file_extension = os.path.splitext(args.files)[1]
272272
args.files = UploadedFile(
273-
"input",
273+
"files",
274274
args.files,
275275
"application/octet-stream",
276-
f"input{file_extension}",
276+
f"files{file_extension}",
277277
)
278278
results = method_function(**vars(args))
279279
print(json.dumps(results))
@@ -322,7 +322,7 @@ def main():
322322
--data /srv/football-players-detection-7/data.yaml\
323323
--Enable_MLFLOW --epochs 50
324324
325-
python3 api/__init__.py predict --input \
325+
python3 api/__init__.py predict --files \
326326
/srv/yolov8_api/tests/data/det/test/cat1.jpg\
327327
--task_type det --accept application/json
328328
"""

api/schemas.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class Meta:
9797
"description": "image size as scalar or (h, w) list,"
9898
" i.e. (640, 480)"
9999
},
100+
load_default=[640,480]
100101
)
101102

102103
conf = fields.Float(
@@ -153,7 +154,8 @@ class Meta:
153154
"description": "Return format for method response.",
154155
"location": "headers",
155156
},
156-
required=True,
157+
required=False,
158+
load_default="application/json",
157159
validate=validate.OneOf(responses.content_types),
158160
)
159161

yolov8_api/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def predict(
4747
print("arg of prediction are", args)
4848

4949
model = YOLO(args["model"])
50-
test_image_path = args["input"]
50+
test_image_path = args["files"]
5151
results = []
5252
for image_path in test_image_path:
5353
print(
@@ -57,7 +57,7 @@ def predict(
5757
utils.remove_keys_from_dict(
5858
args,
5959
[
60-
"input",
60+
"files",
6161
"accept",
6262
"task_type",
6363
],
@@ -73,7 +73,7 @@ def predict(
7373

7474
if __name__ == "__main__":
7575
args = {
76-
"input": ["/home/se1131/cat1.jpg"],
76+
"files": ["/home/se1131/cat1.jpg"],
7777
"model": "yolov8n.pt",
7878
"imgsz": [680, 512],
7979
"conf": 0.25,

0 commit comments

Comments
 (0)