i want to use st.file_uploader to upload a file based on the extension, use the necessary loader ex:
The normal working is
from langchain.document_loaders import PyPDFLoader
loader = PyPDFLoader("example_data/layout-parser-paper.pdf")
pages = loader.load_and_split()
but in streamlit :
import streamlit as st
import pandas as pd
from io import StringIO
uploaded_file = st.file_uploader("Choose a file")
if uploaded_file is not None:
# To read file as bytes:
bytes_data = uploaded_file.getvalue()
st.write(bytes_data)
# To convert to a string based IO:
stringio = StringIO(uploaded_file.getvalue().decode("utf-8"))
st.write(stringio)
# To read file as string:
string_data = stringio.read()
st.write(string_data)
# Can be used wherever a "file-like" object is accepted:
dataframe = pd.read_csv(uploaded_file)
st.write(dataframe)
how can i upload files in st.file_uploader such that it can be accesed by langchain loaders, should i create a temp file, what the best possible option i have thanks
i tried readings as string data but it messes-up with the loader, o just want the file to be accessible by the loaders