Jay-Lokhande commited on
Commit
45e8190
·
verified ·
1 Parent(s): d1cec48

Create run_and_submit.py

Browse files
Files changed (1) hide show
  1. run_and_submit.py +45 -0
run_and_submit.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ from app import PuzzleAgent
4
+ import os
5
+
6
+ agent = PuzzleAgent()
7
+
8
+ API_BASE = "https://agents-course-unit4-scoring.hf.space"
9
+ questions = requests.get(f"{API_BASE}/questions").json()
10
+
11
+ def run_and_submit(username):
12
+ answers = []
13
+
14
+ for q in questions:
15
+ task_id = q["task_id"]
16
+ question = q["question"]
17
+ answer = agent(question)
18
+ answers.append({
19
+ "task_id": task_id,
20
+ "submitted_answer": answer
21
+ })
22
+
23
+ submission_payload = {
24
+ "username": username,
25
+ "agent_code": f"https://huggingface.co/spaces/{os.getenv('SPACE_ID', 'your-username/your-space')}/tree/main",
26
+ "answers": answers
27
+ }
28
+
29
+ res = requests.post(f"{API_BASE}/submit", json=submission_payload)
30
+ print(res.json())
31
+ return res.json()
32
+
33
+ # Gradio UI
34
+ with gr.Blocks() as demo:
35
+ gr.Markdown("## ✨ Jaykumar's PuzzleAgent: AI with a Human Brain")
36
+ gr.Markdown("No templates. No tricks. Just clever, handcrafted logic.")
37
+
38
+ with gr.Row():
39
+ login_btn = gr.LoginButton()
40
+ run_btn = gr.Button("🚀 Run and Submit")
41
+ output = gr.JSON()
42
+
43
+ run_btn.click(fn=run_and_submit, inputs=login_btn, outputs=output)
44
+
45
+ demo.launch()