Upload 5 files
Browse files- app.py +37 -0
- data.csv +0 -0
- get-pip.py +0 -0
- insightly_wbg.png +0 -0
- tempfile +0 -0
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def main():
|
| 11 |
+
load_dotenv()
|
| 12 |
+
|
| 13 |
+
# Load the OpenAI API key from the environment variable
|
| 14 |
+
api_key = os.getenv("OPENAI_API_KEY")
|
| 15 |
+
if api_key is None or api_key == "":
|
| 16 |
+
st.error("OPENAI_API_KEY is not set")
|
| 17 |
+
return
|
| 18 |
+
|
| 19 |
+
st.set_page_config(page_title="Insightly")
|
| 20 |
+
st.sidebar.image("/home/oem/Downloads/insightly_wbg.png", use_column_width=True)
|
| 21 |
+
st.header("Data Analysis 📈")
|
| 22 |
+
|
| 23 |
+
csv_file = st.file_uploader("Upload a CSV file", type="csv")
|
| 24 |
+
if csv_file:
|
| 25 |
+
with NamedTemporaryFile(delete=False) as f:
|
| 26 |
+
f.write(csv_file.getvalue())
|
| 27 |
+
f.flush()
|
| 28 |
+
llm = OpenAI(temperature=0)
|
| 29 |
+
user_input = st.text_input("Question here:")
|
| 30 |
+
agent = create_csv_agent(llm, f.name, verbose=True)
|
| 31 |
+
if user_input:
|
| 32 |
+
response = agent.run(user_input)
|
| 33 |
+
st.write(response)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
if __name__ == "__main__":
|
| 37 |
+
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
|
tempfile
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|