CVNSS commited on
Commit
56ff7e6
·
verified ·
1 Parent(s): a3379e5

Upload 5 files

Browse files
Files changed (5) hide show
  1. Dockerfile +21 -0
  2. README.md +33 -7
  3. app.py +378 -0
  4. index.html +242 -0
  5. requirements.txt +5 -0
Dockerfile ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.11-slim
2
+
3
+ ENV PYTHONDONTWRITEBYTECODE=1 \
4
+ PYTHONUNBUFFERED=1 \
5
+ PORT=7860 \
6
+ WHISPER_MODEL_SIZE=small \
7
+ MAX_UPLOAD_MB=250 \
8
+ KEEP_HOURS=24
9
+
10
+ RUN apt-get update && apt-get install -y --no-install-recommends \
11
+ ffmpeg \
12
+ fonts-dejavu-core \
13
+ && rm -rf /var/lib/apt/lists/*
14
+
15
+ WORKDIR /app
16
+ COPY requirements.txt ./
17
+ RUN pip install --no-cache-dir -r requirements.txt
18
+
19
+ COPY . .
20
+ EXPOSE 7860
21
+ CMD ["python", "app.py"]
README.md CHANGED
@@ -1,12 +1,38 @@
1
  ---
2
- title: VietAutoSub
3
- emoji: 🏃
4
- colorFrom: gray
5
  colorTo: blue
6
- sdk: gradio
7
- sdk_version: 6.9.0
8
- app_file: app.py
9
  pinned: false
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: Viet AutoSub Editor
3
+ emoji: 🎬
4
+ colorFrom: red
5
  colorTo: blue
6
+ sdk: docker
7
+ app_port: 7860
 
8
  pinned: false
9
  ---
10
 
11
+ # Viet AutoSub Editor
12
+
13
+ Ứng dụng tối giản để:
14
+ - Upload video
15
+ - Tự động tạo subtitle tiếng Việt
16
+ - Sửa text và time trong bảng
17
+ - Xuất file `.srt`
18
+ - Xuất lại `.mp4` đã burn subtitle
19
+
20
+ ## Chạy local
21
+
22
+ ```bash
23
+ docker build -t viet-autosub .
24
+ docker run -p 7860:7860 viet-autosub
25
+ ```
26
+
27
+ Hoặc dùng Python trực tiếp:
28
+
29
+ ```bash
30
+ pip install -r requirements.txt
31
+ python app.py
32
+ ```
33
+
34
+ ## Ghi chú
35
+
36
+ - Mặc định dùng model `small` để cân bằng tốc độ và độ chính xác.
37
+ - Với video dài hoặc audio nhiều nhạc nền, nên nâng cấp phần model hoặc thêm căn chỉnh timestamp sâu hơn.
38
+ - Dữ liệu lưu tạm trong thư mục `workspace` và tự dọn sau 24 giờ.
app.py ADDED
@@ -0,0 +1,378 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+ import shutil
4
+ import subprocess
5
+ import threading
6
+ import uuid
7
+ from datetime import datetime, timedelta
8
+ from pathlib import Path
9
+ from typing import List, Optional
10
+
11
+ from fastapi import FastAPI, File, HTTPException, Request, UploadFile
12
+ from fastapi.middleware.cors import CORSMiddleware
13
+ from fastapi.responses import FileResponse, HTMLResponse, JSONResponse
14
+ from fastapi.staticfiles import StaticFiles
15
+ from fastapi.templating import Jinja2Templates
16
+ from faster_whisper import WhisperModel
17
+ from pydantic import BaseModel, Field
18
+
19
+
20
+ APP_DIR = Path(__file__).resolve().parent
21
+ WORK_DIR = APP_DIR / "workspace"
22
+ TEMPLATES_DIR = APP_DIR / "templates"
23
+ STATIC_DIR = APP_DIR / "static"
24
+ WORK_DIR.mkdir(parents=True, exist_ok=True)
25
+
26
+
27
+ app = FastAPI(title="Viet AutoSub Editor")
28
+ app.add_middleware(
29
+ CORSMiddleware,
30
+ allow_origins=["*"],
31
+ allow_credentials=True,
32
+ allow_methods=["*"],
33
+ allow_headers=["*"],
34
+ )
35
+ app.mount("/static", StaticFiles(directory=STATIC_DIR), name="static")
36
+ templates = Jinja2Templates(directory=str(TEMPLATES_DIR))
37
+
38
+
39
+ MODEL_LOCK = threading.Lock()
40
+ MODEL_CACHE = {}
41
+ DEFAULT_MODEL_SIZE = os.getenv("WHISPER_MODEL_SIZE", "small")
42
+ MAX_UPLOAD_MB = int(os.getenv("MAX_UPLOAD_MB", "250"))
43
+ KEEP_HOURS = int(os.getenv("KEEP_HOURS", "24"))
44
+
45
+
46
+ class SegmentIn(BaseModel):
47
+ id: int
48
+ start: str
49
+ end: str
50
+ text: str = Field(default="")
51
+
52
+
53
+ class ExportRequest(BaseModel):
54
+ job_id: str
55
+ segments: List[SegmentIn]
56
+ burn_in: bool = True
57
+
58
+
59
+ class SegmentOut(BaseModel):
60
+ id: int
61
+ start: float
62
+ end: float
63
+ text: str
64
+
65
+
66
+
67
+ def cleanup_old_jobs() -> None:
68
+ cutoff = datetime.utcnow() - timedelta(hours=KEEP_HOURS)
69
+ for folder in WORK_DIR.iterdir():
70
+ if not folder.is_dir():
71
+ continue
72
+ try:
73
+ modified = datetime.utcfromtimestamp(folder.stat().st_mtime)
74
+ if modified < cutoff:
75
+ shutil.rmtree(folder, ignore_errors=True)
76
+ except Exception:
77
+ continue
78
+
79
+
80
+
81
+ def get_model(model_size: str = DEFAULT_MODEL_SIZE) -> WhisperModel:
82
+ with MODEL_LOCK:
83
+ if model_size not in MODEL_CACHE:
84
+ MODEL_CACHE[model_size] = WhisperModel(
85
+ model_size,
86
+ device="cpu",
87
+ compute_type="int8",
88
+ )
89
+ return MODEL_CACHE[model_size]
90
+
91
+
92
+
93
+ def ffmpeg_exists() -> bool:
94
+ return shutil.which("ffmpeg") is not None and shutil.which("ffprobe") is not None
95
+
96
+
97
+
98
+ def save_upload(upload: UploadFile, target_dir: Path) -> Path:
99
+ suffix = Path(upload.filename or "video.mp4").suffix or ".mp4"
100
+ video_path = target_dir / f"source{suffix}"
101
+ with video_path.open("wb") as f:
102
+ while True:
103
+ chunk = upload.file.read(1024 * 1024)
104
+ if not chunk:
105
+ break
106
+ f.write(chunk)
107
+ if f.tell() > MAX_UPLOAD_MB * 1024 * 1024:
108
+ raise HTTPException(status_code=413, detail=f"File quá lớn. Giới hạn {MAX_UPLOAD_MB} MB.")
109
+ return video_path
110
+
111
+
112
+
113
+ def run_ffprobe_duration(video_path: Path) -> Optional[float]:
114
+ try:
115
+ cmd = [
116
+ "ffprobe",
117
+ "-v",
118
+ "error",
119
+ "-show_entries",
120
+ "format=duration",
121
+ "-of",
122
+ "default=noprint_wrappers=1:nokey=1",
123
+ str(video_path),
124
+ ]
125
+ result = subprocess.run(cmd, capture_output=True, text=True, check=True)
126
+ return float(result.stdout.strip())
127
+ except Exception:
128
+ return None
129
+
130
+
131
+
132
+ def transcribe_video(video_path: Path, model_size: str = DEFAULT_MODEL_SIZE) -> List[SegmentOut]:
133
+ model = get_model(model_size)
134
+ segments, _info = model.transcribe(
135
+ str(video_path),
136
+ language="vi",
137
+ vad_filter=True,
138
+ beam_size=5,
139
+ condition_on_previous_text=True,
140
+ )
141
+ rows: List[SegmentOut] = []
142
+ for idx, seg in enumerate(segments, start=1):
143
+ text = (seg.text or "").strip()
144
+ if not text:
145
+ continue
146
+ rows.append(
147
+ SegmentOut(
148
+ id=idx,
149
+ start=float(seg.start),
150
+ end=float(seg.end),
151
+ text=text,
152
+ )
153
+ )
154
+ if not rows:
155
+ raise HTTPException(status_code=400, detail="Không nhận diện được lời thoại trong video.")
156
+ return rows
157
+
158
+
159
+
160
+ def format_srt_time(seconds: float) -> str:
161
+ total_ms = max(0, int(round(seconds * 1000)))
162
+ hours = total_ms // 3600000
163
+ total_ms %= 3600000
164
+ minutes = total_ms // 60000
165
+ total_ms %= 60000
166
+ secs = total_ms // 1000
167
+ millis = total_ms % 1000
168
+ return f"{hours:02d}:{minutes:02d}:{secs:02d},{millis:03d}"
169
+
170
+
171
+
172
+ def parse_time_string(value: str) -> float:
173
+ value = value.strip()
174
+ if not value:
175
+ return 0.0
176
+ value = value.replace(".", ",")
177
+ try:
178
+ hhmmss, ms = value.split(",") if "," in value else (value, "0")
179
+ parts = hhmmss.split(":")
180
+ if len(parts) == 2:
181
+ hours = 0
182
+ minutes, secs = parts
183
+ elif len(parts) == 3:
184
+ hours, minutes, secs = parts
185
+ else:
186
+ raise ValueError
187
+ return int(hours) * 3600 + int(minutes) * 60 + int(secs) + int(ms.ljust(3, "0")[:3]) / 1000.0
188
+ except Exception as exc:
189
+ raise HTTPException(status_code=400, detail=f"Sai định dạng thời gian: {value}") from exc
190
+
191
+
192
+
193
+ def write_srt(job_dir: Path, segments: List[SegmentIn]) -> Path:
194
+ srt_path = job_dir / "edited.srt"
195
+ lines: List[str] = []
196
+ cleaned = sorted(segments, key=lambda s: parse_time_string(s.start))
197
+ for idx, seg in enumerate(cleaned, start=1):
198
+ start_sec = parse_time_string(seg.start)
199
+ end_sec = parse_time_string(seg.end)
200
+ if end_sec <= start_sec:
201
+ end_sec = start_sec + 1.0
202
+ text = (seg.text or "").strip()
203
+ if not text:
204
+ continue
205
+ lines.extend(
206
+ [
207
+ str(idx),
208
+ f"{format_srt_time(start_sec)} --> {format_srt_time(end_sec)}",
209
+ text,
210
+ "",
211
+ ]
212
+ )
213
+ if not lines:
214
+ raise HTTPException(status_code=400, detail="Không có subtitle hợp lệ để xuất SRT.")
215
+ srt_path.write_text("\n".join(lines), encoding="utf-8")
216
+ return srt_path
217
+
218
+
219
+
220
+ def burn_subtitles(job_dir: Path, video_path: Path, srt_path: Path) -> Path:
221
+ output_path = job_dir / "output_subtitled.mp4"
222
+ subtitle_filter = (
223
+ "subtitles=edited.srt:"
224
+ "force_style='FontName=DejaVu Sans,FontSize=20,Outline=1,Shadow=0,MarginV=18,Alignment=2'"
225
+ )
226
+ cmd = [
227
+ "ffmpeg",
228
+ "-y",
229
+ "-i",
230
+ video_path.name,
231
+ "-vf",
232
+ subtitle_filter,
233
+ "-c:v",
234
+ "libx264",
235
+ "-preset",
236
+ "veryfast",
237
+ "-crf",
238
+ "23",
239
+ "-c:a",
240
+ "aac",
241
+ "-b:a",
242
+ "192k",
243
+ output_path.name,
244
+ ]
245
+ try:
246
+ subprocess.run(cmd, cwd=job_dir, capture_output=True, text=True, check=True)
247
+ except subprocess.CalledProcessError as exc:
248
+ stderr = (exc.stderr or "").strip()
249
+ raise HTTPException(status_code=500, detail=f"FFmpeg lỗi khi xuất MP4: {stderr[:1200]}") from exc
250
+ return output_path
251
+
252
+
253
+
254
+ def job_meta_path(job_dir: Path) -> Path:
255
+ return job_dir / "meta.json"
256
+
257
+
258
+
259
+ def save_job_meta(job_dir: Path, data: dict) -> None:
260
+ job_meta_path(job_dir).write_text(json.dumps(data, ensure_ascii=False, indent=2), encoding="utf-8")
261
+
262
+
263
+
264
+ def load_job_meta(job_id: str) -> dict:
265
+ meta = job_meta_path(WORK_DIR / job_id)
266
+ if not meta.exists():
267
+ raise HTTPException(status_code=404, detail="Không tìm thấy job.")
268
+ return json.loads(meta.read_text(encoding="utf-8"))
269
+
270
+
271
+ @app.get("/", response_class=HTMLResponse)
272
+ def home(request: Request):
273
+ return templates.TemplateResponse("index.html", {"request": request})
274
+
275
+
276
+ @app.get("/health")
277
+ def health():
278
+ return {
279
+ "ok": True,
280
+ "ffmpeg": ffmpeg_exists(),
281
+ "workspace": str(WORK_DIR),
282
+ "default_model": DEFAULT_MODEL_SIZE,
283
+ }
284
+
285
+
286
+ @app.post("/api/transcribe")
287
+ def api_transcribe(file: UploadFile = File(...)):
288
+ cleanup_old_jobs()
289
+ if not ffmpeg_exists():
290
+ raise HTTPException(status_code=500, detail="Máy chủ chưa có FFmpeg.")
291
+
292
+ filename = file.filename or "video.mp4"
293
+ if not filename.lower().endswith((".mp4", ".mov", ".mkv", ".avi", ".webm", ".m4v")):
294
+ raise HTTPException(status_code=400, detail="Chỉ hỗ trợ video mp4, mov, mkv, avi, webm, m4v.")
295
+
296
+ job_id = uuid.uuid4().hex
297
+ job_dir = WORK_DIR / job_id
298
+ job_dir.mkdir(parents=True, exist_ok=True)
299
+ try:
300
+ video_path = save_upload(file, job_dir)
301
+ duration = run_ffprobe_duration(video_path)
302
+ segments = transcribe_video(video_path)
303
+ save_job_meta(
304
+ job_dir,
305
+ {
306
+ "job_id": job_id,
307
+ "video_path": video_path.name,
308
+ "duration": duration,
309
+ "created_at": datetime.utcnow().isoformat() + "Z",
310
+ },
311
+ )
312
+ return JSONResponse(
313
+ {
314
+ "job_id": job_id,
315
+ "duration": duration,
316
+ "segments": [
317
+ {
318
+ "id": seg.id,
319
+ "start": format_srt_time(seg.start),
320
+ "end": format_srt_time(seg.end),
321
+ "text": seg.text,
322
+ }
323
+ for seg in segments
324
+ ],
325
+ }
326
+ )
327
+ except Exception:
328
+ shutil.rmtree(job_dir, ignore_errors=True)
329
+ raise
330
+
331
+
332
+ @app.post("/api/export")
333
+ def api_export(payload: ExportRequest):
334
+ job_dir = WORK_DIR / payload.job_id
335
+ if not job_dir.exists():
336
+ raise HTTPException(status_code=404, detail="Job đã hết hạn hoặc không tồn tại.")
337
+
338
+ meta = load_job_meta(payload.job_id)
339
+ video_path = job_dir / meta["video_path"]
340
+ if not video_path.exists():
341
+ raise HTTPException(status_code=404, detail="Không tìm thấy video gốc để xuất lại.")
342
+
343
+ srt_path = write_srt(job_dir, payload.segments)
344
+ response = {
345
+ "job_id": payload.job_id,
346
+ "srt_url": f"/download/{payload.job_id}/srt",
347
+ "mp4_url": None,
348
+ }
349
+
350
+ if payload.burn_in:
351
+ mp4_path = burn_subtitles(job_dir, video_path, srt_path)
352
+ response["mp4_url"] = f"/download/{payload.job_id}/mp4"
353
+ response["mp4_size_mb"] = round(mp4_path.stat().st_size / (1024 * 1024), 2)
354
+
355
+ return JSONResponse(response)
356
+
357
+
358
+ @app.get("/download/{job_id}/srt")
359
+ def download_srt(job_id: str):
360
+ path = WORK_DIR / job_id / "edited.srt"
361
+ if not path.exists():
362
+ raise HTTPException(status_code=404, detail="Chưa có file SRT.")
363
+ return FileResponse(path, media_type="application/x-subrip", filename=f"{job_id}.srt")
364
+
365
+
366
+ @app.get("/download/{job_id}/mp4")
367
+ def download_mp4(job_id: str):
368
+ path = WORK_DIR / job_id / "output_subtitled.mp4"
369
+ if not path.exists():
370
+ raise HTTPException(status_code=404, detail="Chưa có file MP4.")
371
+ return FileResponse(path, media_type="video/mp4", filename=f"{job_id}.mp4")
372
+
373
+
374
+ if __name__ == "__main__":
375
+ import uvicorn
376
+
377
+ port = int(os.getenv("PORT", "7860"))
378
+ uvicorn.run("app:app", host="0.0.0.0", port=port, reload=False)
index.html ADDED
@@ -0,0 +1,242 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="vi">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>Viet AutoSub Editor</title>
7
+ <link rel="preconnect" href="https://fonts.googleapis.com" />
8
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
9
+ <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet" />
10
+ <link rel="stylesheet" href="static/styles.css" />
11
+ </head>
12
+ <body>
13
+
14
+ <!-- ===== OFFLINE BANNER ===== -->
15
+ <div class="offline-banner" id="offlineBanner" hidden>
16
+ <svg viewBox="0 0 20 20" fill="currentColor" class="offline-banner-icon">
17
+ <path fill-rule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clip-rule="evenodd"/>
18
+ </svg>
19
+ <span id="offlineBannerText">Đang chạy offline — Chức năng AI (auto sub, xuất MP4) cần kết nối server HF Space.</span>
20
+ <button class="offline-banner-close" id="offlineBannerClose" title="Đóng">&times;</button>
21
+ </div>
22
+
23
+ <!-- ===== TOP NAV ===== -->
24
+ <nav class="topbar">
25
+ <div class="topbar-inner">
26
+ <div class="logo-group">
27
+ <svg class="logo-icon" viewBox="0 0 32 32" fill="none" aria-label="Viet AutoSub">
28
+ <rect x="2" y="6" width="28" height="20" rx="4" stroke="currentColor" stroke-width="2"/>
29
+ <rect x="6" y="20" width="20" height="4" rx="1.5" fill="currentColor" opacity="0.25"/>
30
+ <rect x="8" y="21" width="7" height="2" rx="1" fill="currentColor"/>
31
+ <rect x="17" y="21" width="5" height="2" rx="1" fill="currentColor" opacity="0.6"/>
32
+ <circle cx="16" cy="13" r="4" stroke="currentColor" stroke-width="1.5"/>
33
+ <polygon points="14.5,11.5 18.5,13 14.5,14.5" fill="currentColor"/>
34
+ </svg>
35
+ <span class="logo-text">Viet AutoSub</span>
36
+ </div>
37
+ <div class="topbar-right">
38
+ <span class="badge badge-env" id="badgeEnv">
39
+ <span class="pulse-dot" id="pulseDot"></span>
40
+ <span id="badgeEnvText">Đang kiểm tra...</span>
41
+ </span>
42
+ <span class="badge badge-model" id="modelBadge">whisper-small</span>
43
+ </div>
44
+ </div>
45
+ </nav>
46
+
47
+ <!-- ===== MAIN LAYOUT ===== -->
48
+ <main class="main">
49
+
50
+ <!-- ===== STEP INDICATOR ===== -->
51
+ <div class="steps">
52
+ <div class="step active" data-step="1">
53
+ <div class="step-num">1</div>
54
+ <div class="step-label">Upload video</div>
55
+ </div>
56
+ <div class="step-line"></div>
57
+ <div class="step" data-step="2">
58
+ <div class="step-num">2</div>
59
+ <div class="step-label">Auto sub tiếng Việt</div>
60
+ </div>
61
+ <div class="step-line"></div>
62
+ <div class="step" data-step="3">
63
+ <div class="step-num">3</div>
64
+ <div class="step-label">Chỉnh sửa subtitle</div>
65
+ </div>
66
+ <div class="step-line"></div>
67
+ <div class="step" data-step="4">
68
+ <div class="step-num">4</div>
69
+ <div class="step-label">Xuất SRT / MP4</div>
70
+ </div>
71
+ </div>
72
+
73
+ <!-- ===== UPLOAD ZONE ===== -->
74
+ <section class="panel upload-panel" id="uploadPanel">
75
+ <div class="drop-zone" id="dropZone">
76
+ <svg class="drop-icon" viewBox="0 0 48 48" fill="none">
77
+ <rect x="4" y="8" width="40" height="32" rx="6" stroke="currentColor" stroke-width="2" stroke-dasharray="4 3"/>
78
+ <path d="M24 18v12M18 24l6-6 6 6" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
79
+ </svg>
80
+ <p class="drop-title">Kéo thả video vào đây</p>
81
+ <p class="drop-hint">hoặc click để chọn file &mdash; MP4, MOV, MKV, AVI, WebM &le; 250 MB</p>
82
+ <input id="videoFile" type="file" accept="video/*" hidden />
83
+ </div>
84
+ <div class="file-info" id="fileInfo" hidden>
85
+ <div class="file-meta">
86
+ <svg viewBox="0 0 20 20" fill="currentColor" class="file-icon"><path d="M4 3a2 2 0 00-2 2v10a2 2 0 002 2h12a2 2 0 002-2V7.414A2 2 0 0017.414 6L14 2.586A2 2 0 0012.586 2H4zm8 1.414L15.586 8H13a1 1 0 01-1-1V4.414zM4 5h6v2a3 3 0 003 3h2v5a1 1 0 01-1 1H4a1 1 0 01-1-1V5a1 1 0 011-1z"/></svg>
87
+ <span id="fileName">video.mp4</span>
88
+ <span class="file-size" id="fileSize">0 MB</span>
89
+ </div>
90
+ <button class="btn btn-ghost btn-sm" id="btnClearFile">Đổi file</button>
91
+ </div>
92
+ </section>
93
+
94
+ <!-- ===== TWO-COLUMN: VIDEO + CONTROLS ===== -->
95
+ <div class="grid-two">
96
+
97
+ <!-- LEFT: Video Preview -->
98
+ <section class="panel video-panel">
99
+ <div class="panel-head">
100
+ <h2 class="panel-title">
101
+ <svg viewBox="0 0 20 20" fill="currentColor" class="icon-sm"><path d="M6.672 1.911a1 1 0 10-1.932.518l.259.966a1 1 0 001.932-.518l-.26-.966zM2.429 4.74a1 1 0 10-.517 1.932l.966.259a1 1 0 00.517-1.932l-.966-.26zm8.814-.569a1 1 0 00-1.415-1.414l-.707.707a1 1 0 101.415 1.415l.707-.708zm-7.071 7.072l.707-.707A1 1 0 003.465 9.12l-.708.707a1 1 0 001.415 1.415zm3.2-5.171a1 1 0 00-1.3 1.3l4 10a1 1 0 001.823.075l1.38-2.759 3.018 3.02a1 1 0 001.414-1.415l-3.019-3.02 2.76-1.379a1 1 0 00-.076-1.822l-10-4z"/></svg>
102
+ Xem trước
103
+ </h2>
104
+ </div>
105
+ <div class="video-wrap">
106
+ <video id="preview" controls playsinline></video>
107
+ <div class="video-placeholder" id="videoPlaceholder">
108
+ <svg viewBox="0 0 64 64" fill="none" class="placeholder-icon">
109
+ <rect x="8" y="14" width="48" height="36" rx="6" stroke="currentColor" stroke-width="2"/>
110
+ <polygon points="26,24 42,32 26,40" fill="currentColor" opacity="0.3"/>
111
+ </svg>
112
+ <span>Chưa có video</span>
113
+ </div>
114
+ </div>
115
+ </section>
116
+
117
+ <!-- RIGHT: Action Panel -->
118
+ <section class="panel action-panel">
119
+ <div class="panel-head">
120
+ <h2 class="panel-title">
121
+ <svg viewBox="0 0 20 20" fill="currentColor" class="icon-sm"><path fill-rule="evenodd" d="M11.49 3.17c-.38-1.56-2.6-1.56-2.98 0a1.532 1.532 0 01-2.286.948c-1.372-.836-2.942.734-2.106 2.106.54.886.061 2.042-.947 2.287-1.561.379-1.561 2.6 0 2.978a1.532 1.532 0 01.947 2.287c-.836 1.372.734 2.942 2.106 2.106a1.532 1.532 0 012.287.947c.379 1.561 2.6 1.561 2.978 0a1.533 1.533 0 012.287-.947c1.372.836 2.942-.734 2.106-2.106a1.533 1.533 0 01.947-2.287c1.561-.379 1.561-2.6 0-2.978a1.532 1.532 0 01-.947-2.287c.836-1.372-.734-2.942-2.106-2.106a1.532 1.532 0 01-2.287-.947zM10 13a3 3 0 100-6 3 3 0 000 6z" clip-rule="evenodd"/></svg>
122
+ Điều khiển
123
+ </h2>
124
+ </div>
125
+
126
+ <div class="action-stack">
127
+ <!-- Transcribe -->
128
+ <button id="btnTranscribe" class="btn btn-primary btn-lg btn-full">
129
+ <svg viewBox="0 0 20 20" fill="currentColor" class="icon-btn"><path fill-rule="evenodd" d="M7 4a3 3 0 016 0v4a3 3 0 11-6 0V4zm4 10.93A7.001 7.001 0 0017 8a1 1 0 10-2 0A5 5 0 015 8a1 1 0 00-2 0 7.001 7.001 0 006 6.93V17H6a1 1 0 100 2h8a1 1 0 100-2h-3v-2.07z" clip-rule="evenodd"/></svg>
130
+ Auto sub tiếng Việt
131
+ </button>
132
+
133
+ <!-- Progress Bar -->
134
+ <div class="progress-wrap" id="progressWrap" hidden>
135
+ <div class="progress-bar">
136
+ <div class="progress-fill" id="progressFill"></div>
137
+ </div>
138
+ <span class="progress-text" id="progressText">Đang xử lý...</span>
139
+ </div>
140
+
141
+ <!-- Status -->
142
+ <div id="status" class="status-box status-idle">
143
+ <svg viewBox="0 0 20 20" fill="currentColor" class="status-icon"><path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" clip-rule="evenodd"/></svg>
144
+ <span id="statusText">Sẵn sàng. Hãy upload video để bắt đầu.</span>
145
+ </div>
146
+
147
+ <hr class="divider" />
148
+
149
+ <!-- Edit Actions -->
150
+ <div class="btn-row">
151
+ <button id="btnAddRow" class="btn btn-outline" disabled>
152
+ <svg viewBox="0 0 20 20" fill="currentColor" class="icon-btn"><path fill-rule="evenodd" d="M10 3a1 1 0 011 1v5h5a1 1 0 110 2h-5v5a1 1 0 11-2 0v-5H4a1 1 0 110-2h5V4a1 1 0 011-1z" clip-rule="evenodd"/></svg>
153
+ Thêm dòng
154
+ </button>
155
+ </div>
156
+
157
+ <hr class="divider" />
158
+
159
+ <!-- Export Actions -->
160
+ <div class="export-group">
161
+ <h3 class="export-title">Xuất file</h3>
162
+ <div class="btn-row">
163
+ <button id="btnExportSrt" class="btn btn-outline" disabled>
164
+ <svg viewBox="0 0 20 20" fill="currentColor" class="icon-btn"><path fill-rule="evenodd" d="M3 17a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zm3.293-7.707a1 1 0 011.414 0L9 10.586V3a1 1 0 112 0v7.586l1.293-1.293a1 1 0 111.414 1.414l-3 3a1 1 0 01-1.414 0l-3-3a1 1 0 010-1.414z" clip-rule="evenodd"/></svg>
165
+ Xuất .SRT
166
+ </button>
167
+ <button id="btnExportMp4" class="btn btn-success" disabled>
168
+ <svg viewBox="0 0 20 20" fill="currentColor" class="icon-btn"><path d="M4 3a2 2 0 00-2 2v10a2 2 0 002 2h12a2 2 0 002-2V5a2 2 0 00-2-2H4zm12 12H4l4-8 3 6 2-4 3 6z"/></svg>
169
+ Xuất .MP4 burn sub
170
+ </button>
171
+ </div>
172
+ </div>
173
+
174
+ <!-- Download Links -->
175
+ <div class="download-group" id="downloadGroup" hidden>
176
+ <a id="downloadSrt" class="dl-link dl-srt" href="#" download>
177
+ <svg viewBox="0 0 20 20" fill="currentColor" class="icon-btn"><path fill-rule="evenodd" d="M3 17a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zm3.293-7.707a1 1 0 011.414 0L9 10.586V3a1 1 0 112 0v7.586l1.293-1.293a1 1 0 111.414 1.414l-3 3a1 1 0 01-1.414 0l-3-3a1 1 0 010-1.414z" clip-rule="evenodd"/></svg>
178
+ Tải .SRT
179
+ </a>
180
+ <a id="downloadMp4" class="dl-link dl-mp4" href="#" download>
181
+ <svg viewBox="0 0 20 20" fill="currentColor" class="icon-btn"><path fill-rule="evenodd" d="M3 17a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zm3.293-7.707a1 1 0 011.414 0L9 10.586V3a1 1 0 112 0v7.586l1.293-1.293a1 1 0 111.414 1.414l-3 3a1 1 0 01-1.414 0l-3-3a1 1 0 010-1.414z" clip-rule="evenodd"/></svg>
182
+ Tải .MP4
183
+ </a>
184
+ </div>
185
+ </div>
186
+ </section>
187
+ </div>
188
+
189
+ <!-- ===== SUBTITLE TABLE ===== -->
190
+ <section class="panel table-panel">
191
+ <div class="panel-head">
192
+ <h2 class="panel-title">
193
+ <svg viewBox="0 0 20 20" fill="currentColor" class="icon-sm"><path fill-rule="evenodd" d="M4 4a2 2 0 012-2h4.586A2 2 0 0112 2.586L15.414 6A2 2 0 0116 7.414V16a2 2 0 01-2 2H6a2 2 0 01-2-2V4z" clip-rule="evenodd"/></svg>
194
+ Bảng Subtitle
195
+ </h2>
196
+ <div class="table-meta">
197
+ <span class="seg-count" id="segmentCount">0 dòng</span>
198
+ <button class="btn btn-ghost btn-sm" id="btnCollapseTable" title="Thu gọn">
199
+ <svg viewBox="0 0 20 20" fill="currentColor" class="icon-xs"><path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd"/></svg>
200
+ </button>
201
+ </div>
202
+ </div>
203
+ <div class="table-scroll" id="tableScroll">
204
+ <table>
205
+ <thead>
206
+ <tr>
207
+ <th class="col-idx">#</th>
208
+ <th class="col-time">Bắt đầu</th>
209
+ <th class="col-time">Kết thúc</th>
210
+ <th class="col-text">Nội dung</th>
211
+ <th class="col-act">Thao tác</th>
212
+ </tr>
213
+ </thead>
214
+ <tbody id="subtitleBody">
215
+ <tr class="empty-row">
216
+ <td colspan="5">
217
+ <div class="empty-state">
218
+ <svg viewBox="0 0 48 48" fill="none" class="empty-icon">
219
+ <rect x="6" y="10" width="36" height="28" rx="4" stroke="currentColor" stroke-width="1.5"/>
220
+ <line x1="12" y1="20" x2="36" y2="20" stroke="currentColor" stroke-width="1.5" opacity="0.3"/>
221
+ <line x1="12" y1="26" x2="30" y2="26" stroke="currentColor" stroke-width="1.5" opacity="0.3"/>
222
+ <line x1="12" y1="32" x2="24" y2="32" stroke="currentColor" stroke-width="1.5" opacity="0.3"/>
223
+ </svg>
224
+ <p>Chưa có subtitle. Upload video rồi bấm <strong>Auto sub tiếng Việt</strong> để bắt đầu.</p>
225
+ </div>
226
+ </td>
227
+ </tr>
228
+ </tbody>
229
+ </table>
230
+ </div>
231
+ </section>
232
+
233
+ </main>
234
+
235
+ <!-- ===== FOOTER ===== -->
236
+ <footer class="footer">
237
+ <span>Viet AutoSub Editor &mdash; Nhận diện giọng nói tiếng Việt bằng Whisper</span>
238
+ </footer>
239
+
240
+ <script src="static/app.js"></script>
241
+ </body>
242
+ </html>
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ fastapi==0.115.12
2
+ uvicorn[standard]==0.34.0
3
+ jinja2==3.1.6
4
+ python-multipart==0.0.20
5
+ faster-whisper==1.1.1