How to download CSV file with results of computer vision model prediction from Python web app?

jessyKuh087 report abuse

My computer vision model is deployed in the Django web application. It takes images as input and produces results which I want to pack into the CSV file and let the user download it. How can I do this?


FlonetTus report abuse

Is it possible to generate a Pandas dataframe from the results of the model prediction?

jessyKuh087 report abuse

Yes, I can do this.

FlonetTus report abuse

Then you need to create a Pandas dataframe first. Then, create a HttpResponse object (using Django). It is important that this object should have content_type='text/csv'. Set the Content-Disposition parameter like this:

response['Content-Disposition'] = 'attachment; filename="result.csv"'

This will make that the file that the user downloads will have the default name 'result.csv'. Then use the created HttpResponse object as the place into which Pandas should save the dataframe as CSV file:


And finally, you can return the response object from the corresponding Django view.

jessyKuh087 report abuse

This works, thank you!

Add Answer

Need support?

Just drop us an email to ... Show more