Spaces:
Sleeping
Sleeping
palitrajarshi
commited on
Commit
·
b7c69c7
1
Parent(s):
0e381c0
Upload 2 files
Browse files- pages/CSV_Data_Analyzer.py +20 -0
- utils1.py +13 -0
pages/CSV_Data_Analyzer.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)
|
utils1.py
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from langchain.agents import create_pandas_dataframe_agent
|
2 |
+
import pandas as pd
|
3 |
+
from langchain.llms import OpenAI
|
4 |
+
|
5 |
+
def query_agent(data, query):
|
6 |
+
# Parse the CSV file and create a Pandas DataFrame from its contents.
|
7 |
+
df = pd.read_csv(data)
|
8 |
+
llm = OpenAI()
|
9 |
+
# Create a Pandas DataFrame agent.
|
10 |
+
agent = create_pandas_dataframe_agent(llm, df, verbose=True)
|
11 |
+
#Python REPL: A Python shell used to evaluating and executing Python commands.
|
12 |
+
#It takes python code as input and outputs the result. The input python code can be generated from another tool in the LangChain
|
13 |
+
return agent.run(query)
|