SergeyO7 commited on
Commit
089f46d
·
verified ·
1 Parent(s): 6b6b147

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -2
app.py CHANGED
@@ -149,6 +149,7 @@ async def run_and_submit_all(profile: gr.OAuthProfile | None):
149
  Fetches all questions asynchronously, runs the MagAgent on them, submits all answers,
150
  and displays the results.
151
  """
 
152
  space_id = os.getenv("SPACE_ID")
153
 
154
  if profile:
@@ -162,6 +163,7 @@ async def run_and_submit_all(profile: gr.OAuthProfile | None):
162
  questions_url = f"{api_url}/questions"
163
  submit_url = f"{api_url}/submit"
164
 
 
165
  try:
166
  agent = MagAgent(rate_limiter=token_bucket)
167
  except Exception as e:
@@ -171,6 +173,7 @@ async def run_and_submit_all(profile: gr.OAuthProfile | None):
171
  agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
172
  print(agent_code)
173
 
 
174
  async with aiohttp.ClientSession() as session:
175
  questions_data = await fetch_questions(session, questions_url)
176
  if questions_data is None:
@@ -178,6 +181,8 @@ async def run_and_submit_all(profile: gr.OAuthProfile | None):
178
  if not questions_data:
179
  return "Fetched questions list is empty or invalid format.", None
180
 
 
 
181
  results_log = []
182
  answers_payload = []
183
  print(f"Running agent on {len(questions_data)} questions...")
@@ -194,13 +199,14 @@ async def run_and_submit_all(profile: gr.OAuthProfile | None):
194
  if result:
195
  answers_payload.append(result)
196
  else:
197
- print(f"Skipping not related question: {task_id}")
198
  results_log.append({
199
  "Task ID": task_id,
200
  "Question": question_text,
201
  "Submitted Answer": "Question skipped - not related"
202
  })
203
-
 
204
  if not answers_payload:
205
  print("Agent did not produce any answers to submit.")
206
  return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
 
149
  Fetches all questions asynchronously, runs the MagAgent on them, submits all answers,
150
  and displays the results.
151
  """
152
+ # --- Determine HF Space Runtime URL and Repo URL ---
153
  space_id = os.getenv("SPACE_ID")
154
 
155
  if profile:
 
163
  questions_url = f"{api_url}/questions"
164
  submit_url = f"{api_url}/submit"
165
 
166
+ # 1. Instantiate Agent
167
  try:
168
  agent = MagAgent(rate_limiter=token_bucket)
169
  except Exception as e:
 
173
  agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
174
  print(agent_code)
175
 
176
+ # 2. Fetch Questions Asynchronously
177
  async with aiohttp.ClientSession() as session:
178
  questions_data = await fetch_questions(session, questions_url)
179
  if questions_data is None:
 
181
  if not questions_data:
182
  return "Fetched questions list is empty or invalid format.", None
183
 
184
+ # 3. Run Agent on Questions
185
+ # Process questions sequentially with rate limiting
186
  results_log = []
187
  answers_payload = []
188
  print(f"Running agent on {len(questions_data)} questions...")
 
199
  if result:
200
  answers_payload.append(result)
201
  else:
202
+ print(f"Skipping not related question")
203
  results_log.append({
204
  "Task ID": task_id,
205
  "Question": question_text,
206
  "Submitted Answer": "Question skipped - not related"
207
  })
208
+ # await asyncio.sleep(30)
209
+
210
  if not answers_payload:
211
  print("Agent did not produce any answers to submit.")
212
  return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)