Paperbag commited on
Commit
f0a6306
·
1 Parent(s): 0b75753

trying to extract file

Browse files
Files changed (1) hide show
  1. app copy.py +29 -1
app copy.py CHANGED
@@ -5,6 +5,8 @@ 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 ---
@@ -22,8 +24,28 @@ class BasicAgent:
22
  messages = [HumanMessage(content=question)]
23
  result = self.graph.invoke({"messages": messages})
24
  answer = result['messages'][-1].content
25
- print(f"Agent returning answer: {answer}")
26
  return answer
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
  agent = BasicAgent()
29
  questions_url = f"{DEFAULT_API_URL}/questions"
@@ -34,12 +56,18 @@ for item in questions_data[:5]:
34
  question_text = item.get("question")
35
  if question_text is None:
36
  continue
 
 
 
 
37
  output = agent(question_text)
38
  print("Q:", question_text)
39
  print("A:", output)
40
  print("-" * 40)
41
 
42
 
 
 
43
  # def run_and_submit_all( profile: gr.OAuthProfile | None):
44
  # """
45
  # Fetches all questions, runs the BasicAgent on them, submits all answers,
 
5
  import pandas as pd
6
  from langchain_core.messages import HumanMessage
7
  from agent import build_graph
8
+ from huggingface_hub import HfApi, hf_hub_download
9
+ from logging import logger
10
 
11
  # (Keep Constants as is)
12
  # --- Constants ---
 
24
  messages = [HumanMessage(content=question)]
25
  result = self.graph.invoke({"messages": messages})
26
  answer = result['messages'][-1].content
 
27
  return answer
28
+
29
+ def file_extract(local_file_path,task_file_paths):
30
+ if local_file_path:
31
+ try:
32
+ # GAIA's file_path is relative to the dataset repo root.
33
+ # Download the file into the allowed cache and get its local path.
34
+ resolved_path = hf_hub_download(
35
+ repo_id="gaia-benchmark/GAIA",
36
+ filename=local_file_path, # e.g. "2023/test/<attachment-id>.pdf"
37
+ repo_type="dataset",
38
+ )
39
+
40
+ task_file_paths[str(task_id)] = resolved_path
41
+ logger.debug(
42
+ f"Stored file path mapping for task_id {task_id}: {resolved_path}"
43
+ )
44
+ except Exception as e:
45
+ logger.warning(
46
+ f"Could not download file '{local_file_path}' for task_id {task_id}: {e}. "
47
+ "Mapping skipped."
48
+ )
49
 
50
  agent = BasicAgent()
51
  questions_url = f"{DEFAULT_API_URL}/questions"
 
56
  question_text = item.get("question")
57
  if question_text is None:
58
  continue
59
+ files_text = item.get("files")
60
+ task_id = item.get("task_id")
61
+ # file = file_extract(,task_id)
62
+ print(files_text,task_id)
63
  output = agent(question_text)
64
  print("Q:", question_text)
65
  print("A:", output)
66
  print("-" * 40)
67
 
68
 
69
+
70
+
71
  # def run_and_submit_all( profile: gr.OAuthProfile | None):
72
  # """
73
  # Fetches all questions, runs the BasicAgent on them, submits all answers,