Gemma SRT Translate
Dịch và sửa phụ đề SRT bằng Gemma 4 12B vision (llama-server + MTP).
Repo này chứa script + notebook Colab; model GGUF tải từ unsloth/gemma-4-12B-it-qat-GGUF.
Cấu trúc repo
YOUR_USERNAME/gemma-srt-translate/
├── README.md ← file này
├── config.yaml ← cấu hình mặc định
├── translate_srt.py ← pipeline chính
├── diarize_audio.py ← Pass 0: phân tích giọng nói (tùy chọn)
├── requirements-diarize.txt ← dependency cho Pass 0
├── colab/
│ └── GemmaSRT_Colab.ipynb ← chạy trên Google Colab (L4 24GB)
└── scripts/
├── download_models.py ← tải GGUF từ Unsloth
└── build_llama_server.sh ← build llama-server Linux (Colab)
Chạy trên Google Colab (khuyến nghị L4 24GB)
Repo Private → không mở được bằng nút Open in Colab trên HF (lỗi 401).
Cách mở: tải colab/GemmaSRT_Colab.ipynb → Colab File → Upload notebook → dán HF_TOKEN vào cell cấu hình → lưu copy lên Drive Gemma/ để dùng lại.
Repo này nằm trên Hugging Face, không phải GitHub — link colab.research.google.com/github/... sẽ lỗi 404.
Cách mở (chọn một):
Nút Open in Colab trên HF (khuyến nghị):
colab/GemmaSRT_Colab.ipynb → bấm Open in ColabShortcut HF
/colab:
https://huggingface.co/STBack23/gemma-srt-translate/colabColab → File → Upload notebook → tải file
.ipynbtừ HF về rồi upload
Sau khi mở notebook:
- Runtime → Change runtime type → GPU L4 (hoặc T4/A100)
- Chạy tuần tự các cell (lần đầu ~15–20 phút: build llama-server + tải model)
- Upload video + SRT hoặc trỏ vào Google Drive
- Tải file
*.vi.srtvề máy
Chạy trên máy local (Windows)
Repo HF không chứa llama-server.exe — dùng bản Windows trong project gốc:
.\run-translate.ps1 -Video "phim.mp4" -InputSrt "phim.srt" -OutputSrt "phim.vi.srt"
Hoặc mở GUI: GemmaSRT.bat
Tải model thủ công
pip install huggingface_hub
python scripts/download_models.py --dest ./models
File tải về (~12–15 GB):
| File | Mục đích |
|---|---|
gemma-4-12B-it-qat-UD-Q4_K_XL.gguf |
Model chính |
mmproj-F16.gguf |
Vision projector |
mtp-gemma-4-12B-it.gguf |
MTP draft (tăng tốc) |
Pipeline
- Parse SRT → gom scene
- Pass 0 (tùy chọn): phân tích giọng nói (pyannote) → "ai nói câu nào" + giới tính/độ tuổi → gán vào từng cue để xưng hô nhất quán
- Pass 1: cắt frame (ffmpeg) → OCR/sửa SRT gốc (vision)
- Pass 2: dịch theo ngữ cảnh + xưng hô
- Ghi SRT dịch, SRT đã sửa, báo cáo JSON
Pass 0 — phân tích giọng nói (diarization)
Bật bằng --diarize (CLI) hoặc ENABLE_DIARIZE = True (Colab). Cần thêm:
pip install -r requirements-diarize.txt
Token HF phải bấm Agree điều kiện các model gated:
community-1 ·
3.1 ·
segmentation-3.0.
--gender-method model dùng audeering wav2vec2 age/gender (~1GB).
VRAM
| GPU | 1 phim | 2 phim song song |
|---|---|---|
| RTX 4060 Ti 16GB | ✅ | ❌ |
| Colab L4 24GB | ✅ | ❌ (dùng local + Colab = 2 phim độc lập) |
Cấu hình
Chỉnh config.yaml hoặc tham số CLI:
python translate_srt.py \
--video phim.mp4 \
--input-srt phim.srt \
--output-srt phim.vi.srt \
--target-lang Vietnamese \
--skip-correction # bỏ pass OCR (nhanh hơn)
Model gốc
Upload repo lên Hugging Face
Xem UPLOAD.md (trong project gốc: huggingface/UPLOAD.md).
- Downloads last month
- 115