shreyasiv commited on
Commit
6fb4833
Β·
1 Parent(s): ea671a6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -13
app.py CHANGED
@@ -4,8 +4,7 @@ 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()
@@ -20,18 +19,38 @@ def main():
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()
 
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()
 
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()