GattoNero commited on
Commit
d4e5999
·
verified ·
1 Parent(s): fc2a85b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -9
app.py CHANGED
@@ -147,6 +147,19 @@ class BasicAgent:
147
  )
148
  risposta = self._ask_gpt4o(prompt_python)
149
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
  elif file_info.endswith(".txt"):
151
  print("coso Text file detected")
152
  text_content = self._load_text(file_info)
@@ -336,6 +349,27 @@ def get_or_download_code(file_name: str) -> str:
336
 
337
  with open(file_path, "r") as f:
338
  return f.read()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
339
 
340
  '''
341
  base_url = "https://huggingface.co/datasets/gaia-benchmark/GAIA/resolve"
@@ -372,19 +406,22 @@ def create_mock_questions():
372
  "Level": "1",
373
  "file_name": ""
374
  }
375
- '''
376
-
377
-
378
-
379
-
380
-
381
- return [
382
- {
383
  "task_id":"f918266a-b3e0-4914-865d-4faa564f1aef",
384
  "question":"What is the final numeric output from the attached Python code?",
385
  "Level":"1",
386
  "file_name":"f918266a-b3e0-4914-865d-4faa564f1aef.py"
387
  }
 
 
 
 
 
 
 
 
 
 
388
  ]
389
 
390
 
@@ -543,7 +580,6 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
543
  print(f"coso final_status: {final_status} - results_df: {results_df}")
544
  return final_status, results_df
545
 
546
- #return "mock1", None
547
 
548
 
549
  except requests.exceptions.HTTPError as e:
 
147
  )
148
  risposta = self._ask_gpt4o(prompt_python)
149
 
150
+ elif file_info.endswith(".xlsx"):
151
+ print_coso("Excel file detected")
152
+ excel_text = self._load_excel_as_text(file_info)
153
+ print_coso(f"Excel before prompt: {excel_text}")
154
+ prompt = (
155
+ "The following is the text extracted from an Excel spreadsheet.\n"
156
+ "Please use it to answer the question that follows:\n\n"
157
+ f"{excel_text}\n\n"
158
+ f"Question: {question}\n"
159
+ "Provide only the final answer. If it is a number, format it as USD with two decimal places if relevant. Do not explain."
160
+ )
161
+ risposta = self._ask_gpt4o(prompt)
162
+
163
  elif file_info.endswith(".txt"):
164
  print("coso Text file detected")
165
  text_content = self._load_text(file_info)
 
349
 
350
  with open(file_path, "r") as f:
351
  return f.read()
352
+
353
+
354
+ def _load_excel_as_text(self, file_name: str) -> str:
355
+ import pandas as pd
356
+ import os
357
+
358
+ file_path = os.path.join("data", file_name)
359
+ try:
360
+ xl = pd.ExcelFile(file_path)
361
+ sheets = xl.sheet_names
362
+ all_text = ""
363
+ for sheet in sheets:
364
+ df = xl.parse(sheet)
365
+ all_text += f"\nSheet: {sheet}\n"
366
+ all_text += df.to_string(index=False)
367
+ return all_text
368
+ except Exception as e:
369
+ print_coso(f"[ERRORE] Impossibile leggere il file Excel: {e}")
370
+ return "ERROR: Could not read the Excel file."
371
+
372
+
373
 
374
  '''
375
  base_url = "https://huggingface.co/datasets/gaia-benchmark/GAIA/resolve"
 
406
  "Level": "1",
407
  "file_name": ""
408
  }
409
+ {
 
 
 
 
 
 
 
410
  "task_id":"f918266a-b3e0-4914-865d-4faa564f1aef",
411
  "question":"What is the final numeric output from the attached Python code?",
412
  "Level":"1",
413
  "file_name":"f918266a-b3e0-4914-865d-4faa564f1aef.py"
414
  }
415
+ '''
416
+
417
+
418
+ return [
419
+ {
420
+ "task_id":"7bd855d8-463d-4ed5-93ca-5fe35145f733",
421
+ "question":"The attached Excel file contains the sales of menu items for a local fast-food chain. What were the total sales that the chain made from food (not including drinks)? Express your answer in USD with two decimal places.",
422
+ "Level":"1",
423
+ "file_name":"7bd855d8-463d-4ed5-93ca-5fe35145f733.xlsx"
424
+ }
425
  ]
426
 
427
 
 
580
  print(f"coso final_status: {final_status} - results_df: {results_df}")
581
  return final_status, results_df
582
 
 
583
 
584
 
585
  except requests.exceptions.HTTPError as e: