ValueError: Expected str or list, got <class 'streamlit.runtime.uploaded_file_manager.UploadedFile'>

create_csv_agent is expecting the Path to a csv file, so you need to provide it a path, rather than an uploaded object itself. The easiest way to do this is by creating a NamedTemporaryFile, writing the uploaded content to that file, and pass that file’s path to create_csv_agent:

from tempfile import NamedTemporaryFile

import streamlit as st
from dotenv import load_dotenv
from langchain.agents import create_csv_agent
from langchain.llms import OpenAI


def main():
    load_dotenv()

    st.set_page_config(page_title="Ask your CSV")
    st.header("Ask your CSV")

    file = st.file_uploader("upload file", type="csv")

    if file:
        with NamedTemporaryFile() as f: # Create temporary file
            f.write(file.getvalue()) # Save uploaded contents to file
            llm = OpenAI(temperature=0)
            user_input = st.text_input("Question here:")

            agent = create_csv_agent(llm, f.name, verbose=True) # Pass temporary filename to create_csv_agent
            if user_input:
                response = agent.run(user_input)
                st.write(response)


if __name__ == "__main__":
    main()