Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -354,8 +354,27 @@ def get_or_download_code(file_name: str) -> str:
|
|
354 |
def _load_excel_as_text(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
|
@@ -366,8 +385,9 @@ def _load_excel_as_text(file_name: str) -> str:
|
|
366 |
all_text += df.to_string(index=False)
|
367 |
return all_text
|
368 |
except Exception as e:
|
369 |
-
|
370 |
-
return "ERROR: Could not read
|
|
|
371 |
|
372 |
|
373 |
|
|
|
354 |
def _load_excel_as_text(file_name: str) -> str:
|
355 |
import pandas as pd
|
356 |
import os
|
357 |
+
import requests
|
358 |
+
|
359 |
file_path = os.path.join("data", file_name)
|
360 |
+
hf_token = os.getenv("HF_TOKEN_READ")
|
361 |
+
|
362 |
+
# Scarica il file se non esiste localmente
|
363 |
+
if not os.path.exists(file_path):
|
364 |
+
print(f"[INFO] File {file_name} non trovato. Scarico...")
|
365 |
+
url = f"https://huggingface.co/datasets/gaia-benchmark/GAIA/resolve/main/2023/validation/{file_name}"
|
366 |
+
headers = {"Authorization": f"Bearer {hf_token}"}
|
367 |
+
try:
|
368 |
+
response = requests.get(url, headers=headers)
|
369 |
+
response.raise_for_status()
|
370 |
+
with open(file_path, "wb") as f:
|
371 |
+
f.write(response.content)
|
372 |
+
print(f"[INFO] Scaricato e salvato in {file_path}")
|
373 |
+
except Exception as e:
|
374 |
+
print(f"[ERRORE] Impossibile scaricare il file Excel: {e}")
|
375 |
+
return "ERROR: Could not download Excel file."
|
376 |
+
|
377 |
+
# Leggi il contenuto
|
378 |
try:
|
379 |
xl = pd.ExcelFile(file_path)
|
380 |
sheets = xl.sheet_names
|
|
|
385 |
all_text += df.to_string(index=False)
|
386 |
return all_text
|
387 |
except Exception as e:
|
388 |
+
print(f"[ERRORE] Impossibile leggere il file Excel: {e}")
|
389 |
+
return "ERROR: Could not read Excel file."
|
390 |
+
|
391 |
|
392 |
|
393 |
|