Kackle commited on
Commit
90db266
·
verified ·
1 Parent(s): 335d05f
Files changed (1) hide show
  1. app.py +15 -4
app.py CHANGED
@@ -124,7 +124,7 @@ def check_reasoning(final_answer, agent_memory):
124
  print("Reasoning check failed. Please review the agent's reasoning.")
125
 
126
 
127
- async def run_and_submit_all(profile: gr.OAuthProfile | None):
128
  """
129
  Fetches all questions, runs the BasicAgent on them, submits all answers,
130
  and displays the results asynchronously.
@@ -132,8 +132,14 @@ async def run_and_submit_all(profile: gr.OAuthProfile | None):
132
  # --- Determine HF Space Runtime URL and Repo URL ---
133
  space_id = os.getenv("SPACE_ID") # Get the SPACE_ID for sending link to the code
134
 
 
135
  if profile:
136
- username= f"{profile.username}"
 
 
 
 
 
137
  print(f"User logged in: {username}")
138
  else:
139
  print("User not logged in.")
@@ -214,7 +220,7 @@ async def run_and_submit_all(profile: gr.OAuthProfile | None):
214
  return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
215
 
216
  # 4. Prepare Submission
217
- submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
218
  status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
219
  print(status_update)
220
 
@@ -298,7 +304,12 @@ with gr.Blocks() as demo:
298
  if not profile:
299
  print("No profile available in sync_wrapper")
300
  return "Please Login to Hugging Face with the button.", None
301
- return asyncio.run(run_and_submit_all(profile))
 
 
 
 
 
302
 
303
  run_button.click(
304
  fn=sync_wrapper,
 
124
  print("Reasoning check failed. Please review the agent's reasoning.")
125
 
126
 
127
+ async def run_and_submit_all(profile):
128
  """
129
  Fetches all questions, runs the BasicAgent on them, submits all answers,
130
  and displays the results asynchronously.
 
132
  # --- Determine HF Space Runtime URL and Repo URL ---
133
  space_id = os.getenv("SPACE_ID") # Get the SPACE_ID for sending link to the code
134
 
135
+ # Handle different profile types
136
  if profile:
137
+ if hasattr(profile, 'username'):
138
+ # It's an OAuthProfile object
139
+ username = profile.username
140
+ else:
141
+ # It's a string or other type
142
+ username = str(profile)
143
  print(f"User logged in: {username}")
144
  else:
145
  print("User not logged in.")
 
220
  return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
221
 
222
  # 4. Prepare Submission
223
+ submission_data = {"username": str(username).strip(), "agent_code": agent_code, "answers": answers_payload}
224
  status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
225
  print(status_update)
226
 
 
304
  if not profile:
305
  print("No profile available in sync_wrapper")
306
  return "Please Login to Hugging Face with the button.", None
307
+ print(f"Profile type in wrapper: {type(profile)}")
308
+ try:
309
+ return asyncio.run(run_and_submit_all(profile))
310
+ except Exception as e:
311
+ print(f"Error in sync_wrapper: {e}")
312
+ return f"Error processing request: {e}", None
313
 
314
  run_button.click(
315
  fn=sync_wrapper,