Spaces:
Runtime error
Runtime error
trying things
Browse files
app.py
CHANGED
@@ -179,60 +179,36 @@ class BasicAgent:
|
|
179 |
|
180 |
# --- Evaluation Logic ---
|
181 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
182 |
-
|
183 |
-
if profile:
|
184 |
-
username = profile.username
|
185 |
-
print(f"User logged in: {username}")
|
186 |
-
else:
|
187 |
-
return "Please Login to Hugging Face with the button.", None
|
188 |
-
|
189 |
-
api_url = DEFAULT_API_URL
|
190 |
-
questions_url = f"{api_url}/questions"
|
191 |
-
submit_url = f"{api_url}/submit"
|
192 |
-
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
193 |
-
|
194 |
try:
|
195 |
agent = BasicAgent()
|
|
|
196 |
except Exception as e:
|
|
|
197 |
return f"Error initializing agent: {e}", None
|
198 |
|
199 |
-
|
200 |
-
response = requests.get(questions_url, timeout=15)
|
201 |
-
response.raise_for_status()
|
202 |
-
questions_data = response.json()
|
203 |
-
if not questions_data:
|
204 |
-
return "Fetched questions list is empty or invalid format.", None
|
205 |
-
except Exception as e:
|
206 |
-
return f"Error fetching questions: {e}", None
|
207 |
-
|
208 |
-
results_log = []
|
209 |
-
answers_payload = []
|
210 |
-
|
211 |
for item in questions_data:
|
212 |
task_id = item.get("task_id")
|
213 |
question_text = item.get("question")
|
214 |
if not task_id or question_text is None:
|
|
|
215 |
continue
|
216 |
try:
|
217 |
submitted_answer = agent(question_text)
|
|
|
218 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
219 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
220 |
except Exception as e:
|
|
|
221 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
|
222 |
|
223 |
-
|
224 |
-
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|
225 |
-
|
226 |
-
submission_data = {
|
227 |
-
"username": username.strip(),
|
228 |
-
"agent_code": agent_code,
|
229 |
-
"answers": answers_payload
|
230 |
-
}
|
231 |
-
|
232 |
try:
|
233 |
response = requests.post(submit_url, json=submission_data, timeout=60)
|
234 |
response.raise_for_status()
|
235 |
result_data = response.json()
|
|
|
236 |
final_status = (
|
237 |
f"Submission Successful!\n"
|
238 |
f"User: {result_data.get('username')}\n"
|
@@ -242,25 +218,5 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
242 |
)
|
243 |
return final_status, pd.DataFrame(results_log)
|
244 |
except Exception as e:
|
245 |
-
|
246 |
-
|
247 |
-
# --- Gradio UI ---
|
248 |
-
with gr.Blocks() as demo:
|
249 |
-
gr.Markdown("# Basic Agent Evaluation Runner")
|
250 |
-
gr.Markdown(
|
251 |
-
"""
|
252 |
-
**Instructions:**
|
253 |
-
1. Clone and customize your agent logic.
|
254 |
-
2. Log in with Hugging Face.
|
255 |
-
3. Click the button to run evaluation and submit your answers.
|
256 |
-
"""
|
257 |
-
)
|
258 |
-
gr.LoginButton()
|
259 |
-
run_button = gr.Button("Run Evaluation & Submit All Answers")
|
260 |
-
status_output = gr.Textbox(label="Run Status / Submission Result", lines=5, interactive=False)
|
261 |
-
results_table = gr.DataFrame(label="Questions and Agent Answers", wrap=True)
|
262 |
-
run_button.click(fn=run_and_submit_all, outputs=[status_output, results_table])
|
263 |
-
|
264 |
-
if __name__ == "__main__":
|
265 |
-
print("Launching Gradio Interface...")
|
266 |
-
demo.launch(debug=True, share=False)
|
|
|
179 |
|
180 |
# --- Evaluation Logic ---
|
181 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
182 |
+
#...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
183 |
try:
|
184 |
agent = BasicAgent()
|
185 |
+
print("Agent initialized successfully.")
|
186 |
except Exception as e:
|
187 |
+
print(f"Error initializing agent: {e}")
|
188 |
return f"Error initializing agent: {e}", None
|
189 |
|
190 |
+
#...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
191 |
for item in questions_data:
|
192 |
task_id = item.get("task_id")
|
193 |
question_text = item.get("question")
|
194 |
if not task_id or question_text is None:
|
195 |
+
print(f"Invalid question: {item}")
|
196 |
continue
|
197 |
try:
|
198 |
submitted_answer = agent(question_text)
|
199 |
+
print(f"Submitted answer for task {task_id}: {submitted_answer}")
|
200 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
201 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
202 |
except Exception as e:
|
203 |
+
print(f"Error processing question {task_id}: {e}")
|
204 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
|
205 |
|
206 |
+
#...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
207 |
try:
|
208 |
response = requests.post(submit_url, json=submission_data, timeout=60)
|
209 |
response.raise_for_status()
|
210 |
result_data = response.json()
|
211 |
+
print(f"Submission response: {result_data}")
|
212 |
final_status = (
|
213 |
f"Submission Successful!\n"
|
214 |
f"User: {result_data.get('username')}\n"
|
|
|
218 |
)
|
219 |
return final_status, pd.DataFrame(results_log)
|
220 |
except Exception as e:
|
221 |
+
print(f"Submission failed: {e}")
|
222 |
+
return f"Submission failed: {e}", pd.DataFrame(results_log)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|