Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import requests | |
| from app import PuzzleAgent | |
| import os | |
| agent = PuzzleAgent() | |
| API_BASE = "https://agents-course-unit4-scoring.hf.space" | |
| questions = requests.get(f"{API_BASE}/questions").json() | |
| def run_and_submit(username): | |
| answers = [] | |
| for q in questions: | |
| task_id = q["task_id"] | |
| question = q["question"] | |
| answer = agent(question) | |
| answers.append({ | |
| "task_id": task_id, | |
| "submitted_answer": answer | |
| }) | |
| submission_payload = { | |
| "username": username, | |
| "agent_code": f"https://huggingface.co/spaces/{os.getenv('SPACE_ID', 'your-username/your-space')}/tree/main", | |
| "answers": answers | |
| } | |
| res = requests.post(f"{API_BASE}/submit", json=submission_payload) | |
| print(res.json()) | |
| return res.json() | |
| # Gradio UI | |
| with gr.Blocks() as demo: | |
| gr.Markdown("## ✨ Jaykumar's PuzzleAgent: AI with a Human Brain") | |
| gr.Markdown("No templates. No tricks. Just clever, handcrafted logic.") | |
| with gr.Row(): | |
| login_btn = gr.LoginButton() | |
| run_btn = gr.Button("🚀 Run and Submit") | |
| output = gr.JSON() | |
| run_btn.click(fn=run_and_submit, inputs=login_btn, outputs=output) | |
| demo.launch() | |