File size: 1,220 Bytes
45e8190
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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()