ssumukh17 commited on
Commit
988a6c6
1 Parent(s): 88fb925

Upload pandas_ai.py

Browse files
Files changed (1) hide show
  1. pandas_ai.py +23 -0
pandas_ai.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ from pandasai import SmartDataframe
3
+ from pandasai.llm import OpenAI
4
+ import os
5
+
6
+ def csv_file(file_upload,message):
7
+ df = pd.read_csv(file_upload,encoding='cp1252')
8
+ df = df.head(30)
9
+ os.environ['OPENAI_API_KEY'] = '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'
10
+ llm = OpenAI(temperature=0)
11
+ df_s = SmartDataframe(df, config={"llm": llm})
12
+ output = df_s.chat(message)
13
+ return output
14
+
15
+ def excel_file(file_upload,message):
16
+ df = pd.read_excel(file_upload,encoding='cp1252')
17
+ df = df.head(30)
18
+ os.environ['OPENAI_API_KEY'] = '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'
19
+ llm = OpenAI(temperature=0)
20
+ df_s = SmartDataframe(df, config={"llm": llm})
21
+ output = df_s.chat(message)
22
+ return output
23
+