0xrsydn commited on
Commit
cca7719
·
verified ·
1 Parent(s): f6a6c9b

Update ai_agent.py

Browse files
Files changed (1) hide show
  1. ai_agent.py +9 -1
ai_agent.py CHANGED
@@ -30,7 +30,15 @@ def sql_agent(file, agent_input):
30
  return agent_output
31
 
32
  def pandas_agent(file, agent_input):
33
- df = pd.read_csv(file)
 
 
 
 
 
 
 
 
34
  agent = create_pandas_dataframe_agent(llm, df, agent_type="openai-tools", verbose=True)
35
  agent_output = agent.invoke(agent_input)
36
  return agent_output
 
30
  return agent_output
31
 
32
  def pandas_agent(file, agent_input):
33
+ # Check if the file extension is CSV
34
+ if file.endswith('.csv'):
35
+ df = pd.read_csv(file)
36
+ # Check if the file extension is XLS or XLSX
37
+ elif file.endswith('.xls') or file.endswith('.xlsx'):
38
+ df = pd.read_excel(file)
39
+ else:
40
+ return "Unsupported file format. Only CSV, XLS, or XLSX files are supported."
41
+ # Proceed with your agent code
42
  agent = create_pandas_dataframe_agent(llm, df, agent_type="openai-tools", verbose=True)
43
  agent_output = agent.invoke(agent_input)
44
  return agent_output