Spaces:
Sleeping
Sleeping
Update app.py
Browse files1234568 unmodified lines151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859import osimport gradio as grimport pandas as pdfrom langchain_core.messages import HumanMessagefrom graph_builder import build_graphfrom api_client import fetch_questions, submit_answers8 unmodified linesreturn result_state["final_answer"]def run_and_submit_all(profile):space_id = os.getenv("SPACE_ID")username = profile.username if profile else Noneif not username:return "Please log in to Hugging Face.", Noneagent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"agent = GaiaAgent()questions_data = fetch_questions()answers_payload = []results_log = []for item in questions_data:task_id = item["task_id"]question = item["question"]answer = agent(question)answers_payload.append({"task_id": task_id, "submitted_answer": answer})results_log.append({"Task ID": task_id, "Question": question, "Submitted Answer": answer})result = submit_answers(username, agent_code, answers_payload)final_status = f"Submission Successful!\nUser: {result.get('username')}\nScore: {result.get('score')}%\nCorrect: {result.get('correct_count')}/{result.get('total_attempted')}\nMessage: {result.get('message', '')}"return final_status, pd.DataFrame(results_log)with gr.Blocks() as demo:gr.Markdown("# GAIA LangGraph Agent")gr.Markdown("Log in and run your agent to evaluate on GAIA benchmark.")login_button = gr.LoginButton()run_button = gr.Button("Run Evaluation & Submit All Answers")status_output = gr.Textbox(label="Run Status", lines=5)results_table = gr.DataFrame(label="Results")run_button.click(fn=run_and_submit_all,inputs=[login_button],outputs=[status_output, results_table])if __name__ == "__main__":demo.launch()12345678 unmodified lines16171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879import osimport gradio as grimport pandas as pdimport tracebackfrom langchain_core.messages import HumanMessagefrom graph_builder import build_graphfrom api_client import fetch_questions, submit_answers8 unmodified linesreturn result_state["final_answer"]def run_and_submit_all(profile):try:space_id = os.getenv("SPACE_ID")username = profile.username if profile else Noneif not username:return "❌ Please log in to Hugging Face.", Noneagent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"agent = GaiaAgent()questions_data = fetch_questions()if not questions_data:return "❌ No questions retrieved from GAIA API.", Noneanswers_payload = []results_log = []for item in questions_data:task_id = item["task_id"]question = item["question"]answer = agent(question)answers_payload.append({"task_id": task_id, "submitted_answer": answer})results_log.append({"Task ID": task_id,"Question": question,"Submitted Answer": answer})result = submit_answers(username, agent_code, answers_payload)final_status = (f"✅ Submission Successful!\n"f"User: {result.get('username')}\n"f"Score: {result.get('score')}%\n"f"Correct: {result.get('correct_count')}/{result.get('total_attempted')}\n"f"Message: {result.get('message', '')}")return final_status, pd.DataFrame(results_log)except Exception as e:error_message = (f"❌ An error occurred:\n{str(e)}\n\n"f"Traceback:\n{traceback.format_exc()}")return error_message, Nonewith gr.Blocks() as demo:gr.Markdown("# 🤖 GAIA LangGraph Agent")gr.Markdown("Log in and run your agent to evaluate on the GAIA benchmark.")login_button = gr.LoginButton()run_button = gr.Button("🚀 Run Evaluation & Submit All Answers")status_output = gr.Textbox(label="Run Status", lines=10)results_table = gr.DataFrame(label="Results")run_button.click(fn=run_and_submit_all,inputs=[login_button], # wire login profile as inputoutputs=[status_output, results_table])if __name__ == "__main__":demo.launch()
app.py+45-25