FileNotFoundError (Works perfectly fine for a pdf file imported the same way)

Summary

The issue is related to the create_csv_agent function, which is causing a “FileNotFoundError” when trying to read the CSV file. I am deploying the app so it should be able to read the file when it’s uploaded and should not matter if the file is in the current dir or not.

Steps to reproduce

Code snippet:

 # Upload PDF file
 st.write(f'### 2. Upload your {file_type} file')
 if file_type.lower().endswith('pdf'):
     uploaded_file = st.file_uploader('Upload your PDF file', type=['pdf'], label_visibility="collapsed")
 elif file_type.lower().endswith('csv'):
     st.write(os.getcwd())
     uploaded_file = st.file_uploader('Upload your CSV file', type=['csv'], label_visibility="collapsed")
 else:
     uploaded_file = None

 # Read PDF file and extract text
 if uploaded_file is not None:
     if uploaded_file.name.endswith('.pdf'):
         text = read_pdf(uploaded_file)
     elif uploaded_file.name.endswith('.csv'):
         st.write(text)
         agent = create_csv_agent(OpenAI(openai_api_key=OPENAI_API_KEY,temperature=0), uploaded_file.name, verbose=True)
         st.write(agent)

Actual behavior:

Links

Hey @virajsabhaya23,

Thanks for sharing your question!

It sounds like you’re not passing the correct path to the uploaded CSV file. You mentioned “I am deploying the app so it should be able to read the file when it’s uploaded and should not matter if the file is in the current dir or not.” – but this is actually not true. If the file is not uploaded to the current directory, you’ll need to provide the full path.

It looks like you have the right idea, though, of using st.write(os.getcwd()) to print out the path. The screenshot you shared looks like it’s from when you’re running the app locally. I’d recommend running the app when it’s deployed and using the st.write(os.getcwd()) line to figure out what path you need to provide.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.