Spaces:
Build error
Build error
Download utils.py from jcnok/csv_analysis: direct link, hf CLI and curl.
- Browser
- Download file 673 Bytes
-
https://huggingface.co/spaces/jcnok/csv_analysis/resolve/main/utils.py
- Command line
-
hf download hf://spaces/jcnok/csv_analysis/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/jcnok/csv_analysis/resolve/main/utils.py
673 Bytes
| from langchain_experimental.agents import create_pandas_dataframe_agent | |
| import pandas as pd | |
| from langchain_openai import OpenAI | |
| import os | |
| from langchain_openai import ChatOpenAI | |
| def query_agent(data, query): | |
| # Parse the CSV file and create a Pandas DataFrame from its contents. | |
| df = pd.read_csv(data) | |
| os.environ["OPENAI_API_KEY"] | |
| llm = ChatOpenAI(model="gpt-4o-mini", temperature=0) | |
| # Create a Pandas DataFrame agent. | |
| agent = create_pandas_dataframe_agent(llm,df,verbose=True) | |
| #It takes python code as input and outputs the result. The input python code can be generated from another tool in the LangChain | |
| return agent.invoke(query) |