yanndebray / programming-GPTs

Book in writing ... 🦜
https://yanndebray.github.io/programming-GPTs/
MIT License
3 stars 0 forks source link

chap 5 - add file input to code interpreter #22

Closed yanndebray closed 1 month ago

yanndebray commented 1 month ago

image

yanndebray commented 1 month ago

File upload:

import streamlit as st

st.title('File Upload 📁')
uploaded_file = None
if 'toggle_file' not in st.session_state:
    st.session_state.toggle_file = False

def toggle_on():
    if not st.session_state.toggle_file:
        st.session_state.toggle_file = True

def toggle_off():
    if st.session_state.toggle_file:
        st.session_state.toggle_file = False

st.button('upload file', on_click=toggle_on)

if st.session_state.toggle_file:
    uploaded_file = st.file_uploader("Choose a file")

st.write(uploaded_file)

if prompt := st.chat_input():
    with st.chat_message('user',avatar='user'):
        st.write(prompt)
        if uploaded_file:
            st.write(uploaded_file.name)
    toggle_off()
yanndebray commented 1 month ago

image