Spaces:
Runtime error
Runtime error
Re-enable certain lines that were disabled for debugging purposes
Browse files
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 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 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 |
-
|
| 96 |
-
|
| 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 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
print("Submission successful.")
|
| 114 |
results_df = pd.DataFrame(results_log)
|
| 115 |
-
return
|
| 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 |
-
|
| 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 |
-
|
|
|
|
| 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)
|