junkmind shreyasiv commited on
Commit
b7e4a74
·
0 Parent(s):

Duplicate from Insightly/CSV-Bot

Browse files

Co-authored-by: Shreya Sivakumar <[email protected]>

Files changed (9) hide show
  1. .gitattributes +35 -0
  2. README.md +13 -0
  3. app.py +86 -0
  4. data.csv +0 -0
  5. emb.py +80 -0
  6. get-pip.py +0 -0
  7. requirements.txt +77 -0
  8. setup.sh +38 -0
  9. tempfile +0 -0
.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: CSV Bot
3
+ emoji: 🏃
4
+ colorFrom: indigo
5
+ colorTo: red
6
+ sdk: streamlit
7
+ sdk_version: 1.21.0
8
+ app_file: app.py
9
+ pinned: false
10
+ duplicated_from: Insightly/CSV-Bot
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # Set the page configuration here
10
+ st.set_page_config(page_title="Insightly")
11
+
12
+ def main():
13
+ load_dotenv()
14
+
15
+ # Load the OpenAI API key from the environment variable
16
+ api_key = os.getenv("OPENAI_API_KEY")
17
+ if api_key is None or api_key == "":
18
+ st.error("OPENAI_API_KEY is not set")
19
+ return
20
+
21
+ st.sidebar.image("https://i.ibb.co/bX6GdqG/insightly-wbg.png", use_column_width=True)
22
+ st.title("Data Analysis 📈")
23
+
24
+ csv_files = st.file_uploader("Upload CSV files", type="csv", accept_multiple_files=True)
25
+ if csv_files:
26
+ llm = OpenAI(temperature=0)
27
+ user_input = st.text_input("Question here:")
28
+
29
+ # Iterate over each CSV file
30
+ for csv_file in csv_files:
31
+ with NamedTemporaryFile(delete=False) as f:
32
+ f.write(csv_file.getvalue())
33
+ f.flush()
34
+ df = pd.read_csv(f.name)
35
+
36
+ # Perform any necessary data preprocessing or feature engineering here
37
+ # You can modify the code based on your specific requirements
38
+
39
+ # Example: Accessing columns from the DataFrame
40
+ # column_data = df["column_name"]
41
+
42
+ # Example: Applying transformations or calculations to the data
43
+ # transformed_data = column_data.apply(lambda x: x * 2)
44
+
45
+ # Example: Using the preprocessed data with the OpenAI API
46
+ # llm_response = llm.predict(transformed_data)
47
+
48
+ if user_input:
49
+ # Pass the user input to the OpenAI agent for processing
50
+ agent = create_csv_agent(llm, f.name, verbose=True)
51
+ response = agent.run(user_input)
52
+
53
+ st.write(f"CSV File: {csv_file.name}")
54
+ st.write("Response:")
55
+ st.write(response)
56
+
57
+ # Add links to the sidebar with the same spacing properties
58
+
59
+ st.sidebar.markdown("<p class='sidebar-link'>📚 <a href='https://chandrakalagowda-demo2.hf.space/'> PDF Bot </a></p>", unsafe_allow_html=True)
60
+ st.sidebar.markdown("<p class='sidebar-link'>🖼️ <a href='https://insightly-image-reader.hf.space'> Image Reader</a></p>", unsafe_allow_html=True)
61
+ st.sidebar.markdown("<p class='sidebar-link'>📸 <a href='https://insightly-frame-capturer.hf.space/'> Frame Capturer</a></p>", unsafe_allow_html=True)
62
+
63
+ # Custom CSS to style the link and create vertical space
64
+ st.markdown(
65
+ """
66
+ <style>
67
+ .image-container {
68
+ margin-bottom: 60px;
69
+ }
70
+ .sidebar-link {
71
+ display: flex;
72
+ justify-content: left;
73
+ font-size: 28px;
74
+ margin-top: 20px;
75
+ margin-left: 10px;
76
+ }
77
+ .vertical-space {
78
+ height: 20px;
79
+ }
80
+ </style>
81
+ """,
82
+ unsafe_allow_html=True,
83
+ )
84
+
85
+ if __name__ == "__main__":
86
+ 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