GattoNero commited on
Commit
7f4b84d
·
verified ·
1 Parent(s): 0a65f10

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -12
app.py CHANGED
@@ -158,25 +158,26 @@ class BasicAgent:
158
 
159
 
160
  def get_or_download_image(file_name: str) -> Image.Image:
161
- """
162
- Controlla se l'immagine è presente in /data. Se non lo è, la scarica da Hugging Face.
163
- Restituisce un oggetto PIL.Image.
164
- """
 
165
  file_path = os.path.join("data", file_name)
 
 
 
 
 
166
 
167
  if not os.path.exists(file_path):
168
  print(f"[INFO] File {file_name} non trovato in /data, lo scarico...")
169
- #url = f"https://huggingface.co/datasets/gaia-benchmark/GAIA/resolve/main/2023/validation/{file_name}"
170
-
171
 
172
- base_url = "https://huggingface.co/datasets/gaia-benchmark/GAIA/resolve"
173
- commit_hash = "86620fe7a265fdd074ea8d8c8b7a556a1058b0af"
174
- full_url = f"{base_url}/{commit_hash}/2023/validation/{file_name}"
175
 
176
-
177
-
178
  try:
179
- response = requests.get(full_url)
180
  response.raise_for_status()
181
  with open(file_path, "wb") as f:
182
  f.write(response.content)
 
158
 
159
 
160
  def get_or_download_image(file_name: str) -> Image.Image:
161
+ import os
162
+ import requests
163
+ from PIL import Image
164
+ from io import BytesIO
165
+
166
  file_path = os.path.join("data", file_name)
167
+ hf_token = os.getenv("HF_TOKEN_READ")
168
+
169
+ if not hf_token:
170
+ print("[ERRORE] HF_TOKEN_READ non trovato. Imposta la variabile d'ambiente HF_TOKEN_READ.")
171
+ return None
172
 
173
  if not os.path.exists(file_path):
174
  print(f"[INFO] File {file_name} non trovato in /data, lo scarico...")
 
 
175
 
176
+ url = f"https://huggingface.co/datasets/gaia-benchmark/GAIA/resolve/main/2023/validation/{file_name}"
177
+ headers = {"Authorization": f"Bearer {hf_token}"}
 
178
 
 
 
179
  try:
180
+ response = requests.get(url, headers=headers)
181
  response.raise_for_status()
182
  with open(file_path, "wb") as f:
183
  f.write(response.content)