ui: modernize UI to Mainframe design system

This commit is contained in:
hiep200311
2026-06-17 16:58:50 +07:00
parent ba68e5c15c
commit ff47d331ae
13 changed files with 2292 additions and 1822 deletions
File diff suppressed because it is too large Load Diff
+4 -522
View File
@@ -5,240 +5,9 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Phiên Âm</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family:
-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
background: #f5f5f5;
min-height: 100vh;
padding: 40px 20px;
color: #111;
}
.container {
max-width: 760px;
margin: 0 auto;
background: #fff;
border: 1px solid #e0e0e0;
border-radius: 4px;
padding: 48px;
}
h1 {
font-size: 22px;
font-weight: 500;
letter-spacing: -0.3px;
margin-bottom: 6px;
color: #111;
}
.subtitle {
font-size: 14px;
color: #777;
margin-bottom: 36px;
}
.upload-view {
display: block;
}
.transcript-view {
display: none;
}
.upload-area {
border: 1.5px dashed #ccc;
border-radius: 4px;
padding: 48px 32px;
text-align: center;
cursor: pointer;
transition:
border-color 0.2s,
background 0.2s;
margin-bottom: 24px;
}
.upload-area:hover,
.upload-area.dragover {
border-color: #111;
background: #fafafa;
}
.upload-icon {
font-size: 22px;
margin-bottom: 14px;
display: block;
}
.upload-area h3 {
font-size: 15px;
font-weight: 500;
margin-bottom: 6px;
color: #222;
}
.upload-area p {
font-size: 13px;
color: #999;
}
.file-input {
display: none;
}
.language-select {
display: flex;
gap: 24px;
margin-bottom: 24px;
font-size: 14px;
color: #444;
}
.language-select label {
display: flex;
align-items: center;
gap: 6px;
cursor: pointer;
}
.language-select input[type="radio"] {
accent-color: #111;
}
.model-select {
margin-bottom: 24px;
font-size: 14px;
color: #444;
}
.model-select select {
margin-left: 10px;
padding: 6px 10px;
border: 1px solid #ccc;
border-radius: 3px;
font-size: 14px;
}
.btn {
background: #111;
color: #fff;
border: none;
padding: 10px 24px;
border-radius: 3px;
font-size: 14px;
font-weight: 500;
cursor: pointer;
transition: background 0.15s;
margin: 4px 4px 4px 0;
text-decoration: none;
display: inline-block;
}
.btn:hover {
background: #333;
}
.btn:disabled {
background: #ccc;
cursor: not-allowed;
}
.btn-outline {
background: #fff;
color: #111;
border: 1px solid #ccc;
}
.btn-outline:hover {
background: #f5f5f5;
border-color: #999;
}
.file-info {
background: #f9f9f9;
border: 1px solid #eee;
padding: 14px 16px;
border-radius: 3px;
margin-bottom: 20px;
font-size: 13px;
color: #555;
line-height: 1.8;
word-break: break-all;
display: none;
}
.progress-container {
margin-top: 28px;
display: none;
}
.progress-container h3 {
font-size: 14px;
font-weight: 500;
color: #444;
margin-bottom: 10px;
}
.progress-bar {
width: 100%;
height: 3px;
background: #eee;
border-radius: 2px;
overflow: hidden;
margin-bottom: 10px;
}
.progress-fill {
height: 100%;
background: #111;
width: 0%;
transition: width 0.3s ease;
}
.upload-progress-bar {
width: 100%;
height: 3px;
background: #e0e0e0;
border-radius: 2px;
overflow: hidden;
margin: 10px 0;
}
.upload-progress-fill {
height: 100%;
background: #4caf50;
width: 0%;
transition: width 0.3s ease;
}
.progress-text {
margin-top: 8px;
font-size: 13px;
color: #888;
}
.result-area {
margin-top: 28px;
display: none;
border-top: 1px solid #eee;
padding-top: 24px;
}
.result-label {
font-size: 13px;
font-weight: 500;
color: #111;
margin-bottom: 12px;
}
.result-preview {
background: #f9f9f9;
border: 1px solid #eee;
border-radius: 3px;
padding: 16px;
font-size: 13px;
color: #444;
line-height: 1.7;
margin-bottom: 16px;
}
.meta {
font-size: 13px;
color: #666;
margin-bottom: 24px;
padding-bottom: 20px;
border-bottom: 1px solid #eee;
line-height: 1.8;
}
.transcript-content {
background: #f9f9f9;
border: 1px solid #eee;
border-radius: 3px;
padding: 20px;
font-size: 14px;
line-height: 1.8;
white-space: pre-wrap;
word-wrap: break-word;
max-height: 560px;
overflow-y: auto;
color: #333;
}
.nav-buttons {
margin-bottom: 24px;
}
</style>
<link rel="stylesheet" href="https://db.onlinewebfonts.com/c/5ac3fe7c6abd2f62067f266d89671492?family=HelveticaNowDisplay-Medium" />
<link rel="stylesheet" href="https://db.onlinewebfonts.com/c/1aa3377e489837a26d019bba501e779d?family=HelveticaNowDisplayW01-Rg" />
<link rel="stylesheet" href="/static/transcriptionPages/transcriptionMain.css" />
</head>
<body>
<div class="container">
@@ -336,294 +105,7 @@
</div>
</div>
<script>
if (document.querySelector(".upload-view").style.display !== "none") {
const uploadArea = document.getElementById("uploadArea");
const fileInput = document.getElementById("fileInput");
const uploadBtn = document.getElementById("uploadBtn");
const fileInfo = document.getElementById("fileInfo");
const progressContainer = document.getElementById("progressContainer");
const progressFill = document.getElementById("progressFill");
const uploadProgressFill =
document.getElementById("uploadProgressFill");
const progressText = document.getElementById("progressText");
const resultArea = document.getElementById("resultArea");
const transcriptPreview = document.getElementById("transcriptPreview");
let selectedFile = null;
uploadArea.addEventListener("click", () => fileInput.click());
uploadArea.addEventListener("dragover", (e) => {
e.preventDefault();
uploadArea.classList.add("dragover");
});
uploadArea.addEventListener("dragleave", () =>
uploadArea.classList.remove("dragover"),
);
uploadArea.addEventListener("drop", (e) => {
e.preventDefault();
uploadArea.classList.remove("dragover");
if (e.dataTransfer.files.length > 0)
handleFileSelect(e.dataTransfer.files[0]);
});
fileInput.addEventListener("change", (e) => {
if (e.target.files.length > 0) handleFileSelect(e.target.files[0]);
});
function handleFileSelect(file) {
selectedFile = file;
const sizeInMB = (file.size / (1024 * 1024)).toFixed(2);
fileInfo.style.display = "block";
fileInfo.innerHTML = `<strong>Tệp đã chọn:</strong> ${file.name}<br><strong>Kích thước:</strong> ${sizeInMB} MB`;
uploadBtn.style.display = "inline-block";
}
uploadBtn.addEventListener("click", async () => {
if (!selectedFile) return;
const language = document.querySelector(
'input[name="language"]:checked',
).value;
const model = document.getElementById("modelSelect").value;
uploadBtn.disabled = true;
progressContainer.style.display = "block";
resultArea.style.display = "none";
try {
await uploadFileInChunks(selectedFile, language, model);
} catch (error) {
alert("Tải lên thất bại: " + error.message);
uploadBtn.disabled = false;
progressContainer.style.display = "none";
}
});
async function uploadFileInChunks(file, language, model) {
const CHUNK_SIZE = 3 * 60 * 1000; // 3 minutes in milliseconds
let jobId = null;
// Create audio context to get duration
const audioContext = new (
window.AudioContext || window.webkitAudioContext
)();
const arrayBuffer = await file.arrayBuffer();
const audioBuffer = await audioContext.decodeAudioData(arrayBuffer);
const duration = audioBuffer.duration * 1000; // Duration in milliseconds
const totalChunks = Math.ceil(duration / CHUNK_SIZE);
progressText.textContent = `Đang chuẩn bị tải lên ${totalChunks} phần...`;
for (let i = 0; i < totalChunks; i++) {
const start = i * CHUNK_SIZE;
const end = Math.min(start + CHUNK_SIZE, duration);
progressText.textContent = `Đang tải lên phần ${i + 1}/${totalChunks}...`;
// Extract chunk from audio
const chunkBlob = await extractAudioChunk(
audioBuffer,
start,
end,
file.type,
);
const formData = new FormData();
formData.append("chunk", chunkBlob, `chunk_${i}.mp3`);
formData.append("chunk_index", i);
formData.append("total_chunks", totalChunks);
formData.append("filename", file.name);
formData.append("language", language);
formData.append("model", model);
if (jobId) {
formData.append("job_id", jobId);
}
const response = await fetch("/upload-chunk", {
method: "POST",
body: formData,
});
const data = await response.json();
if (!response.ok) {
throw new Error(data.error || "Upload failed");
}
jobId = data.job_id;
// Update upload progress
const uploadProgress = ((i + 1) / totalChunks) * 100;
uploadProgressFill.style.width = uploadProgress + "%";
if (data.status === "processing") {
progressText.textContent =
"Tất cả các phần đã được tải lên! Đang bắt đầu phiên âm...";
startPolling(jobId);
return;
}
}
}
async function extractAudioChunk(
audioBuffer,
startTime,
endTime,
mimeType,
) {
const sampleRate = audioBuffer.sampleRate;
const startSample = Math.floor((startTime * sampleRate) / 1000);
const endSample = Math.floor((endTime * sampleRate) / 1000);
const frameCount = endSample - startSample;
// Create new audio buffer for chunk
const chunkBuffer = new AudioContext().createBuffer(
audioBuffer.numberOfChannels,
frameCount,
sampleRate,
);
// Copy data
for (
let channel = 0;
channel < audioBuffer.numberOfChannels;
channel++
) {
const channelData = audioBuffer.getChannelData(channel);
const chunkData = chunkBuffer.getChannelData(channel);
for (let i = 0; i < frameCount; i++) {
chunkData[i] = channelData[startSample + i];
}
}
// Convert to WAV first, then let server handle conversion
const wavBlob = audioBufferToWav(chunkBuffer);
// If it's already an audio file, return as is, otherwise convert
if (mimeType.includes("audio")) {
return wavBlob;
} else {
// For video files, we'll send the audio portion
return wavBlob;
}
}
function audioBufferToWav(buffer) {
const numChannels = buffer.numberOfChannels;
const sampleRate = buffer.sampleRate;
const format = 1; // PCM
const bitDepth = 16;
let resultBuffer;
if (numChannels === 2) {
resultBuffer = interleave(
buffer.getChannelData(0),
buffer.getChannelData(1),
);
} else {
resultBuffer = buffer.getChannelData(0);
}
const dataLength = resultBuffer.length * 2;
const bufferLength = 44 + dataLength;
const arrayBuffer = new ArrayBuffer(bufferLength);
const view = new DataView(arrayBuffer);
// Write WAV header
writeString(view, 0, "RIFF");
view.setUint32(4, 36 + dataLength, true);
writeString(view, 8, "WAVE");
writeString(view, 12, "fmt ");
view.setUint32(16, 16, true);
view.setUint16(20, format, true);
view.setUint16(22, numChannels, true);
view.setUint32(24, sampleRate, true);
view.setUint32(28, sampleRate * 4, true);
view.setUint16(32, numChannels * 2, true);
view.setUint16(34, bitDepth, true);
writeString(view, 36, "data");
view.setUint32(40, dataLength, true);
// Write audio data
const offset = 44;
for (let i = 0; i < resultBuffer.length; i++) {
const sample = Math.max(-1, Math.min(1, resultBuffer[i]));
view.setInt16(
offset + i * 2,
sample < 0 ? sample * 0x8000 : sample * 0x7fff,
true,
);
}
return new Blob([arrayBuffer], { type: "audio/wav" });
}
function writeString(view, offset, string) {
for (let i = 0; i < string.length; i++) {
view.setUint8(offset + i, string.charCodeAt(i));
}
}
function interleave(left, right) {
const length = left.length + right.length;
const result = new Float32Array(length);
let inputIndex = 0;
for (let i = 0; i < length; i += 2) {
result[i] = left[inputIndex];
result[i + 1] = right[inputIndex];
inputIndex++;
}
return result;
}
function startPolling(jobId) {
const pollInterval = setInterval(async () => {
try {
const data = await (await fetch(`/status/${jobId}`)).json();
progressFill.style.width = data.progress + "%";
if (data.status === "processing") {
progressText.textContent = data.current_chunk
? `Đang phiên âm đoạn ${data.current_chunk}...`
: `Đang xử lý: ${data.progress}%`;
} else if (data.status === "completed") {
clearInterval(pollInterval);
progressText.textContent = "Hoàn tất!";
showResult(jobId);
} else if (data.status === "error") {
clearInterval(pollInterval);
progressText.textContent = "Lỗi: " + data.error;
uploadBtn.disabled = false;
}
} catch (e) {
console.error("Lỗi kiểm tra:", e);
}
}, 2000);
}
async function showResult(jobId) {
try {
const html = await (await fetch(`/view/${jobId}`)).text();
const doc = new DOMParser().parseFromString(html, "text/html");
const content =
doc.querySelector(".transcript-content")?.textContent ||
"Đã tải bản phiên âm";
transcriptPreview.innerHTML = `<pre style="white-space:pre-wrap;word-wrap:break-word;margin:0;font-family:inherit">${content.substring(0, 300)}...</pre>`;
resultArea.style.display = "block";
uploadBtn.disabled = false;
document.getElementById("viewFullBtn").onclick = () =>
window.open(`/view/${jobId}`, "_blank");
document.getElementById("downloadBtn").onclick = () =>
(window.location.href = `/transcript/${jobId}`);
} catch (e) {
console.error("Lỗi hiển thị:", e);
}
}
}
</script>
<script src="/static/transcriptionPages/transcriptionMain.js"></script>
<script src="/static/header/headerLoader.js?v=1.0"></script>
</body>
</html>
@@ -5,60 +5,9 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Transcript - {{ filename }}</title>
<style>
body {
font-family:
-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
background: #f5f5f5;
padding: 20px;
}
.container {
max-width: 900px;
margin: 0 auto;
background: white;
border-radius: 10px;
padding: 30px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
h1 {
color: #333;
margin-bottom: 10px;
}
.meta {
color: #666;
margin-bottom: 20px;
padding-bottom: 20px;
border-bottom: 1px solid #eee;
}
.transcript {
background: #f9f9f9;
padding: 20px;
border-radius: 8px;
line-height: 1.6;
white-space: pre-wrap;
word-wrap: break-word;
}
.btn {
background: #000000;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
text-decoration: none;
display: inline-block;
margin-right: 10px;
}
.btn:hover {
background: #000000;
}
</style>
<link rel="stylesheet" href="https://db.onlinewebfonts.com/c/5ac3fe7c6abd2f62067f266d89671492?family=HelveticaNowDisplay-Medium" />
<link rel="stylesheet" href="https://db.onlinewebfonts.com/c/1aa3377e489837a26d019bba501e779d?family=HelveticaNowDisplayW01-Rg" />
<link rel="stylesheet" href="/static/transcriptionPages/transcriptionReview.css" />
</head>
<body>
<div class="container">
@@ -75,5 +24,6 @@
<div class="transcript">{{ content }}</div>
</div>
<script src="/static/transcriptionPages/transcriptionReview.js"></script>
</body>
</html>