Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -352,12 +352,52 @@ def get_or_download_code(file_name: str) -> str:
|
|
352 |
with open(file_path, "r") as f:
|
353 |
return f.read()
|
354 |
|
355 |
-
|
356 |
def _load_excel_as_text(file_name: str) -> str:
|
357 |
import pandas as pd
|
358 |
import os
|
359 |
import requests
|
360 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
361 |
file_path = os.path.join("data", file_name)
|
362 |
hf_token = os.getenv("HF_TOKEN_READ")
|
363 |
|
|
|
352 |
with open(file_path, "r") as f:
|
353 |
return f.read()
|
354 |
|
|
|
355 |
def _load_excel_as_text(file_name: str) -> str:
|
356 |
import pandas as pd
|
357 |
import os
|
358 |
import requests
|
359 |
|
360 |
+
from io import StringIO
|
361 |
+
|
362 |
+
file_path = os.path.join("data", file_name)
|
363 |
+
hf_token = os.getenv("HF_TOKEN_READ")
|
364 |
+
|
365 |
+
# Scarica il file se non esiste localmente
|
366 |
+
if not os.path.exists(file_path):
|
367 |
+
print_coso(f"[INFO] File {file_name} non trovato. Scarico...")
|
368 |
+
url = f"https://huggingface.co/datasets/gaia-benchmark/GAIA/resolve/main/2023/validation/{file_name}"
|
369 |
+
headers = {"Authorization": f"Bearer {hf_token}"}
|
370 |
+
try:
|
371 |
+
response = requests.get(url, headers=headers)
|
372 |
+
response.raise_for_status()
|
373 |
+
with open(file_path, "wb") as f:
|
374 |
+
f.write(response.content)
|
375 |
+
print(f"[INFO] Scaricato e salvato in {file_path}")
|
376 |
+
except Exception as e:
|
377 |
+
print(f"[ERRORE] Impossibile scaricare il file Excel: {e}")
|
378 |
+
return "ERROR: Could not download Excel file."
|
379 |
+
|
380 |
+
try:
|
381 |
+
df = pd.read_excel(file_path)
|
382 |
+
df = df.applymap(lambda x: f"{x:.2f}" if isinstance(x, float) else x)
|
383 |
+
|
384 |
+
# Costruzione della tabella markdown-style
|
385 |
+
header = "| " + " | ".join(df.columns) + " |"
|
386 |
+
separator = "| " + " | ".join(["---"] * len(df.columns)) + " |"
|
387 |
+
rows = df.astype(str).apply(lambda row: "| " + " | ".join(row) + " |", axis=1).tolist()
|
388 |
+
|
389 |
+
table_text = "\n".join([header, separator] + rows)
|
390 |
+
return table_text
|
391 |
+
|
392 |
+
except Exception as e:
|
393 |
+
print(f"[ERRORE] Impossibile leggere il file Excel: {e}")
|
394 |
+
return "ERROR: Could not read Excel file."
|
395 |
+
|
396 |
+
def _load_excel_as_text2(file_name: str) -> str:
|
397 |
+
import pandas as pd
|
398 |
+
import os
|
399 |
+
import requests
|
400 |
+
|
401 |
file_path = os.path.join("data", file_name)
|
402 |
hf_token = os.getenv("HF_TOKEN_READ")
|
403 |
|