How to upload an image with st.file_uploader?

I know how to use st.file_uploader to upload text files with streamlit documentation. Does anyone have the script for uploading an image file (jpg, png, gif)? TIA

The object returned by st.file_uploader is a subclass of BytesIO and you can feed it directly to st.image:

import streamlit as st

uploaded_file = st.file_uploader("Choose an image file", type="jpg")
if uploaded_file:
    st.image(uploaded_file)

If you need to save the file, you can use PIL:

import streamlit as st
from PIL import Image

uploaded_file = st.file_uploader("Choose an image file", type="jpg")
if uploaded_file:
    image = Image.open(uploaded_file)
    image.save("output_image.jpg")
    st.image("output_image.jpg")