Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -144,7 +144,80 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 144 |
results_log.append({
|
| 145 |
"Task ID": task_id,
|
| 146 |
"Question": item.get("question", ""),
|
| 147 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
|
| 149 |
|
| 150 |
|
|
|
|
| 144 |
results_log.append({
|
| 145 |
"Task ID": task_id,
|
| 146 |
"Question": item.get("question", ""),
|
| 147 |
+
"Submitted Answer": error_msg
|
| 148 |
+
})
|
| 149 |
+
|
| 150 |
+
if not answers_payload:
|
| 151 |
+
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|
| 152 |
+
|
| 153 |
+
submission_data = {
|
| 154 |
+
"username": username.strip(),
|
| 155 |
+
"agent_code": agent_code,
|
| 156 |
+
"answers": answers_payload
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
print(f"Submitting {len(answers_payload)} answers to: {submit_url}")
|
| 160 |
+
try:
|
| 161 |
+
response = requests.post(submit_url, json=submission_data, timeout=60)
|
| 162 |
+
response.raise_for_status()
|
| 163 |
+
result_data = response.json()
|
| 164 |
+
final_status = (
|
| 165 |
+
f"Submission Successful!\n"
|
| 166 |
+
f"User: {result_data.get('username')}\n"
|
| 167 |
+
f"Overall Score: {result_data.get('score', 'N/A')}% "
|
| 168 |
+
f"({result_data.get('correct_count', '?')}/{result_data.get('total_attempted', '?')} correct)\n"
|
| 169 |
+
f"Message: {result_data.get('message', 'No message received.')}"
|
| 170 |
+
)
|
| 171 |
+
results_df = pd.DataFrame(results_log)
|
| 172 |
+
return final_status, results_df
|
| 173 |
+
except requests.exceptions.HTTPError as e:
|
| 174 |
+
try:
|
| 175 |
+
detail = e.response.json().get("detail", e.response.text)
|
| 176 |
+
except Exception:
|
| 177 |
+
detail = e.response.text[:500]
|
| 178 |
+
return f"Submission Failed: {detail}", pd.DataFrame(results_log)
|
| 179 |
+
except requests.exceptions.Timeout:
|
| 180 |
+
return "Submission Failed: The request timed out.", pd.DataFrame(results_log)
|
| 181 |
+
except Exception as e:
|
| 182 |
+
return f"An unexpected error occurred during submission: {e}", pd.DataFrame(results_log)
|
| 183 |
+
|
| 184 |
+
# Gradio UI
|
| 185 |
+
with gr.Blocks() as demo:
|
| 186 |
+
gr.Markdown("# Basic Agent Evaluation Runner")
|
| 187 |
+
gr.Markdown("""
|
| 188 |
+
**Instructions:**
|
| 189 |
+
1. Clone this space and define your agent and tools.
|
| 190 |
+
2. Log in to your Hugging Face account using the button below.
|
| 191 |
+
3. Click 'Run Evaluation & Submit All Answers' to test your agent and submit results.
|
| 192 |
+
""")
|
| 193 |
+
|
| 194 |
+
gr.LoginButton()
|
| 195 |
+
run_button = gr.Button("Run Evaluation & Submit All Answers")
|
| 196 |
+
|
| 197 |
+
status_output = gr.Textbox(label="Run Status / Submission Result", lines=5, interactive=False)
|
| 198 |
+
results_table = gr.DataFrame(label="Questions and Agent Answers", wrap=True)
|
| 199 |
+
|
| 200 |
+
run_button.click(fn=run_and_submit_all, outputs=[status_output, results_table])
|
| 201 |
+
|
| 202 |
+
if __name__ == "__main__":
|
| 203 |
+
print("\n" + "-"*30 + " App Starting " + "-"*30)
|
| 204 |
+
space_host = os.getenv("SPACE_HOST")
|
| 205 |
+
space_id = os.getenv("SPACE_ID")
|
| 206 |
+
|
| 207 |
+
if space_host:
|
| 208 |
+
print(f"✅ SPACE_HOST found: {space_host}")
|
| 209 |
+
print(f" Runtime URL should be: https://{space_host}.hf.space")
|
| 210 |
+
else:
|
| 211 |
+
print("ℹ️ SPACE_HOST not found.")
|
| 212 |
+
|
| 213 |
+
if space_id:
|
| 214 |
+
print(f"✅ SPACE_ID found: {space_id}")
|
| 215 |
+
print(f" Repo URL: https://huggingface.co/spaces/{space_id}")
|
| 216 |
+
else:
|
| 217 |
+
print("ℹ️ SPACE_ID not found.")
|
| 218 |
+
|
| 219 |
+
print("-"*(60 + len(" App Starting ")) + "\n")
|
| 220 |
+
demo.launch(debug=True, share=False)
|
| 221 |
|
| 222 |
|
| 223 |
|