Spaces:
Sleeping
Sleeping
Upload 6 files
Browse files- app.py +56 -0
- data.csv +0 -0
- get-pip.py +0 -0
- insightly_wbg.png +0 -0
- requirements.txt +100 -0
- tempfile +0 -0
app.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|
data.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
get-pip.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
insightly_wbg.png
ADDED
|
requirements.txt
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
aiohttp==3.8.4
|
| 2 |
+
aiosignal==1.3.1
|
| 3 |
+
altair==5.0.1
|
| 4 |
+
appnope==0.1.3
|
| 5 |
+
asttokens==2.2.1
|
| 6 |
+
async-timeout==4.0.2
|
| 7 |
+
attrs==23.1.0
|
| 8 |
+
backcall==0.2.0
|
| 9 |
+
blinker==1.6.2
|
| 10 |
+
cachetools==5.3.1
|
| 11 |
+
certifi==2023.5.7
|
| 12 |
+
charset-normalizer==3.1.0
|
| 13 |
+
click==8.1.3
|
| 14 |
+
comm==0.1.3
|
| 15 |
+
dataclasses-json==0.5.8
|
| 16 |
+
debugpy==1.6.7
|
| 17 |
+
decorator==5.1.1
|
| 18 |
+
executing==1.2.0
|
| 19 |
+
faiss-cpu==1.7.4
|
| 20 |
+
filelock==3.12.2
|
| 21 |
+
frozenlist==1.3.3
|
| 22 |
+
fsspec==2023.6.0
|
| 23 |
+
gitdb==4.0.10
|
| 24 |
+
GitPython==3.1.31
|
| 25 |
+
greenlet==2.0.2
|
| 26 |
+
huggingface-hub==0.15.1
|
| 27 |
+
idna==3.4
|
| 28 |
+
importlib-metadata==6.6.0
|
| 29 |
+
ipykernel==6.23.2
|
| 30 |
+
ipython==8.14.0
|
| 31 |
+
jedi==0.18.2
|
| 32 |
+
Jinja2==3.1.2
|
| 33 |
+
jsonschema==4.17.3
|
| 34 |
+
jupyter_client==8.2.0
|
| 35 |
+
jupyter_core==5.3.1
|
| 36 |
+
langchain==0.0.201
|
| 37 |
+
langchainplus-sdk==0.0.10
|
| 38 |
+
markdown-it-py==3.0.0
|
| 39 |
+
MarkupSafe==2.1.3
|
| 40 |
+
marshmallow==3.19.0
|
| 41 |
+
marshmallow-enum==1.5.1
|
| 42 |
+
matplotlib-inline==0.1.6
|
| 43 |
+
mdurl==0.1.2
|
| 44 |
+
multidict==6.0.4
|
| 45 |
+
mypy-extensions==1.0.0
|
| 46 |
+
nest-asyncio==1.5.6
|
| 47 |
+
numexpr==2.8.4
|
| 48 |
+
numpy==1.24.3
|
| 49 |
+
openai==0.27.8
|
| 50 |
+
openapi-schema-pydantic==1.2.4
|
| 51 |
+
packaging==23.1
|
| 52 |
+
pandas==2.0.2
|
| 53 |
+
parso==0.8.3
|
| 54 |
+
pexpect==4.8.0
|
| 55 |
+
pickleshare==0.7.5
|
| 56 |
+
Pillow==9.5.0
|
| 57 |
+
platformdirs==3.5.3
|
| 58 |
+
prompt-toolkit==3.0.38
|
| 59 |
+
protobuf==4.23.3
|
| 60 |
+
psutil==5.9.5
|
| 61 |
+
ptyprocess==0.7.0
|
| 62 |
+
pure-eval==0.2.2
|
| 63 |
+
pyarrow==12.0.1
|
| 64 |
+
pydantic==1.10.9
|
| 65 |
+
pydeck==0.8.1b0
|
| 66 |
+
Pygments==2.15.1
|
| 67 |
+
Pympler==1.0.1
|
| 68 |
+
PyPDF2==3.0.1
|
| 69 |
+
pyrsistent==0.19.3
|
| 70 |
+
python-dateutil==2.8.2
|
| 71 |
+
python-dotenv==1.0.0
|
| 72 |
+
pytz==2023.3
|
| 73 |
+
pytz-deprecation-shim==0.1.0.post0
|
| 74 |
+
PyYAML==6.0
|
| 75 |
+
pyzmq==25.1.0
|
| 76 |
+
regex==2023.6.3
|
| 77 |
+
requests==2.31.0
|
| 78 |
+
rich==13.4.2
|
| 79 |
+
six==1.16.0
|
| 80 |
+
smmap==5.0.0
|
| 81 |
+
SQLAlchemy==2.0.16
|
| 82 |
+
stack-data==0.6.2
|
| 83 |
+
streamlit==1.23.1
|
| 84 |
+
tabulate==0.9.0
|
| 85 |
+
tenacity==8.2.2
|
| 86 |
+
tiktoken==0.4.0
|
| 87 |
+
toml==0.10.2
|
| 88 |
+
toolz==0.12.0
|
| 89 |
+
tornado==6.3.2
|
| 90 |
+
tqdm==4.65.0
|
| 91 |
+
traitlets==5.9.0
|
| 92 |
+
typing-inspect==0.9.0
|
| 93 |
+
typing_extensions==4.6.3
|
| 94 |
+
tzdata==2023.3
|
| 95 |
+
tzlocal==4.3
|
| 96 |
+
urllib3==2.0.3
|
| 97 |
+
validators==0.20.0
|
| 98 |
+
wcwidth==0.2.6
|
| 99 |
+
yarl==1.9.2
|
| 100 |
+
zipp==3.15.0
|
tempfile
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|