shreyasiv commited on
Commit
aff2ccc
1 Parent(s): dd2436f
Files changed (1) hide show
  1. app.py +37 -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()