Delete app.py
Browse files
app.py
DELETED
|
@@ -1,56 +0,0 @@
|
|
| 1 |
-
from tempfile import NamedTemporaryFile
|
| 2 |
-
from langchain.agents import create_csv_agent
|
| 3 |
-
from langchain.llms import OpenAI
|
| 4 |
-
from dotenv import load_dotenv
|
| 5 |
-
import os
|
| 6 |
-
import streamlit as st
|
| 7 |
-
import pandas as pd
|
| 8 |
-
|
| 9 |
-
def main():
|
| 10 |
-
load_dotenv()
|
| 11 |
-
|
| 12 |
-
# Load the OpenAI API key from the environment variable
|
| 13 |
-
api_key = os.getenv("OPENAI_API_KEY")
|
| 14 |
-
if api_key is None or api_key == "":
|
| 15 |
-
st.error("OPENAI_API_KEY is not set")
|
| 16 |
-
return
|
| 17 |
-
|
| 18 |
-
st.set_page_config(page_title="Insightly")
|
| 19 |
-
st.sidebar.image("/home/oem/Downloads/insightly_wbg.png", use_column_width=True)
|
| 20 |
-
st.header("Data Analysis 📈")
|
| 21 |
-
|
| 22 |
-
csv_files = st.file_uploader("Upload CSV files", type="csv", accept_multiple_files=True)
|
| 23 |
-
if csv_files:
|
| 24 |
-
llm = OpenAI(temperature=0)
|
| 25 |
-
user_input = st.text_input("Question here:")
|
| 26 |
-
|
| 27 |
-
# Iterate over each CSV file
|
| 28 |
-
for csv_file in csv_files:
|
| 29 |
-
with NamedTemporaryFile(delete=False) as f:
|
| 30 |
-
f.write(csv_file.getvalue())
|
| 31 |
-
f.flush()
|
| 32 |
-
df = pd.read_csv(f.name)
|
| 33 |
-
|
| 34 |
-
# Perform any necessary data preprocessing or feature engineering here
|
| 35 |
-
# You can modify the code based on your specific requirements
|
| 36 |
-
|
| 37 |
-
# Example: Accessing columns from the DataFrame
|
| 38 |
-
# column_data = df["column_name"]
|
| 39 |
-
|
| 40 |
-
# Example: Applying transformations or calculations to the data
|
| 41 |
-
# transformed_data = column_data.apply(lambda x: x * 2)
|
| 42 |
-
|
| 43 |
-
# Example: Using the preprocessed data with the OpenAI API
|
| 44 |
-
# llm_response = llm.predict(transformed_data)
|
| 45 |
-
|
| 46 |
-
if user_input:
|
| 47 |
-
# Pass the user input to the OpenAI agent for processing
|
| 48 |
-
agent = create_csv_agent(llm, f.name, verbose=True)
|
| 49 |
-
response = agent.run(user_input)
|
| 50 |
-
|
| 51 |
-
st.write(f"CSV File: {csv_file.name}")
|
| 52 |
-
st.write("Response:")
|
| 53 |
-
st.write(response)
|
| 54 |
-
|
| 55 |
-
if __name__ == "__main__":
|
| 56 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|