Spaces:
Sleeping
Sleeping
Upload 5 files
Browse files- .env +1 -0
- .env.example +2 -0
- app.py +20 -0
- requirements.txt +0 -0
- utils.py +20 -0
.env
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
OPENAI_API_KEY="sk-3f8iW6nSTjf2422hgnm9654gh6g4fss5hkluYz7dO98vje4uPCT"
|
.env.example
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
OPENAI_API_KEY=""
|
2 |
+
HUGGINGFACEHUB_API_TOKEN=""
|
app.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from dotenv import load_dotenv
|
3 |
+
from utils import query_agent
|
4 |
+
|
5 |
+
load_dotenv()
|
6 |
+
|
7 |
+
|
8 |
+
st.title("Let's do some analysis on your CSV")
|
9 |
+
st.header("Please upload your CSV file here:")
|
10 |
+
|
11 |
+
# Capture the CSV file
|
12 |
+
data = st.file_uploader("Upload CSV file",type="csv")
|
13 |
+
|
14 |
+
query = st.text_area("Enter your query")
|
15 |
+
button = st.button("Generate Response")
|
16 |
+
|
17 |
+
if button:
|
18 |
+
# Get Response
|
19 |
+
answer = query_agent(data,query)
|
20 |
+
st.write(answer)
|
requirements.txt
ADDED
Binary file (332 Bytes). View file
|
|
utils.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
##from langchain.agents import create_pandas_dataframe_agent #This import has been recently replaced by the below
|
2 |
+
from langchain_experimental.agents import create_pandas_dataframe_agent
|
3 |
+
import pandas as pd
|
4 |
+
#from langchain.llms import OpenAI
|
5 |
+
#New import from langchain, which replaces the above
|
6 |
+
from langchain_openai import OpenAI
|
7 |
+
|
8 |
+
def query_agent(data, query):
|
9 |
+
|
10 |
+
# Parse the CSV file and create a Pandas DataFrame from its contents.
|
11 |
+
df = pd.read_csv(data)
|
12 |
+
|
13 |
+
llm = OpenAI()
|
14 |
+
|
15 |
+
# Create a Pandas DataFrame agent.
|
16 |
+
agent = create_pandas_dataframe_agent(llm, df, verbose=True)
|
17 |
+
|
18 |
+
#Python REPL: A Python shell used to evaluating and executing Python commands.
|
19 |
+
#It takes python code as input and outputs the result. The input python code can be generated from another tool in the LangChain
|
20 |
+
return agent.invoke(query)
|