update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,10 @@ import inspect
|
|
| 5 |
import pandas as pd
|
| 6 |
from langchain_core.messages import HumanMessage
|
| 7 |
from agent import build_graph
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
# (Keep Constants as is)
|
| 10 |
# --- Constants ---
|
|
@@ -25,6 +29,29 @@ class BasicAgent:
|
|
| 25 |
print(f"Agent returning answer: {answer}")
|
| 26 |
return answer
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 30 |
"""
|
|
@@ -90,7 +117,12 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 90 |
continue
|
| 91 |
|
| 92 |
if file_name:
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
try:
|
| 95 |
submitted_answer = agent(question_text)
|
| 96 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
|
|
|
| 5 |
import pandas as pd
|
| 6 |
from langchain_core.messages import HumanMessage
|
| 7 |
from agent import build_graph
|
| 8 |
+
from huggingface_hub import hf_hub_download
|
| 9 |
+
import logging
|
| 10 |
+
|
| 11 |
+
logger = logging.getLogger(__name__)
|
| 12 |
|
| 13 |
# (Keep Constants as is)
|
| 14 |
# --- Constants ---
|
|
|
|
| 29 |
print(f"Agent returning answer: {answer}")
|
| 30 |
return answer
|
| 31 |
|
| 32 |
+
def file_extract(local_file_path, task_id):
|
| 33 |
+
if not local_file_path:
|
| 34 |
+
return None
|
| 35 |
+
|
| 36 |
+
token = os.getenv("HUGGINGFACEHUB_API_TOKEN") or os.getenv("HF_TOKEN")
|
| 37 |
+
|
| 38 |
+
# GAIA files are usually placed in date-based subdirectories
|
| 39 |
+
prefixes = ["2023/validation/", "2023/test/", "2023/train/", ""]
|
| 40 |
+
|
| 41 |
+
for prefix in prefixes:
|
| 42 |
+
try:
|
| 43 |
+
resolved_path = hf_hub_download(
|
| 44 |
+
repo_id="gaia-benchmark/GAIA",
|
| 45 |
+
filename=f"{prefix}{local_file_path}",
|
| 46 |
+
repo_type="dataset",
|
| 47 |
+
token=token
|
| 48 |
+
)
|
| 49 |
+
return resolved_path
|
| 50 |
+
except Exception:
|
| 51 |
+
continue
|
| 52 |
+
|
| 53 |
+
logger.warning(f"Could not download file '{local_file_path}' for task_id {task_id}. Make sure you accepted GAIA terms on HF and set HF_TOKEN.")
|
| 54 |
+
return None
|
| 55 |
|
| 56 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 57 |
"""
|
|
|
|
| 117 |
continue
|
| 118 |
|
| 119 |
if file_name:
|
| 120 |
+
# Actually download the file to local cache and get absolute path
|
| 121 |
+
resolved_path = file_extract(file_name, task_id)
|
| 122 |
+
if resolved_path:
|
| 123 |
+
question_text += f"\n\n[Attached File Local Path: {resolved_path}]"
|
| 124 |
+
else:
|
| 125 |
+
question_text += f"\n\n[Attached File: {file_name} (Download Failed)]"
|
| 126 |
try:
|
| 127 |
submitted_answer = agent(question_text)
|
| 128 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|