Update app.py
Browse files
app.py
CHANGED
|
@@ -65,7 +65,9 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 65 |
results_log = []
|
| 66 |
answers_payload = []
|
| 67 |
print(f"Running agent on {len(questions_data)} questions...")
|
| 68 |
-
|
|
|
|
|
|
|
| 69 |
print(f"ITEMS {item}")
|
| 70 |
task_id = item.get("task_id")
|
| 71 |
question_text = item.get("question")
|
|
@@ -74,20 +76,18 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 74 |
file_path = ""
|
| 75 |
|
| 76 |
if file_name:
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
# save images/videos/audio locally if needed
|
| 84 |
-
file_content = response.content
|
| 85 |
-
os.makedirs("./files, exist_ok= True")
|
| 86 |
-
file_path = f"./files/{file_name}"
|
| 87 |
-
with open(file_path, "wb") as f:
|
| 88 |
-
f.write(response.content)
|
| 89 |
else:
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
if not task_id or question_text is None:
|
| 92 |
print(f"Skipping item with missing task_id or question: {item}")
|
| 93 |
continue
|
|
@@ -189,6 +189,16 @@ if __name__ == "__main__":
|
|
| 189 |
space_host_startup = os.getenv("SPACE_HOST")
|
| 190 |
space_id_startup = os.getenv("SPACE_ID") # Get SPACE_ID at startup
|
| 191 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
if space_host_startup:
|
| 193 |
print(f"✅ SPACE_HOST found: {space_host_startup}")
|
| 194 |
print(f" Runtime URL should be: https://{space_host_startup}.hf.space")
|
|
|
|
| 65 |
results_log = []
|
| 66 |
answers_payload = []
|
| 67 |
print(f"Running agent on {len(questions_data)} questions...")
|
| 68 |
+
files_base = os.path.join(data_dir, "2023", "test")
|
| 69 |
+
subset = dataset.select(range(20))
|
| 70 |
+
for item in subset:
|
| 71 |
print(f"ITEMS {item}")
|
| 72 |
task_id = item.get("task_id")
|
| 73 |
question_text = item.get("question")
|
|
|
|
| 76 |
file_path = ""
|
| 77 |
|
| 78 |
if file_name:
|
| 79 |
+
file_path = os.path.join(files_base, file_name)
|
| 80 |
+
|
| 81 |
+
# Decide binary or text
|
| 82 |
+
if file_name.endswith((".txt", ".py", ".csv", ".json")):
|
| 83 |
+
with open(file_path, "r", encoding="utf-8") as f:
|
| 84 |
+
file_content = f.read()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
else:
|
| 86 |
+
with open(file_path, "rb") as f:
|
| 87 |
+
file_content = f.read()
|
| 88 |
+
|
| 89 |
+
else:
|
| 90 |
+
print(f"File not found: {file_url} (status {response.status_code})")
|
| 91 |
if not task_id or question_text is None:
|
| 92 |
print(f"Skipping item with missing task_id or question: {item}")
|
| 93 |
continue
|
|
|
|
| 189 |
space_host_startup = os.getenv("SPACE_HOST")
|
| 190 |
space_id_startup = os.getenv("SPACE_ID") # Get SPACE_ID at startup
|
| 191 |
|
| 192 |
+
data_dir = snapshot_download(
|
| 193 |
+
repo_id="gaia-benchmark/GAIA",
|
| 194 |
+
repo_type="dataset"
|
| 195 |
+
)
|
| 196 |
+
|
| 197 |
+
dataset = load_dataset(data_dir, "2023_level1", split="test")
|
| 198 |
+
print("Dataset", dataset)
|
| 199 |
+
print(len(dataset))
|
| 200 |
+
print(type(dataset))
|
| 201 |
+
|
| 202 |
if space_host_startup:
|
| 203 |
print(f"✅ SPACE_HOST found: {space_host_startup}")
|
| 204 |
print(f" Runtime URL should be: https://{space_host_startup}.hf.space")
|