Closed energydrink9 closed 2 months ago
Hi @energydrink9, you can send multiple pieces of data along with a file upload, as shown in the following example. You can send the additional data as JSON and access it directly using the corresponding keys. To access the file, you can retrieve the filename as follows:
from PIL import Image
import litserve as ls
class ImageAPI(ls.LitAPI):
def setup(self, device):
self.model = lambda x: x.size
def decode_request(self, request):
print(request["model_name"])
return Image.open(request["request"].filename)
def predict(self, x):
return self.model(x)
def encode_response(self, output):
return {"output": output}
if __name__ == "__main__":
api = ImageAPI()
server = ls.LitServer(api)
server.run(port=8000)
import requests
url = "http://127.0.0.1:8000/predict"
image_path = "image.jpg"
# Open the image file in binary mode
with open(image_path, 'rb') as image_file:
files = {'request': image_file}
response = requests.post(url, files=files, data={"model_name": "resnet50"})
print(response.json())
Added a new section for this in the documentation here. Please let me know if it helps!
Closing the issue for now, feel free to reopen if you are still facing this issue!
Thank you Aniket, I managed to implement the parameterization following your advice
⚠️ BEFORE SUBMITTING, READ:
We're excited for your request! However, here are things we are not interested in:
🚀 Feature
Hello team,
Please correct me if I'm wrong but I couldn't find a way to specify query parameters for my endpoint when using a request annotated with FileUpload in
decode_request
. Is it possible to add support for them?Motivation
It's sometimes useful to specify additional parameters in the request in order to control inference.