New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
can't read an image uploaded with st.file_uploader() #884
Comments
The return type of file_uploader is |
Edit - just noticed this thread with solution https://discuss.streamlit.io/t/png-bytes-io-numpy-conversion-using-file-uploader/1409/2 Suggested example for the docs: import streamlit as st
from PIL import Image
import numpy as np
img_file_buffer = st.file_uploader("Upload an image", type=["png", "jpg", "jpeg"])
image = Image.open(img_file_buffer)
img_array = np.array(image)
if image is not None:
st.image(
image,
caption=f"You amazing image has shape {img_array.shape[0:2]}",
use_column_width=True,
) |
Dear @robmarkcole, You need to check that import streamlit as st
import numpy as np
from PIL import Image
img_file_buffer = st.file_uploader("Upload an image")
if img_file_buffer is not None:
image = Image.open(img_file_buffer)
img_array = np.array(image) # if you want to pass it to OpenCV
st.image(image, caption="The caption", use_column_width=True) P.S. Thanks for the suggested example! |
Hi, this is very helpful. Unfortunately, I have an audio file to upload instead of an image and I need streamlit to open it and display as an audio file. Ive written this code but it keeps on returning an error:
Is there a better way for me to go around the type error issue in streamlit so I can play the uploaded audio file by the user? Thank you so much! |
Hi @emacarayan , I'm working on an improvement to the audio/video/image processors that will allow you to do exactly what you're trying to do. It should be out with the next release. For now, try doing this to read the bytes out of the file into the audio processor:
Thanks for playing with this new feature. (And also, thanks for using OGG! 😸 ) |
I get my hand on the new feature that we all have been waiting for.
I tested it to upload an image and read it with OpenCV (cv.VideoCapture) but unfortunately, I encounter an error. The type of the uploaded image is <_io.BytesIO object at 0x7f4c7adc7db0>
Error message
The text was updated successfully, but these errors were encountered: