msanton commited on
Commit
507af88
·
verified ·
1 Parent(s): 6b2d642

Re-enable certain lines that were disabled for debugging purposes

Browse files
Files changed (1) hide show
  1. app.py +21 -25
app.py CHANGED
@@ -26,13 +26,12 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
26
  # --- Determine HF Space Runtime URL and Repo URL ---
27
  space_id = os.getenv("SPACE_ID") # Get the SPACE_ID for sending link to the code
28
 
29
- #if profile:
30
- # username= f"{profile.username}"
31
- # print(f"User logged in: {username}")
32
- #else:
33
- # print("User not logged in.")
34
- #username = "test"
35
- # return "Please Login to Hugging Face with the button.", None
36
 
37
  api_url = DEFAULT_API_URL
38
  questions_url = f"{api_url}/questions"
@@ -92,27 +91,26 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
92
  return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
93
 
94
  # 4. Prepare Submission
95
- #submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
96
- #status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
97
- status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user 'test'..."
98
  print(status_update)
99
 
100
  # 5. Submit
101
  print(f"Submitting {len(answers_payload)} answers to: {submit_url}")
102
  try:
103
- #response = requests.post(submit_url, json=submission_data, timeout=60)
104
- #response.raise_for_status()
105
- #result_data = response.json()
106
- #final_status = (
107
- # f"Submission Successful!\n"
108
- # f"User: {result_data.get('username')}\n"
109
- # f"Overall Score: {result_data.get('score', 'N/A')}% "
110
- # f"({result_data.get('correct_count', '?')}/{result_data.get('total_attempted', '?')} correct)\n"
111
- # f"Message: {result_data.get('message', 'No message received.')}"
112
- #)
113
  print("Submission successful.")
114
  results_df = pd.DataFrame(results_log)
115
- return "final_status", results_df
116
  except requests.exceptions.HTTPError as e:
117
  error_detail = f"Server responded with status {e.response.status_code}."
118
  try:
@@ -142,7 +140,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
142
 
143
 
144
  # --- Build Gradio Interface using Blocks ---
145
- #with gr.Blocks() as demo:
146
  gr.Markdown("# Basic Agent Evaluation Runner")
147
  gr.Markdown(
148
  """
@@ -178,8 +176,6 @@ if __name__ == "__main__":
178
  space_host_startup = os.getenv("SPACE_HOST")
179
  space_id_startup = os.getenv("SPACE_ID") # Get SPACE_ID at startup
180
 
181
- run_and_submit_all(None)
182
-
183
  if space_host_startup:
184
  print(f"✅ SPACE_HOST found: {space_host_startup}")
185
  print(f" Runtime URL should be: https://{space_host_startup}.hf.space")
@@ -196,4 +192,4 @@ if __name__ == "__main__":
196
  print("-"*(60 + len(" App Starting ")) + "\n")
197
 
198
  print("Launching Gradio Interface for Basic Agent Evaluation...")
199
- #demo.launch(debug=True, share=False)
 
26
  # --- Determine HF Space Runtime URL and Repo URL ---
27
  space_id = os.getenv("SPACE_ID") # Get the SPACE_ID for sending link to the code
28
 
29
+ if profile:
30
+ username= f"{profile.username}"
31
+ print(f"User logged in: {username}")
32
+ else:
33
+ print("User not logged in.")
34
+ return "Please Login to Hugging Face with the button.", None
 
35
 
36
  api_url = DEFAULT_API_URL
37
  questions_url = f"{api_url}/questions"
 
91
  return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
92
 
93
  # 4. Prepare Submission
94
+ submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
95
+ status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
 
96
  print(status_update)
97
 
98
  # 5. Submit
99
  print(f"Submitting {len(answers_payload)} answers to: {submit_url}")
100
  try:
101
+ response = requests.post(submit_url, json=submission_data, timeout=60)
102
+ response.raise_for_status()
103
+ result_data = response.json()
104
+ final_status = (
105
+ f"Submission Successful!\n"
106
+ f"User: {result_data.get('username')}\n"
107
+ f"Overall Score: {result_data.get('score', 'N/A')}% "
108
+ f"({result_data.get('correct_count', '?')}/{result_data.get('total_attempted', '?')} correct)\n"
109
+ f"Message: {result_data.get('message', 'No message received.')}"
110
+ )
111
  print("Submission successful.")
112
  results_df = pd.DataFrame(results_log)
113
+ return final_status, results_df
114
  except requests.exceptions.HTTPError as e:
115
  error_detail = f"Server responded with status {e.response.status_code}."
116
  try:
 
140
 
141
 
142
  # --- Build Gradio Interface using Blocks ---
143
+ with gr.Blocks() as demo:
144
  gr.Markdown("# Basic Agent Evaluation Runner")
145
  gr.Markdown(
146
  """
 
176
  space_host_startup = os.getenv("SPACE_HOST")
177
  space_id_startup = os.getenv("SPACE_ID") # Get SPACE_ID at startup
178
 
 
 
179
  if space_host_startup:
180
  print(f"✅ SPACE_HOST found: {space_host_startup}")
181
  print(f" Runtime URL should be: https://{space_host_startup}.hf.space")
 
192
  print("-"*(60 + len(" App Starting ")) + "\n")
193
 
194
  print("Launching Gradio Interface for Basic Agent Evaluation...")
195
+ demo.launch(debug=True, share=False)