Upload 7 files
Browse files- app.py +62 -0
- data.csv +0 -0
- emb.py +80 -0
- get-pip.py +0 -0
- requirements.txt +77 -0
- setup.sh +38 -0
- tempfile +0 -0
app.py
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
from streamlit_chat import message
|
9 |
+
from langchain.embeddings.openai import OpenAIEmbeddings
|
10 |
+
from langchain.chat_models import ChatOpenAI
|
11 |
+
from langchain.chains import ConversationalRetrievalChain
|
12 |
+
from langchain.document_loaders.csv_loader import CSVLoader
|
13 |
+
from langchain.vectorstores import FAISS
|
14 |
+
|
15 |
+
def main():
|
16 |
+
load_dotenv()
|
17 |
+
|
18 |
+
# Load the OpenAI API key from the environment variable
|
19 |
+
api_key = os.getenv("OPENAI_API_KEY")
|
20 |
+
if api_key is None or api_key == "":
|
21 |
+
st.error("OPENAI_API_KEY is not set")
|
22 |
+
return
|
23 |
+
|
24 |
+
st.set_page_config(page_title="Insightly")
|
25 |
+
st.sidebar.image("/home/oem/Downloads/insightly_wbg.png", use_column_width=True)
|
26 |
+
st.header("Data Analysis π")
|
27 |
+
|
28 |
+
csv_files = st.file_uploader("Upload CSV files", type="csv", accept_multiple_files=True)
|
29 |
+
if csv_files:
|
30 |
+
llm = OpenAI(temperature=0)
|
31 |
+
user_input = st.text_input("Question here:")
|
32 |
+
|
33 |
+
# Iterate over each CSV file
|
34 |
+
for csv_file in csv_files:
|
35 |
+
with NamedTemporaryFile(delete=False) as f:
|
36 |
+
f.write(csv_file.getvalue())
|
37 |
+
f.flush()
|
38 |
+
df = pd.read_csv(f.name)
|
39 |
+
|
40 |
+
# Perform any necessary data preprocessing or feature engineering here
|
41 |
+
# You can modify the code based on your specific requirements
|
42 |
+
|
43 |
+
# Example: Accessing columns from the DataFrame
|
44 |
+
# column_data = df["column_name"]
|
45 |
+
|
46 |
+
# Example: Applying transformations or calculations to the data
|
47 |
+
# transformed_data = column_data.apply(lambda x: x * 2)
|
48 |
+
|
49 |
+
# Example: Using the preprocessed data with the OpenAI API
|
50 |
+
# llm_response = llm.predict(transformed_data)
|
51 |
+
|
52 |
+
if user_input:
|
53 |
+
# Pass the user input to the OpenAI agent for processing
|
54 |
+
agent = create_csv_agent(llm, f.name, verbose=True)
|
55 |
+
response = agent.run(user_input)
|
56 |
+
|
57 |
+
st.write(f"CSV File: {csv_file.name}")
|
58 |
+
st.write("Response:")
|
59 |
+
st.write(response)
|
60 |
+
|
61 |
+
if __name__ == "__main__":
|
62 |
+
main()
|
data.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
emb.py
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import openai
|
2 |
+
|
3 |
+
# Set up the OpenAI API credentials
|
4 |
+
openai.api_key = "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"
|
5 |
+
|
6 |
+
# Code snippet
|
7 |
+
code = """
|
8 |
+
from tempfile import NamedTemporaryFile
|
9 |
+
from langchain.agents import create_csv_agent
|
10 |
+
from langchain.llms import OpenAI
|
11 |
+
from dotenv import load_dotenv
|
12 |
+
import os
|
13 |
+
import streamlit as st
|
14 |
+
import pandas as pd
|
15 |
+
|
16 |
+
def main():
|
17 |
+
load_dotenv()
|
18 |
+
|
19 |
+
# Load the OpenAI API key from the environment variable
|
20 |
+
api_key = os.getenv("OPENAI_API_KEY")
|
21 |
+
if api_key is None or api_key == "":
|
22 |
+
st.error("OPENAI_API_KEY is not set")
|
23 |
+
return
|
24 |
+
|
25 |
+
st.set_page_config(page_title="Insightly")
|
26 |
+
st.sidebar.image("/home/oem/Downloads/insightly_wbg.png", use_column_width=True)
|
27 |
+
st.header("Data Analysis π")
|
28 |
+
|
29 |
+
csv_files = st.file_uploader("Upload CSV files", type="csv", accept_multiple_files=True)
|
30 |
+
if csv_files:
|
31 |
+
llm = OpenAI(temperature=0)
|
32 |
+
user_input = st.text_input("Question here:")
|
33 |
+
|
34 |
+
# Iterate over each CSV file
|
35 |
+
for csv_file in csv_files:
|
36 |
+
with NamedTemporaryFile(delete=False) as f:
|
37 |
+
f.write(csv_file.getvalue())
|
38 |
+
f.flush()
|
39 |
+
df = pd.read_csv(f.name)
|
40 |
+
|
41 |
+
# Perform any necessary data preprocessing or feature engineering here
|
42 |
+
# You can modify the code based on your specific requirements
|
43 |
+
|
44 |
+
# Example: Accessing columns from the DataFrame
|
45 |
+
# column_data = df["column_name"]
|
46 |
+
|
47 |
+
# Example: Applying transformations or calculations to the data
|
48 |
+
# transformed_data = column_data.apply(lambda x: x * 2)
|
49 |
+
|
50 |
+
# Example: Using the preprocessed data with the OpenAI API
|
51 |
+
# llm_response = llm.predict(transformed_data)
|
52 |
+
|
53 |
+
if user_input:
|
54 |
+
# Pass the user input to the OpenAI agent for processing
|
55 |
+
agent = create_csv_agent(llm, f.name, verbose=True)
|
56 |
+
response = agent.run(user_input)
|
57 |
+
|
58 |
+
st.write(f"CSV File: {csv_file.name}")
|
59 |
+
st.write("Response:")
|
60 |
+
st.write(response)
|
61 |
+
|
62 |
+
if __name__ == "__main__":
|
63 |
+
main()
|
64 |
+
"""
|
65 |
+
|
66 |
+
# Retrieve the embeddings
|
67 |
+
response = openai.Completion.create(
|
68 |
+
model="gpt-3.5-turbo",
|
69 |
+
documents=[code],
|
70 |
+
num_completions=1,
|
71 |
+
return_prompt=True,
|
72 |
+
return_sequences=False,
|
73 |
+
expand_prompt=False
|
74 |
+
)
|
75 |
+
|
76 |
+
# Extract the embeddings from the response
|
77 |
+
embeddings = response.choices[0].embedding
|
78 |
+
|
79 |
+
# Print the embeddings
|
80 |
+
print(embeddings)
|
get-pip.py
ADDED
The diff for this file is too large to render.
See raw diff
|
|
requirements.txt
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
aiohttp==3.8.4
|
2 |
+
aiosignal==1.3.1
|
3 |
+
altair==5.0.1
|
4 |
+
async-timeout==4.0.2
|
5 |
+
attrs==23.1.0
|
6 |
+
blinker==1.6.2
|
7 |
+
cachetools==5.3.1
|
8 |
+
certifi==2023.5.7
|
9 |
+
charset-normalizer==3.1.0
|
10 |
+
click==8.1.3
|
11 |
+
Cython==0.29.35
|
12 |
+
dataclasses-json==0.5.8
|
13 |
+
decorator==5.1.1
|
14 |
+
filelock==3.12.2
|
15 |
+
frozenlist==1.3.3
|
16 |
+
fsspec==2023.6.0
|
17 |
+
gitdb==4.0.10
|
18 |
+
GitPython==3.1.31
|
19 |
+
greenlet==2.0.2
|
20 |
+
huggingface==0.0.1
|
21 |
+
huggingface-hub==0.15.1
|
22 |
+
idna==3.4
|
23 |
+
importlib-metadata==6.7.0
|
24 |
+
Jinja2==3.1.2
|
25 |
+
jsonschema==4.17.3
|
26 |
+
langchain==0.0.219
|
27 |
+
langchainplus-sdk==0.0.17
|
28 |
+
markdown-it-py==3.0.0
|
29 |
+
MarkupSafe==2.1.3
|
30 |
+
marshmallow==3.19.0
|
31 |
+
marshmallow-enum==1.5.1
|
32 |
+
mdurl==0.1.2
|
33 |
+
multidict==6.0.4
|
34 |
+
mypy-extensions==1.0.0
|
35 |
+
numexpr==2.8.4
|
36 |
+
numpy==1.25.0
|
37 |
+
openai==0.27.8
|
38 |
+
openapi-schema-pydantic==1.2.4
|
39 |
+
packaging==23.1
|
40 |
+
pandas==2.0.3
|
41 |
+
Pillow==9.5.0
|
42 |
+
protobuf==4.23.3
|
43 |
+
pyarrow==12.0.1
|
44 |
+
pydantic==1.10.9
|
45 |
+
pydeck==0.8.1b0
|
46 |
+
Pygments==2.15.1
|
47 |
+
Pympler==1.0.1
|
48 |
+
pyrsistent==0.19.3
|
49 |
+
python-dateutil==2.8.2
|
50 |
+
python-dotenv==1.0.0
|
51 |
+
pytz==2023.3
|
52 |
+
pytz-deprecation-shim==0.1.0.post0
|
53 |
+
PyYAML==6.0
|
54 |
+
regex==2023.6.3
|
55 |
+
requests==2.31.0
|
56 |
+
rich==13.4.2
|
57 |
+
safetensors==0.3.1
|
58 |
+
six==1.16.0
|
59 |
+
smmap==5.0.0
|
60 |
+
SQLAlchemy==2.0.17
|
61 |
+
streamlit==1.24.0
|
62 |
+
streamlit-chat==0.1.1
|
63 |
+
tabulate==0.9.0
|
64 |
+
tenacity==8.2.2
|
65 |
+
toml==0.10.2
|
66 |
+
toolz==0.12.0
|
67 |
+
tornado==6.3.2
|
68 |
+
tqdm==4.65.0
|
69 |
+
typing-inspect==0.9.0
|
70 |
+
typing_extensions==4.6.3
|
71 |
+
tzdata==2023.3
|
72 |
+
tzlocal==4.3.1
|
73 |
+
urllib3==2.0.3
|
74 |
+
validators==0.20.0
|
75 |
+
watchdog==3.0.0
|
76 |
+
yarl==1.9.2
|
77 |
+
zipp==3.15.0
|
setup.sh
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
def display_ui():
|
4 |
+
st.sidebar.image("/home/oem/Downloads/insightly_wbg.png", use_column_width=True)
|
5 |
+
st.header("Data Analysis π")
|
6 |
+
|
7 |
+
csv_files = st.file_uploader("Upload CSV files", type="csv", accept_multiple_files=True)
|
8 |
+
if csv_files:
|
9 |
+
llm = OpenAI(temperature=0)
|
10 |
+
user_input = st.text_input("Question here:")
|
11 |
+
|
12 |
+
# Iterate over each CSV file
|
13 |
+
for csv_file in csv_files:
|
14 |
+
with NamedTemporaryFile(delete=False) as f:
|
15 |
+
f.write(csv_file.getvalue())
|
16 |
+
f.flush()
|
17 |
+
df = pd.read_csv(f.name)
|
18 |
+
|
19 |
+
# Perform any necessary data preprocessing or feature engineering here
|
20 |
+
# You can modify the code based on your specific requirements
|
21 |
+
|
22 |
+
# Example: Accessing columns from the DataFrame
|
23 |
+
# column_data = df["column_name"]
|
24 |
+
|
25 |
+
# Example: Applying transformations or calculations to the data
|
26 |
+
# transformed_data = column_data.apply(lambda x: x * 2)
|
27 |
+
|
28 |
+
# Example: Using the preprocessed data with the OpenAI API
|
29 |
+
# llm_response = llm.predict(transformed_data)
|
30 |
+
|
31 |
+
if user_input:
|
32 |
+
# Pass the user input to the OpenAI agent for processing
|
33 |
+
agent = create_csv_agent(llm, f.name, verbose=True)
|
34 |
+
response = agent.run(user_input)
|
35 |
+
|
36 |
+
st.write(f"CSV File: {csv_file.name}")
|
37 |
+
st.write("Response:")
|
38 |
+
st.write(response)
|
tempfile
ADDED
The diff for this file is too large to render.
See raw diff
|
|