added simple fronted

This commit is contained in:
Karma Riuk
2025-05-07 13:05:25 +02:00
parent a16435b021
commit c567b59635
3 changed files with 99 additions and 0 deletions

62
public/index.html Normal file
View File

@ -0,0 +1,62 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Dataset Downloader & Answer Uploader</title>
<style>
body {
font-family: sans-serif;
max-width: 600px;
margin: 2em auto;
}
fieldset {
margin-bottom: 1.5em;
padding: 1em;
}
button {
padding: 0.5em 1em;
}
</style>
</head>
<body>
<h1>Crab Webapp</h1>
<fieldset>
<legend><strong>Download a Dataset</strong></legend>
<label for="datasetSelect">Dataset:</label>
<select id="datasetSelect">
<option value="comment_generation">comment_generation</option>
<option value="code_refinement">code_refinement</option>
</select>
<label>
<input type="checkbox" id="withContext">
Include context
</label>
<br /><br />
<button id="downloadBtn">Download</button>
</fieldset>
<fieldset>
<legend><strong>Upload Your Answers</strong></legend>
<label for="answerType">Type:</label>
<select id="answerType">
<option value="comments">Comments</option>
<option value="refinement">Refinement</option>
</select>
<br /><br />
<input type="file" id="fileInput" accept="application/json" />
<br /><br />
<button id="uploadBtn">Upload JSON</button>
</fieldset>
<div id="status" style="color: green;"></div>
<script src="js/index.js"></script>
</body>
</html>

36
public/js/index.js Normal file
View File

@ -0,0 +1,36 @@
// Download logic
document.getElementById('downloadBtn').onclick = () => {
const ds = document.getElementById('datasetSelect').value;
const withCtx = document.getElementById('withContext').checked;
const url = `/datasets/download/${ds}` + (withCtx ? '?withContext=true' : '');
window.location = url;
};
// Upload logic
document.getElementById('uploadBtn').onclick = async () => {
const type = document.getElementById('answerType').value;
const fileInput = document.getElementById('fileInput');
if (!fileInput.files.length) {
return alert('Please choose a JSON file first.');
}
const file = fileInput.files[0];
const form = new FormData();
form.append('file', file);
const res = await fetch(`/answers/submit/${type}`, {
method: 'POST',
body: form
});
const json = await res.json();
console.log(json)
const statusEl = document.getElementById('status');
if (res.ok) {
statusEl.style.color = 'green';
statusEl.textContent = json.message || 'Upload succeeded!';
} else {
statusEl.style.color = 'red';
statusEl.textContent = json.error + (json.message ? (': ' + json.message) : '');
}
};

View File

@ -13,6 +13,7 @@ app.use(cors());
app.use(json());
// Use routes
app.use(express.static("public"));
app.use('/', routes);
// Start server