ngocdang83 commited on
Commit
1a857d7
·
verified ·
1 Parent(s): 941537c

Thêm notebook Colab vào Space (cho nút Open in Colab)

Browse files
Files changed (1) hide show
  1. HachimiMT_Colab.ipynb +98 -0
HachimiMT_Colab.ipynb ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "# HachimiMT — Dịch Trung → Việt (Google Colab)\n",
8
+ "\n",
9
+ "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",
10
+ "\n",
11
+ "**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",
12
+ "\n",
13
+ "> 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",
14
+ "\n",
15
+ "Mã nguồn: tải từ HF Space [ngocdang83/HachimiMT-demo](https://huggingface.co/spaces/ngocdang83/HachimiMT-demo)."
16
+ ]
17
+ },
18
+ {
19
+ "cell_type": "markdown",
20
+ "metadata": {},
21
+ "source": [
22
+ "### 1. Tải mã nguồn app (từ HF Space, ~60 KB)"
23
+ ]
24
+ },
25
+ {
26
+ "cell_type": "code",
27
+ "execution_count": null,
28
+ "metadata": {},
29
+ "outputs": [],
30
+ "source": [
31
+ "import urllib.request, zipfile, os\n",
32
+ "\n",
33
+ "ZIP_URL = \"https://huggingface.co/spaces/ngocdang83/HachimiMT-demo/resolve/main/hachimimt-local.zip\"\n",
34
+ "urllib.request.urlretrieve(ZIP_URL, \"hachimimt-local.zip\")\n",
35
+ "with zipfile.ZipFile(\"hachimimt-local.zip\") as z:\n",
36
+ " z.extractall(\".\")\n",
37
+ "print(\"Đã tải + giải nén:\", sorted(os.listdir(\"hachimimt\")))"
38
+ ]
39
+ },
40
+ {
41
+ "cell_type": "markdown",
42
+ "metadata": {},
43
+ "source": [
44
+ "### 2. Cài thư viện (CTranslate2 + Gradio + tokenizer) — ~1 phút"
45
+ ]
46
+ },
47
+ {
48
+ "cell_type": "code",
49
+ "execution_count": null,
50
+ "metadata": {},
51
+ "outputs": [],
52
+ "source": [
53
+ "!pip install -q -r hachimimt/requirements.txt"
54
+ ]
55
+ },
56
+ {
57
+ "cell_type": "markdown",
58
+ "metadata": {},
59
+ "source": [
60
+ "### 3. Chạy app — đợi link `*.gradio.live` hiện ra rồi bấm vào\n",
61
+ "\n",
62
+ "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."
63
+ ]
64
+ },
65
+ {
66
+ "cell_type": "code",
67
+ "execution_count": null,
68
+ "metadata": {},
69
+ "outputs": [],
70
+ "source": [
71
+ "import os, sys\n",
72
+ "\n",
73
+ "# Bật link share công khai (gradio.live) — app đọc cờ này.\n",
74
+ "os.environ[\"HACHIMIMT_SHARE\"] = \"1\"\n",
75
+ "\n",
76
+ "# Chạy app từ thư mục src/ (import phẳng giống khi chạy local).\n",
77
+ "sys.path.insert(0, os.path.abspath(\"hachimimt/src\"))\n",
78
+ "import app\n",
79
+ "app.main()"
80
+ ]
81
+ }
82
+ ],
83
+ "metadata": {
84
+ "colab": {
85
+ "name": "HachimiMT — Dịch Trung Việt",
86
+ "provenance": []
87
+ },
88
+ "kernelspec": {
89
+ "display_name": "Python 3",
90
+ "name": "python3"
91
+ },
92
+ "language_info": {
93
+ "name": "python"
94
+ }
95
+ },
96
+ "nbformat": 4,
97
+ "nbformat_minor": 0
98
+ }