Spaces:
Build error
Build error
Download utils.py from samim2024/CSV-Analysis-MISTRAL-AI: direct link, hf CLI and curl.
- Browser
- Download file 1.08 kB
-
https://huggingface.co/spaces/samim2024/CSV-Analysis-MISTRAL-AI/resolve/main/utils.py
- Command line
-
hf download hf://spaces/samim2024/CSV-Analysis-MISTRAL-AI/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/samim2024/CSV-Analysis-MISTRAL-AI/resolve/main/utils.py
1.08 kB
| ##from langchain.agents import create_pandas_dataframe_agent #This import has been recently replaced by the below | |
| from langchain_experimental.agents import create_pandas_dataframe_agent | |
| import pandas as pd | |
| #from langchain.llms import OpenAI | |
| #New import from langchain, which replaces the above | |
| #from langchain_openai import OpenAI | |
| from langchain.llms import HuggingFaceEndpoint | |
| from langchain.llms import huggingface_hub | |
| from langchain_community.llms import huggingface_hub | |
| def query_agent(data, query): | |
| # Parse the CSV file and create a Pandas DataFrame from its contents. | |
| df = pd.read_csv(data) | |
| #llm = OpenAI() | |
| llm = HuggingFaceEndpoint(repo_id="mistralai/Mixtral-8x7B-Instruct-v0.1", temperature=0.9) | |
| # Create a Pandas DataFrame agent. | |
| agent = create_pandas_dataframe_agent(llm, df, verbose=True) | |
| #Python REPL: A Python shell used to evaluating and executing Python commands. | |
| #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) |