Last active
February 12, 2025 04:51
-
-
Save piclez/b20a58b19f9a5cc152dd85aa55a30fd1 to your computer and use it in GitHub Desktop.
Langchain Pandas Dataframe Agent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Streamlit application for querying invoice data using LangChain's pandas DataFrame agent. | |
Provides a simple interface for natural language queries on invoice data. | |
""" | |
import os | |
import pandas as pd | |
import streamlit as st | |
from langchain_experimental.agents import create_pandas_dataframe_agent | |
from langchain_openai import OpenAI | |
from dotenv import load_dotenv | |
load_dotenv() | |
os.getenv("OPENAI_API_KEY") | |
llm = OpenAI() | |
st.title("Querying Incoices") | |
# data = st.file_uploader("Upload CSV file", type="csv") | |
query = st.text_area("Enter your query") | |
button = st.button("Generate Response") | |
def get_response(dataframe): | |
""" | |
Create and query a pandas dataframe agent. | |
Args: | |
dataframe: pandas DataFrame to query | |
Returns: | |
dict: Agent's response to the query | |
""" | |
agent = create_pandas_dataframe_agent(llm, dataframe, verbose=True) | |
return agent.invoke(query) | |
if button: | |
df = pd.read_csv("data/invoices.csv") | |
response = get_response(df) | |
st.write(response["output"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment