|
import streamlit as st |
|
import tempfile |
|
import json |
|
|
|
def add_upload(choice): |
|
if choice == 'Upload Document': |
|
uploaded_files = st.sidebar.file_uploader('Upload Files', |
|
type=['pdf', 'docx', 'txt'], |
|
accept_multiple_files=True) |
|
|
|
if uploaded_files is not None: |
|
|
|
for key in list(st.session_state.keys()): |
|
if key.startswith('filename') or key.startswith('filepath'): |
|
del st.session_state[key] |
|
|
|
|
|
for index, uploaded_file in enumerate(uploaded_files): |
|
with tempfile.NamedTemporaryFile(mode="wb", delete=False) as temp: |
|
bytes_data = uploaded_file.getvalue() |
|
temp.write(bytes_data) |
|
st.session_state[f'filename_{index}'] = uploaded_file.name |
|
st.session_state[f'filepath_{index}'] = temp.name |
|
|
|
else: |
|
|
|
with open('docStore/sample/files.json', 'r') as json_file: |
|
files = json.load(json_file) |
|
|
|
option = st.sidebar.selectbox('Select the example document', |
|
list(files.keys())) |
|
file_path = files[option] |
|
st.session_state['filename_0'] = file_path |
|
st.session_state['filepath_0'] = file_path |
|
|
|
|
|
|
|
def get_tabs(uploaded_docs): |
|
tabs = [] |
|
for doc_name in uploaded_docs: |
|
tab_title = doc_name |
|
tabs.append(tab_title) |
|
return tabs |
|
|
|
|