dygoo commited on
Commit
2c886b4
·
verified ·
1 Parent(s): 637eefa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -1
app.py CHANGED
@@ -190,7 +190,17 @@ class BasicAgent:
190
  return summary
191
  except Exception as e:
192
  return f"CSV reading error: {str(e)}"
193
-
 
 
 
 
 
 
 
 
 
 
194
  def process_question(self, question: str) -> str:
195
  try:
196
  # Processing image
@@ -199,6 +209,11 @@ class BasicAgent:
199
  image_url = image_url_match.group(0)
200
  return self._process_image_query(question, image_url)
201
 
 
 
 
 
 
202
  # Read csv
203
  if "calculate" in question.lower() and any(c in question for c in "+-*/"):
204
  calculation = re.search(r'calculate\s+([\d\s\+\-\*\/\(\)\.\,\^\%]+)', question, re.IGNORECASE)
 
190
  return summary
191
  except Exception as e:
192
  return f"CSV reading error: {str(e)}"
193
+
194
+ def _read_excel(self, file_url):
195
+ try:
196
+ response = requests.get(file_url)
197
+ import io, pandas as pd
198
+ df = pd.read_excel(io.BytesIO(response.content))
199
+ summary = f"Excel contains {len(df)} rows, {len(df.columns)} columns.\nColumns: {', '.join(df.columns)}\nSample data: {df.head(3).to_string()}"
200
+ return summary
201
+ except Exception as e:
202
+ return f"Excel reading error: {str(e)}"
203
+
204
  def process_question(self, question: str) -> str:
205
  try:
206
  # Processing image
 
209
  image_url = image_url_match.group(0)
210
  return self._process_image_query(question, image_url)
211
 
212
+ #Excel
213
+ excel_url_match = re.search(r'https?://\S+\.(xlsx|xls|xlsm)', question, re.IGNORECASE)
214
+ if excel_url_match:
215
+ return self._read_excel(excel_url_match.group(0))
216
+
217
  # Read csv
218
  if "calculate" in question.lower() and any(c in question for c in "+-*/"):
219
  calculation = re.search(r'calculate\s+([\d\s\+\-\*\/\(\)\.\,\^\%]+)', question, re.IGNORECASE)