Annessha18 commited on
Commit
cee66e6
·
verified ·
1 Parent(s): d3caa42

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -18
app.py CHANGED
@@ -72,9 +72,9 @@ class BasicAgent:
72
  # GAIA RUN + SUBMIT
73
  # -----------------------------
74
  def run_and_submit_all(profile):
75
- # Check if logged in
76
- if profile is None or "username" not in profile:
77
- return "Please login to Hugging Face", pd.DataFrame()
78
 
79
  username = profile["username"]
80
  space_id = os.getenv("SPACE_ID", "Annessha18/gaia-agent")
@@ -86,12 +86,13 @@ def run_and_submit_all(profile):
86
 
87
  agent = BasicAgent()
88
 
 
89
  try:
90
  response = requests.get(questions_url, timeout=15)
91
  response.raise_for_status()
92
  questions = response.json()
93
  except Exception as e:
94
- return f"Error fetching questions: {e}", pd.DataFrame()
95
 
96
  answers = []
97
  log = []
@@ -100,15 +101,8 @@ def run_and_submit_all(profile):
100
  task_id = q.get("task_id", "unknown")
101
  question_text = q.get("question", "")
102
  answer = agent(question_text)
103
- answers.append({
104
- "task_id": task_id,
105
- "submitted_answer": answer
106
- })
107
- log.append({
108
- "Task ID": task_id,
109
- "Question": question_text,
110
- "Answer": answer
111
- })
112
 
113
  payload = {
114
  "username": username,
@@ -116,19 +110,20 @@ def run_and_submit_all(profile):
116
  "answers": answers
117
  }
118
 
 
119
  try:
120
  response = requests.post(submit_url, json=payload, timeout=30)
121
  response.raise_for_status()
122
  result = response.json()
123
  status = (
124
- f"Submission Successful!\n"
125
  f"User: {result.get('username')}\n"
126
  f"Score: {result.get('score')}%\n"
127
  f"Correct: {result.get('correct_count')}/{result.get('total_attempted')}\n"
128
  f"Message: {result.get('message')}"
129
  )
130
  except Exception as e:
131
- status = f"Submission Failed: {e}"
132
 
133
  return status, pd.DataFrame(log)
134
 
@@ -138,13 +133,16 @@ def run_and_submit_all(profile):
138
  with gr.Blocks() as demo:
139
  gr.Markdown("# 🤖 GAIA Level 1 Agent")
140
 
 
141
  login_btn = gr.LoginButton(label="Login to Hugging Face")
142
  run_btn = gr.Button("Run Evaluation & Submit All Answers")
143
-
144
  status_out = gr.Textbox(label="Submission Result", lines=5)
145
  table_out = gr.Dataframe(label="Questions and Answers")
146
 
147
- # login_btn returns a dictionary, pass it as input
148
- run_btn.click(run_and_submit_all, inputs=[login_btn], outputs=[status_out, table_out])
 
 
 
149
 
150
  demo.launch()
 
72
  # GAIA RUN + SUBMIT
73
  # -----------------------------
74
  def run_and_submit_all(profile):
75
+ # Check login
76
+ if not profile or "username" not in profile:
77
+ return "⚠️ Please login to Hugging Face", pd.DataFrame()
78
 
79
  username = profile["username"]
80
  space_id = os.getenv("SPACE_ID", "Annessha18/gaia-agent")
 
86
 
87
  agent = BasicAgent()
88
 
89
+ # Fetch questions
90
  try:
91
  response = requests.get(questions_url, timeout=15)
92
  response.raise_for_status()
93
  questions = response.json()
94
  except Exception as e:
95
+ return f"Error fetching questions: {e}", pd.DataFrame()
96
 
97
  answers = []
98
  log = []
 
101
  task_id = q.get("task_id", "unknown")
102
  question_text = q.get("question", "")
103
  answer = agent(question_text)
104
+ answers.append({"task_id": task_id, "submitted_answer": answer})
105
+ log.append({"Task ID": task_id, "Question": question_text, "Answer": answer})
 
 
 
 
 
 
 
106
 
107
  payload = {
108
  "username": username,
 
110
  "answers": answers
111
  }
112
 
113
+ # Submit answers
114
  try:
115
  response = requests.post(submit_url, json=payload, timeout=30)
116
  response.raise_for_status()
117
  result = response.json()
118
  status = (
119
+ f"Submission Successful!\n"
120
  f"User: {result.get('username')}\n"
121
  f"Score: {result.get('score')}%\n"
122
  f"Correct: {result.get('correct_count')}/{result.get('total_attempted')}\n"
123
  f"Message: {result.get('message')}"
124
  )
125
  except Exception as e:
126
+ status = f"Submission Failed: {e}"
127
 
128
  return status, pd.DataFrame(log)
129
 
 
133
  with gr.Blocks() as demo:
134
  gr.Markdown("# 🤖 GAIA Level 1 Agent")
135
 
136
+ # Login button
137
  login_btn = gr.LoginButton(label="Login to Hugging Face")
138
  run_btn = gr.Button("Run Evaluation & Submit All Answers")
 
139
  status_out = gr.Textbox(label="Submission Result", lines=5)
140
  table_out = gr.Dataframe(label="Questions and Answers")
141
 
142
+ # Wrap login profile to avoid runtime error
143
+ def wrapped_submit(profile):
144
+ return run_and_submit_all(profile)
145
+
146
+ run_btn.click(wrapped_submit, inputs=[login_btn], outputs=[status_out, table_out])
147
 
148
  demo.launch()