jbaselga commited on
Commit
1dbd212
verified
1 Parent(s): 0430769

Update api_server.py

Browse files
Files changed (1) hide show
  1. api_server.py +62 -0
api_server.py CHANGED
@@ -65,3 +65,65 @@ def submit(sub: Submission):
65
  total_attempted=total,
66
  message=f"Puntuaci贸n: {correct}/{total} = {score:.1f}%"
67
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  total_attempted=total,
66
  message=f"Puntuaci贸n: {correct}/{total} = {score:.1f}%"
67
  )
68
+
69
+ from fastapi.responses import HTMLResponse
70
+
71
+ @app.get("/", response_class=HTMLResponse)
72
+ def read_root():
73
+ return """
74
+ <!DOCTYPE html>
75
+ <html>
76
+ <head>
77
+ <title>GAIA Agents - Test Interface</title>
78
+ </head>
79
+ <body>
80
+ <h1>GAIA Agents - Preguntas y Respuestas</h1>
81
+ <button onclick="loadQuestions()">Cargar preguntas</button>
82
+ <div id="questions"></div>
83
+ <button onclick="submitAnswers()">Enviar respuestas</button>
84
+ <div id="result"></div>
85
+ <script>
86
+ let answers = {};
87
+
88
+ async function loadQuestions() {
89
+ const resp = await fetch('/questions');
90
+ const data = await resp.json();
91
+ const container = document.getElementById('questions');
92
+ container.innerHTML = '';
93
+ data.forEach(q => {
94
+ const div = document.createElement('div');
95
+ div.innerHTML = `
96
+ <p><b>${q.task_id}</b>: ${q.question}</p>
97
+ <input type="text" id="answer_${q.task_id}" placeholder="Tu respuesta">
98
+ `;
99
+ container.appendChild(div);
100
+ });
101
+ }
102
+
103
+ async function submitAnswers() {
104
+ const container = document.getElementById('questions');
105
+ answers = {};
106
+ Array.from(container.querySelectorAll('input')).forEach(input => {
107
+ const tid = input.id.replace('answer_', '');
108
+ answers[tid] = input.value;
109
+ });
110
+
111
+ const payload = {
112
+ username: "tu_usuario",
113
+ agent_code: "https://huggingface.co/spaces/jbaselga/agentes-unit4/tree/main",
114
+ answers: Object.entries(answers).map(([tid, ans]) => ({task_id: tid, submitted_answer: ans}))
115
+ };
116
+
117
+ const resp = await fetch('/submit', {
118
+ method: 'POST',
119
+ headers: {'Content-Type': 'application/json'},
120
+ body: JSON.stringify(payload)
121
+ });
122
+
123
+ const result = await resp.json();
124
+ document.getElementById('result').innerHTML = `<h3>Resultado</h3><p>${result.message}</p>`;
125
+ }
126
+ </script>
127
+ </body>
128
+ </html>
129
+ """