FD900 commited on
Commit
0617575
·
verified ·
1 Parent(s): 576dbe1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -8
app.py CHANGED
@@ -6,29 +6,35 @@ import requests
6
  from agent import solve_task, load_tasks
7
  from mistral_hf_wrapper import MistralInference
8
 
9
- # Load from environment variables
10
  API_URL = os.getenv("HF_MISTRAL_ENDPOINT")
11
  API_TOKEN = os.getenv("HF_TOKEN")
12
  USERNAME = os.getenv("HF_USERNAME")
13
  CODE_LINK = os.getenv("HF_CODE_LINK")
14
 
15
- # Launches agent to solve all tasks and submits to GAIA
16
  def run_and_submit_all():
17
  model = MistralInference(api_url=API_URL, api_token=API_TOKEN)
18
  tasks = load_tasks()
19
- answers = []
20
 
 
 
 
 
21
  for task in tasks:
22
  try:
23
  result = solve_task(task, model)
 
 
24
  answers.append(result)
25
  except Exception as e:
26
  answers.append({
27
- "task_id": task.get("question_id", "unknown"),
28
  "submitted_answer": f"ERROR: {str(e)}"
29
  })
30
- print("Total answers generated:", len(answers)) #temp
31
- # Submit results to GAIA benchmark API
 
 
 
32
  res = requests.post(
33
  "https://agents-course-unit4-scoring.hf.space/submit",
34
  headers={"Content-Type": "application/json"},
@@ -41,8 +47,7 @@ def run_and_submit_all():
41
 
42
  if res.ok:
43
  return json.dumps(res.json(), indent=2)
44
- else:
45
- return f"Error submitting: {res.status_code} - {res.text}"
46
 
47
  # Gradio interface
48
  gr.Interface(
 
6
  from agent import solve_task, load_tasks
7
  from mistral_hf_wrapper import MistralInference
8
 
 
9
  API_URL = os.getenv("HF_MISTRAL_ENDPOINT")
10
  API_TOKEN = os.getenv("HF_TOKEN")
11
  USERNAME = os.getenv("HF_USERNAME")
12
  CODE_LINK = os.getenv("HF_CODE_LINK")
13
 
 
14
  def run_and_submit_all():
15
  model = MistralInference(api_url=API_URL, api_token=API_TOKEN)
16
  tasks = load_tasks()
 
17
 
18
+ if not tasks:
19
+ return "No tasks loaded from metadata.jsonl. Make sure the file exists and is valid."
20
+
21
+ answers = []
22
  for task in tasks:
23
  try:
24
  result = solve_task(task, model)
25
+ if not result.get("submitted_answer"): # Check empty responses
26
+ result["submitted_answer"] = "ERROR: Empty model response"
27
  answers.append(result)
28
  except Exception as e:
29
  answers.append({
30
+ "task_id": task.get("question_id", "UNKNOWN"),
31
  "submitted_answer": f"ERROR: {str(e)}"
32
  })
33
+
34
+ # Debug: check if answers are constructed correctly
35
+ if not answers:
36
+ return " No answers generated. Check model response."
37
+
38
  res = requests.post(
39
  "https://agents-course-unit4-scoring.hf.space/submit",
40
  headers={"Content-Type": "application/json"},
 
47
 
48
  if res.ok:
49
  return json.dumps(res.json(), indent=2)
50
+ return f"Error submitting: {res.status_code} - {res.text}"
 
51
 
52
  # Gradio interface
53
  gr.Interface(