viturko/Scan_CSV
0
1import streamlit as st2from dotenv import load_dotenv3from langchain.agents import create_pandas_dataframe_agent4import pandas as pd5from langchain.llms import OpenAI6 7load_dotenv()8 9def query_agent(data, query):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 LangChain20 return agent.run(query)21 22st.title("Let's do some analysis on your CSV")23st.header("Please upload your CSV file here:")24 25# Capture the CSV file26data = st.file_uploader("Upload CSV file",type="csv")27 28query = st.text_area("Enter your query")29button = st.button("Generate Response")30 31if button:32 # Get Response33 answer = query_agent(data,query)34 st.write(answer)