Reputation: 65
I am using two file uploaders inside the same function. The first file uploader works well , however, the second file uploader gets overwritten by the first.
def apps():
text = None
passport = st.file_uploader("Upload Passport", type=["png", "jpg"], key="passport")
if passport:
button = st.button("Print")
if button:
text = st.write(passport.name)
if text:
st.success(text)
verify_button = st.sidebar.button("Verify Face")
if verify_button:
photo = st.sidebar.file_uploader("UPLOAD PHOTO", type=["png", "jpg"], key="photo")
The second file uploader does not get activated on clicking verify_button. The first file uploader shows on the screen again.
Upvotes: 0
Views: 622
Reputation: 5014
When you put a button and the user presses it, streamlit will rerun the code from top to bottom - meaning it will rerun the app(). So the solution is not to add a button inside the app()
Example:
import streamlit as st
def apps():
passport = st.file_uploader("Upload Passport", type=["png", "jpg"], key="passport")
if passport:
st.image(passport)
# button = st.button("Print")
# if button:
# st.write(passport.name)
# verify_button = st.sidebar.button("Verify Face")
# if verify_button:
st.sidebar.write('Verify Face')
photo = st.sidebar.file_uploader("UPLOAD PHOTO", type=["png", "jpg"], key="photo")
if photo:
st.sidebar.image(photo)
apps()
Upvotes: 2