How to create a Post request with streamlit

I have a image processing script that converts video’s to frame and I want to turn it to a web service where user uploads a video then the system converts the video to frame and saves to a folder.

Is it possible to create a post request that takes a video from a user calls an endpoint which in turn processes the video and sends a response back to the user.

I am kind of familiar DL and ML and I have little knowledge of restful api

Can I do this with streamlit…??

Hi @chukypedro,

you mention several points here.

1. File_uploader
Streamlit offers a component for file uploading including video files (I belief):

import streamlit as st
import cv2 as cv
import tempfile

--> f = st.file_uploader("Upload file") <--
tfile = tempfile.NamedTemporaryFile(delete=False)
tfile.write(f.read())
vf = cv.VideoCapture(tfile.name)

2. Requests in python
You can than send a request to the API using:

import requests
url = 'https://www.w3schools.com/python/demopage.php'
myobj = {'somekey': 'somevalue'}
x = requests.post(url, data = myobj)
print(x.text)

3. API
Finally, you can implement an API with:


and smoothly process and return the data.

In case you are using streamlit sharing, you might not need to send the data somewhere to store files.
I have a similar question posted a few minutes ago:

Hope that helps you :slightly_smiling_face:have a nice day.
Cheers
Chris

1 Like

Yes, you could do something like this, but it doesn’t necessarily have to be “in Streamlit”, since you have the full power of Python available as well. @chris_klose points out some thoughts, and it really is a matter of thinking through the pipeline you want and doing it.

Streamlit sharing isn’t going to provide you with a lot of RAM and disk space, so it might not be the best solution for this. But I can envision an app that calls out to Amazon S3 or Google Drive to post the modified video and returns a link to where someone can download it.

Best,
Randy