{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# HachimiMT — Dịch Trung → Việt (Google Colab)\n", "\n", "Chạy app dịch truyện **HachimiMT / MoxhiMT** (CTranslate2) ngay trên Colab — tận dụng **CPU/GPU miễn phí** của Google, không cần cài gì trên máy.\n", "\n", "**Cách dùng:** Menu `Runtime → Run all` (hoặc Ctrl+F9). Cell cuối sẽ in ra một **link công khai** (`*.gradio.live`) — bấm vào đó để mở giao diện dịch.\n", "\n", "> Muốn nhanh hơn: `Runtime → Change runtime type → T4 GPU` trước khi Run all (app tự dùng GPU nếu có).\n", "\n", "Mã nguồn: tải từ HF Space [ngocdang83/HachimiMT-demo](https://huggingface.co/spaces/ngocdang83/HachimiMT-demo)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 1. Tải mã nguồn app (từ HF Space, ~60 KB)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import urllib.request, zipfile, os\n", "\n", "ZIP_URL = \"https://huggingface.co/spaces/ngocdang83/HachimiMT-demo/resolve/main/hachimimt-local.zip\"\n", "urllib.request.urlretrieve(ZIP_URL, \"hachimimt-local.zip\")\n", "with zipfile.ZipFile(\"hachimimt-local.zip\") as z:\n", " z.extractall(\".\")\n", "print(\"Đã tải + giải nén:\", sorted(os.listdir(\"hachimimt\")))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 2. Cài thư viện (CTranslate2 + Gradio + tokenizer) — ~1 phút" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!pip install -q -r hachimimt/requirements.txt" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 3. Chạy app — đợi link `*.gradio.live` hiện ra rồi bấm vào\n", "\n", "Lần dịch đầu sẽ tự tải model (~57 MB) từ Hugging Face. Để dừng: bấm nút ⏹ stop của cell." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os, sys\n", "\n", "# Bật link share công khai (gradio.live) — app đọc cờ này.\n", "os.environ[\"HACHIMIMT_SHARE\"] = \"1\"\n", "\n", "# Chạy app từ thư mục src/ (import phẳng giống khi chạy local).\n", "sys.path.insert(0, os.path.abspath(\"hachimimt/src\"))\n", "import app\n", "app.main()" ] } ], "metadata": { "colab": { "name": "HachimiMT — Dịch Trung Việt", "provenance": [] }, "kernelspec": { "display_name": "Python 3", "name": "python3" }, "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 0 }