Reputation: 795
I am using streamlit to upload and read simple csv file with streamlit file uploader, but I keep getting ' raise ValueError(f"Expected str or list, got {type(path)}") ' on langchain's create_csv_agent
from langchain.agents import create_csv_agent
from langchain.llms import OpenAI
from dotenv import load_dotenv
import streamlit as st
def main():
load_dotenv()
st.set_page_config(page_title="Ask your CSV ", page_icon="🧊")
st.header("Ask your CSV")
user_csv = st.file_uploader("Upload a CSV file", type="csv")
if user_csv is not None:
# st.write(user_csv.read())
# import pdb; pdb.set_trace()
llm = OpenAI(temperature=0)
agent = create_csv_agent(llm, user_csv.read(), verbose=True)
user_question = st.text_input("Ask your question")
if user_question is not None and user_question != "":
response = agent.run(user_question)
st.write(response)
if __name__ == "__main__":
main()
once a csv is uploaded, a value error is raised.
I tried parsing the file name. I am expecting to read the file and ask questions about it.
Upvotes: 0
Views: 652
Reputation: 81
It seems that you're reading in the CSV file using user_csv.read()
which will return a string. Instead, it's recommended to use Pandas' read_csv()
to read the contents of the CSV file.
In your case, replace user_csv.read()
with pd.read_csv(user_csv)
.
Hope this helps!
Upvotes: 0