Hari-Prasath-M91 commited on
Commit
aed7b8c
·
1 Parent(s): cd2b618
Files changed (1) hide show
  1. app.py +104 -0
app.py CHANGED
@@ -1277,6 +1277,110 @@ def taskadder(tasks: Tasks):
1277
 
1278
  return {"successful": "Task successfully added to the roadmap"}
1279
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1280
  # --- AGENT 2: Roadmap Manager (Roadmap Manager Page) ---
1281
  @app.get("/agent2")
1282
  def agent2(
 
1277
 
1278
  return {"successful": "Task successfully added to the roadmap"}
1279
 
1280
+ @app.get("/taskform", response_class=HTMLResponse)
1281
+ def task_form():
1282
+ return """
1283
+ <!DOCTYPE html>
1284
+ <html>
1285
+ <head>
1286
+ <title>Task Scheduler</title>
1287
+ <style>
1288
+ body { font-family: Arial; padding: 20px; }
1289
+ .subject-block, .task-block { border: 1px solid #ccc; padding: 15px; margin-top: 10px; border-radius: 5px; }
1290
+ .task-block { margin-left: 20px; }
1291
+ input, select { margin: 5px; }
1292
+ </style>
1293
+ </head>
1294
+ <body>
1295
+ <h2>Task Scheduler</h2>
1296
+ <label>From Date: <input type="date" id="from_date"></label>
1297
+ <label>To Date: <input type="date" id="to_date"></label>
1298
+ <div id="subjects_container"></div>
1299
+ <button onclick="addSubject()">➕ Add Subject</button><br><br>
1300
+ <button onclick="submitForm()">✅ Submit Tasks</button>
1301
+
1302
+ <script>
1303
+ function addSubject() {
1304
+ const subjectsContainer = document.getElementById('subjects_container');
1305
+ const subjectBlock = document.createElement('div');
1306
+ subjectBlock.className = 'subject-block';
1307
+
1308
+ const subjectSelect = document.createElement('select');
1309
+ ['Physics', 'Chemistry', 'Maths'].forEach(sub => {
1310
+ const opt = document.createElement('option');
1311
+ opt.value = sub;
1312
+ opt.innerText = sub;
1313
+ subjectSelect.appendChild(opt);
1314
+ });
1315
+
1316
+ const tasksContainer = document.createElement('div');
1317
+ tasksContainer.className = 'tasks-container';
1318
+
1319
+ const addTaskBtn = document.createElement('button');
1320
+ addTaskBtn.innerText = '➕ Add Task';
1321
+ addTaskBtn.type = 'button';
1322
+ addTaskBtn.onclick = () => addTask(tasksContainer);
1323
+
1324
+ subjectBlock.appendChild(document.createTextNode("Subject: "));
1325
+ subjectBlock.appendChild(subjectSelect);
1326
+ subjectBlock.appendChild(addTaskBtn);
1327
+ subjectBlock.appendChild(tasksContainer);
1328
+
1329
+ subjectsContainer.appendChild(subjectBlock);
1330
+ addTask(tasksContainer);
1331
+ }
1332
+
1333
+ function addTask(container) {
1334
+ const taskBlock = document.createElement('div');
1335
+ taskBlock.className = 'task-block';
1336
+ taskBlock.innerHTML = `
1337
+ Chapter: <input type="text" class="chapter">
1338
+ Description: <input type="text" class="description">
1339
+ Time (hrs): <input type="number" class="time" min="1">
1340
+ `;
1341
+ container.appendChild(taskBlock);
1342
+ }
1343
+
1344
+ function submitForm() {
1345
+ const fromDate = document.getElementById('from_date').value;
1346
+ const toDate = document.getElementById('to_date').value;
1347
+
1348
+ const subjectBlocks = document.querySelectorAll('.subject-block');
1349
+ const subjects = [];
1350
+
1351
+ subjectBlocks.forEach(subjectBlock => {
1352
+ const subjectName = subjectBlock.querySelector('select').value;
1353
+ const taskElements = subjectBlock.querySelectorAll('.task-block');
1354
+
1355
+ const tasks = Array.from(taskElements).map(task => ({
1356
+ chapter: task.querySelector('.chapter').value,
1357
+ description: task.querySelector('.description').value,
1358
+ estimated_time: parseInt(task.querySelector('.time').value)
1359
+ }));
1360
+
1361
+ subjects.push({ subject: subjectName, tasks });
1362
+ });
1363
+
1364
+ const data = {
1365
+ from_date: fromDate,
1366
+ to_date: toDate,
1367
+ subjects
1368
+ };
1369
+
1370
+ fetch("https://hari-prasath-m91-sstudize-agents-fastapi.hf.space/taskadder", {
1371
+ method: "POST",
1372
+ headers: { "Content-Type": "application/json" },
1373
+ body: JSON.stringify(data)
1374
+ })
1375
+ .then(res => res.json())
1376
+ .then(json => alert("✅ " + JSON.stringify(json)))
1377
+ .catch(err => alert("❌ Error: " + err));
1378
+ }
1379
+ </script>
1380
+ </body>
1381
+ </html>
1382
+ """
1383
+
1384
  # --- AGENT 2: Roadmap Manager (Roadmap Manager Page) ---
1385
  @app.get("/agent2")
1386
  def agent2(