Possible to coexist send_file() and json object in return ...
?
#5033
-
I have the following API endpoint that accepts an image to analyze and returns objects found in the image as a collection of cropped images. @api.post("/detect")
def detect() -> ResponseReturnValue:
"""Detect objects in an image and return each object as a separate image."""
# Machine learning logic
...
# Example object data
object_data: dict = {
"dog_1.jpg": {"label": "dog", "score": 0.99, "box": [0, 0, 100, 100]},
"dog_2.jpg": {"label": "dog", "score": 0.99, "box": [0, 0, 100, 100]},
"person_1.jpg": {"label": "person", "score": 0.99, "box": [0, 0, 100, 100]},
}
zip_file: Path = Path("/path/to/zipfile")
return send_file(zip_file) Currently, it only returns a zip file of the collection ( What I tried:
Environment: python = "^3.11"
flask = "^2.2.3"
torch = "^2.0.0"
torchvision = "^0.15.1"
opencv-python = "^4.7.0.72" |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
its not quite clear what you are asking for, there can only be one response, itsc currently either the json or the zip file without providing details on the intended conusmption its unclear how to do what you want |
Beta Was this translation helpful? Give feedback.
-
You can return any data you want, but you can only return one thing. You can combine multiple files into one block of data, such as by zipping them, but it's up to you to also be able to decode that again on the other side. |
Beta Was this translation helpful? Give feedback.
its not quite clear what you are asking for, there can only be one response, itsc currently either the json or the zip file
without providing details on the intended conusmption its unclear how to do what you want