DANGDOCAO commited on
Commit
576ac4c
·
verified ·
1 Parent(s): b6bf661

Delete HVU_QA/HVU_QA_end_to_end_guide.ipynb

Browse files
Files changed (1) hide show
  1. HVU_QA/HVU_QA_end_to_end_guide.ipynb +0 -643
HVU_QA/HVU_QA_end_to_end_guide.ipynb DELETED
@@ -1,643 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "markdown",
5
- "metadata": {},
6
- "source": [
7
- "# HVU_QA - Notebook h??ng d?n s? d?ng\n",
8
- "\n",
9
- "Notebook n?y ???c t?ch th?nh **2 lu?ng r? r?ng**:\n",
10
- "- **Ph?n A - Full project**: d?nh cho ng??i t?i to?n b? source code ?? d?ng v? ph?t tri?n ti?p.\n",
11
- "- **Ph?n B - Ch?y nhanh b?ng tool**: d?nh cho ng??i ch? d?ng `HVU_QA_tool.py` ho?c `HVU_QA_tool.bat` ?? d?ng runtime v? ch?y m? h?nh sinh c?u h?i.\n",
12
- "\n",
13
- "Notebook ???c vi?t ?? ch?y t? th? m?c g?c c?a repo `HVU_QA`.\n"
14
- ]
15
- },
16
- {
17
- "cell_type": "markdown",
18
- "metadata": {},
19
- "source": [
20
- "## 0. Chu?n b? helper d?ng chung\n",
21
- "\n",
22
- "Cell d??i ??y s?:\n",
23
- "- t?m th? m?c g?c project\n",
24
- "- chu?n h?a ???ng d?n `venv`\n",
25
- "- cung c?p h?m ch?y l?nh shell t? notebook\n",
26
- "- cung c?p h?m ch? server ph?n h?i ?n ??nh\n",
27
- "- cung c?p th? m?c demo cho ph?n `Quick tool`\n"
28
- ]
29
- },
30
- {
31
- "cell_type": "code",
32
- "metadata": {},
33
- "execution_count": null,
34
- "outputs": [],
35
- "source": [
36
- "from __future__ import annotations\n",
37
- "\n",
38
- "import json\n",
39
- "import os\n",
40
- "import platform\n",
41
- "import shutil\n",
42
- "import subprocess\n",
43
- "import sys\n",
44
- "import time\n",
45
- "import urllib.request\n",
46
- "from pathlib import Path\n",
47
- "\n",
48
- "\n",
49
- "def find_project_root(start: Path) -> Path:\n",
50
- " current = start.resolve()\n",
51
- " while True:\n",
52
- " markers = [\n",
53
- " current / 'main.py',\n",
54
- " current / 'requirements.txt',\n",
55
- " current / 'backend' / 'app.py',\n",
56
- " current / 'frontend' / 'index.html',\n",
57
- " current / 'HVU_QA_tool.py',\n",
58
- " ]\n",
59
- " if all(marker.exists() for marker in markers):\n",
60
- " return current\n",
61
- " if current.parent == current:\n",
62
- " raise FileNotFoundError('Kh?ng t?m th?y th? m?c g?c c?a project HVU_QA t? notebook hi?n t?i.')\n",
63
- " current = current.parent\n",
64
- "\n",
65
- "\n",
66
- "PROJECT_ROOT = find_project_root(Path.cwd())\n",
67
- "os.chdir(PROJECT_ROOT)\n",
68
- "\n",
69
- "IS_WINDOWS = platform.system().lower().startswith('win')\n",
70
- "VENV_DIR = PROJECT_ROOT / 'venv'\n",
71
- "VENV_PYTHON = VENV_DIR / ('Scripts/python.exe' if IS_WINDOWS else 'bin/python')\n",
72
- "WEB_LOG_FILE = PROJECT_ROOT / 'hvu_qa_web.log'\n",
73
- "QUICK_TOOL_DIR = PROJECT_ROOT / '_notebook_quick_tool'\n",
74
- "QUICK_TOOL_RUNTIME = QUICK_TOOL_DIR / 'HVU_QA_runtime'\n",
75
- "\n",
76
- "\n",
77
- "def print_title(title: str) -> None:\n",
78
- " print(f'\\n=== {title} ===')\n",
79
- "\n",
80
- "\n",
81
- "def run_command(command: list[str], *, cwd: Path | None = None, env: dict[str, str] | None = None, check: bool = True):\n",
82
- " print_title('Ch?y l?nh')\n",
83
- " print(' '.join(command))\n",
84
- " result = subprocess.run(\n",
85
- " command,\n",
86
- " cwd=str(cwd or PROJECT_ROOT),\n",
87
- " env=env,\n",
88
- " text=True,\n",
89
- " encoding='utf-8',\n",
90
- " capture_output=True,\n",
91
- " )\n",
92
- " if result.stdout:\n",
93
- " print(result.stdout)\n",
94
- " if result.stderr:\n",
95
- " print(result.stderr)\n",
96
- " if check and result.returncode != 0:\n",
97
- " raise RuntimeError(f'L?nh th?t b?i v?i m? l?i {result.returncode}')\n",
98
- " return result\n",
99
- "\n",
100
- "\n",
101
- "def wait_for_json(url: str, timeout: int = 45):\n",
102
- " deadline = time.time() + timeout\n",
103
- " last_error = None\n",
104
- " while time.time() < deadline:\n",
105
- " try:\n",
106
- " with urllib.request.urlopen(url, timeout=3) as response:\n",
107
- " return json.loads(response.read().decode('utf-8'))\n",
108
- " except Exception as exc: # noqa: BLE001\n",
109
- " last_error = exc\n",
110
- " time.sleep(1)\n",
111
- " raise RuntimeError(f'Kh?ng nh?n ???c ph?n h?i JSON t? {url} sau {timeout} gi?y. L?i cu?i: {last_error}')\n",
112
- "\n",
113
- "\n",
114
- "def read_log_tail(path: Path, lines: int = 40) -> str:\n",
115
- " if not path.exists():\n",
116
- " return '(Ch?a c? log server.)'\n",
117
- " content = path.read_text(encoding='utf-8', errors='ignore').splitlines()\n",
118
- " if not content:\n",
119
- " return '(Log server ?ang tr?ng.)'\n",
120
- " return '\\n'.join(content[-lines:])\n",
121
- "\n",
122
- "\n",
123
- "print_title('Th?ng tin m?i tr??ng')\n",
124
- "print('PROJECT_ROOT =', PROJECT_ROOT)\n",
125
- "print('Notebook Python =', sys.executable)\n",
126
- "print('VENV_PYTHON =', VENV_PYTHON)\n",
127
- "print('IS_WINDOWS =', IS_WINDOWS)\n",
128
- "print('WEB_LOG_FILE =', WEB_LOG_FILE)\n",
129
- "print('QUICK_TOOL_DIR =', QUICK_TOOL_DIR)\n"
130
- ]
131
- },
132
- {
133
- "cell_type": "markdown",
134
- "metadata": {},
135
- "source": [
136
- "# Ph?n A - Full project\n",
137
- "\n",
138
- "Ph?n n?y d?nh cho tr??ng h?p b?n ?? t?i **to?n b? project `HVU_QA`** v? mu?n d?ng ho?c ph?t tri?n ti?p.\n"
139
- ]
140
- },
141
- {
142
- "cell_type": "markdown",
143
- "metadata": {},
144
- "source": [
145
- "## A1. Ki?m tra c?u tr?c project\n",
146
- "\n",
147
- "Cell n?y x?c nh?n nhanh c?c file quan tr?ng ?? c? trong repo.\n"
148
- ]
149
- },
150
- {
151
- "cell_type": "code",
152
- "metadata": {},
153
- "execution_count": null,
154
- "outputs": [],
155
- "source": [
156
- "important_paths = [\n",
157
- " 'main.py',\n",
158
- " 'HVU_QA_tool.py',\n",
159
- " 'requirements.txt',\n",
160
- " 'backend/app.py',\n",
161
- " 'backend/__init__.py',\n",
162
- " 'frontend/index.html',\n",
163
- " 'frontend/app.js',\n",
164
- " 'frontend/style.css',\n",
165
- " 'generate_question.py',\n",
166
- " 'fine_tune_qg.py',\n",
167
- "]\n",
168
- "\n",
169
- "print_title('Ki?m tra file quan tr?ng')\n",
170
- "for item in important_paths:\n",
171
- " path = PROJECT_ROOT / item\n",
172
- " print(f'{item:30} ->', 'OK' if path.exists() else 'THI?U')\n"
173
- ]
174
- },
175
- {
176
- "cell_type": "markdown",
177
- "metadata": {},
178
- "source": [
179
- "## A2. T?o m?i tr??ng ?o `venv`\n",
180
- "\n",
181
- "Cell n?y s? t?o `venv` n?u ch?a c?.\n"
182
- ]
183
- },
184
- {
185
- "cell_type": "code",
186
- "metadata": {},
187
- "execution_count": null,
188
- "outputs": [],
189
- "source": [
190
- "if VENV_PYTHON.exists():\n",
191
- " print('venv ?? t?n t?i:', VENV_DIR)\n",
192
- "else:\n",
193
- " run_command([sys.executable, '-m', 'venv', str(VENV_DIR)])\n",
194
- " print('?? t?o xong venv t?i:', VENV_DIR)\n"
195
- ]
196
- },
197
- {
198
- "cell_type": "markdown",
199
- "metadata": {},
200
- "source": [
201
- "## A3. C?i dependencies t? `requirements.txt`\n",
202
- "\n",
203
- "Cell n?y d?ng cho **full project**. N?u b?n ch? d?ng launcher m?t file th? sang **Ph?n B**.\n"
204
- ]
205
- },
206
- {
207
- "cell_type": "code",
208
- "metadata": {},
209
- "execution_count": null,
210
- "outputs": [],
211
- "source": [
212
- "run_command([str(VENV_PYTHON), '-m', 'pip', 'install', '--upgrade', 'pip'])\n",
213
- "run_command([str(VENV_PYTHON), '-m', 'pip', 'install', '-r', str(PROJECT_ROOT / 'requirements.txt')])\n"
214
- ]
215
- },
216
- {
217
- "cell_type": "markdown",
218
- "metadata": {},
219
- "source": [
220
- "## A4. T?i ho?c ??ng b? model b?ng `HVU_QA_tool.py`\n",
221
- "\n",
222
- "Notebook g?i tool ? **ch? ?? full project** ?? ??ng b? model n?u c?n.\n",
223
- "\n",
224
- "- `BEST_MODEL_ONLY = False`: t?i model g?c theo repo hi?n t?i.\n",
225
- "- `BEST_MODEL_ONLY = True`: ch? d?ng khi repo tr?n Hugging Face th?t s? c? th? m?c `best-model`.\n"
226
- ]
227
- },
228
- {
229
- "cell_type": "code",
230
- "metadata": {},
231
- "execution_count": null,
232
- "outputs": [],
233
- "source": [
234
- "BEST_MODEL_ONLY = False\n",
235
- "full_project_tool_command = [str(VENV_PYTHON), str(PROJECT_ROOT / 'HVU_QA_tool.py'), '--skip-run']\n",
236
- "if BEST_MODEL_ONLY:\n",
237
- " full_project_tool_command.append('--best-model-only')\n",
238
- "run_command(full_project_tool_command)\n"
239
- ]
240
- },
241
- {
242
- "cell_type": "markdown",
243
- "metadata": {},
244
- "source": [
245
- "## A5. Ki?m tra model local sau khi t?i\n",
246
- "\n",
247
- "N?u ? b??c tr?n d?ng `BEST_MODEL_ONLY = True`, notebook s? ch? b?t bu?c ki?m tra `best-model`.\n"
248
- ]
249
- },
250
- {
251
- "cell_type": "code",
252
- "metadata": {},
253
- "execution_count": null,
254
- "outputs": [],
255
- "source": [
256
- "model_root = PROJECT_ROOT / 't5-viet-qg-finetuned'\n",
257
- "best_model_only = bool(globals().get('BEST_MODEL_ONLY', False))\n",
258
- "\n",
259
- "root_required_files = [\n",
260
- " model_root / 'config.json',\n",
261
- " model_root / 'generation_config.json',\n",
262
- " model_root / 'model.safetensors',\n",
263
- " model_root / 'tokenizer_config.json',\n",
264
- " model_root / 'special_tokens_map.json',\n",
265
- " model_root / 'spiece.model',\n",
266
- "]\n",
267
- "\n",
268
- "best_required_files = [\n",
269
- " model_root / 'best-model' / 'config.json',\n",
270
- " model_root / 'best-model' / 'generation_config.json',\n",
271
- " model_root / 'best-model' / 'model.safetensors',\n",
272
- " model_root / 'best-model' / 'tokenizer_config.json',\n",
273
- " model_root / 'best-model' / 'special_tokens_map.json',\n",
274
- " model_root / 'best-model' / 'spiece.model',\n",
275
- "]\n",
276
- "\n",
277
- "print_title('Ki?m tra model local')\n",
278
- "required_sets = [('best-model', best_required_files)] if best_model_only else [\n",
279
- " ('model g?c', root_required_files),\n",
280
- " ('best-model', best_required_files),\n",
281
- "]\n",
282
- "\n",
283
- "for label, files in required_sets:\n",
284
- " print(f'\\n{label}:')\n",
285
- " for item in files:\n",
286
- " print(item.relative_to(PROJECT_ROOT), '->', 'OK' if item.exists() else 'THI?U')\n"
287
- ]
288
- },
289
- {
290
- "cell_type": "markdown",
291
- "metadata": {},
292
- "source": [
293
- "## A6. Ch?y web app b?ng `main.py`\n",
294
- "\n",
295
- "Cell n?y s? ch?y Flask server ? background, **kh?ng t? m? tr?nh duy?t**, v? ghi log v?o `hvu_qa_web.log`.\n"
296
- ]
297
- },
298
- {
299
- "cell_type": "code",
300
- "metadata": {},
301
- "execution_count": null,
302
- "outputs": [],
303
- "source": [
304
- "WEB_HOST = '127.0.0.1'\n",
305
- "WEB_PORT = '5000'\n",
306
- "base_url = f'http://{WEB_HOST}:{WEB_PORT}'\n",
307
- "\n",
308
- "if 'web_process' in globals() and web_process and web_process.poll() is None:\n",
309
- " print('Web app ?ang ch?y r?i. PID =', web_process.pid)\n",
310
- " print('URL =', base_url)\n",
311
- "else:\n",
312
- " web_env = os.environ.copy()\n",
313
- " web_env['HVU_HOST'] = WEB_HOST\n",
314
- " web_env['HVU_PORT'] = WEB_PORT\n",
315
- " web_env['HVU_OPEN_BROWSER'] = '0'\n",
316
- "\n",
317
- " if WEB_LOG_FILE.exists():\n",
318
- " WEB_LOG_FILE.unlink()\n",
319
- "\n",
320
- " with WEB_LOG_FILE.open('w', encoding='utf-8') as log_stream:\n",
321
- " web_process = subprocess.Popen(\n",
322
- " [str(VENV_PYTHON), str(PROJECT_ROOT / 'main.py')],\n",
323
- " cwd=str(PROJECT_ROOT),\n",
324
- " env=web_env,\n",
325
- " stdout=log_stream,\n",
326
- " stderr=subprocess.STDOUT,\n",
327
- " )\n",
328
- "\n",
329
- " try:\n",
330
- " info_payload = wait_for_json(base_url + '/api/info', timeout=45)\n",
331
- " except Exception as exc: # noqa: BLE001\n",
332
- " return_code = web_process.poll()\n",
333
- " raise RuntimeError(\n",
334
- " 'Web app kh?ng kh?i ??ng th?nh c?ng. '\n",
335
- " f'returncode={return_code}\\n\\nLog g?n nh?t:\\n{read_log_tail(WEB_LOG_FILE, lines=80)}'\n",
336
- " ) from exc\n",
337
- "\n",
338
- " print('?? kh?i ??ng web app. PID =', web_process.pid)\n",
339
- " print('URL =', base_url)\n",
340
- " print('Model ?ang ch?n =', info_payload.get('selected_model_id'))\n",
341
- " print('T?n model hi?n th? =', info_payload.get('model_name'))\n",
342
- " print('Log server =', WEB_LOG_FILE)\n"
343
- ]
344
- },
345
- {
346
- "cell_type": "markdown",
347
- "metadata": {},
348
- "source": [
349
- "## A7. G?i th? API backend\n",
350
- "\n",
351
- "Cell n?y g?i `GET /api/info`, `POST /api/generate`, v? th? `POST /api/model` n?u c? nhi?u h?n m?t model kh? d?ng.\n"
352
- ]
353
- },
354
- {
355
- "cell_type": "code",
356
- "metadata": {},
357
- "execution_count": null,
358
- "outputs": [],
359
- "source": [
360
- "def http_get_json(url: str):\n",
361
- " with urllib.request.urlopen(url) as response:\n",
362
- " return json.loads(response.read().decode('utf-8'))\n",
363
- "\n",
364
- "\n",
365
- "def http_post_json(url: str, payload: dict):\n",
366
- " data = json.dumps(payload, ensure_ascii=False).encode('utf-8')\n",
367
- " request = urllib.request.Request(url, data=data, headers={'Content-Type': 'application/json'})\n",
368
- " with urllib.request.urlopen(request) as response:\n",
369
- " return json.loads(response.read().decode('utf-8'))\n",
370
- "\n",
371
- "\n",
372
- "info_payload = http_get_json(base_url + '/api/info')\n",
373
- "print_title('GET /api/info')\n",
374
- "print(json.dumps(info_payload, ensure_ascii=False, indent=2))\n",
375
- "\n",
376
- "generate_payload = {\n",
377
- " 'text': 'C? s? gi?o d?c ??i h?c c? nhi?m v? t? ch?c ??o t?o, nghi?n c?u khoa h?c v? ph?c v? c?ng ??ng.',\n",
378
- " 'num_questions': 3,\n",
379
- "}\n",
380
- "generate_result = http_post_json(base_url + '/api/generate', generate_payload)\n",
381
- "print_title('POST /api/generate')\n",
382
- "print(json.dumps(generate_result, ensure_ascii=False, indent=2))\n",
383
- "\n",
384
- "available_models = info_payload.get('available_models', [])\n",
385
- "print_title('Danh s?ch model kh? d?ng')\n",
386
- "print(json.dumps(available_models, ensure_ascii=False, indent=2))\n",
387
- "\n",
388
- "if len(available_models) < 2:\n",
389
- " print('Ch? c? m?t model kh? d?ng n?n b? qua b??c chuy?n model.')\n",
390
- "else:\n",
391
- " current_model_id = info_payload.get('selected_model_id')\n",
392
- " target_model_id = next(item['id'] for item in available_models if item['id'] != current_model_id)\n",
393
- " switched_payload = http_post_json(base_url + '/api/model', {'model_id': target_model_id})\n",
394
- " print_title('POST /api/model')\n",
395
- " print(json.dumps(switched_payload, ensure_ascii=False, indent=2))\n",
396
- "\n",
397
- " restored_payload = http_post_json(base_url + '/api/model', {'model_id': current_model_id})\n",
398
- " print_title('Kh?i ph?c model ban ??u')\n",
399
- " print(json.dumps(restored_payload, ensure_ascii=False, indent=2))\n"
400
- ]
401
- },
402
- {
403
- "cell_type": "markdown",
404
- "metadata": {},
405
- "source": [
406
- "## A8. Ch?y `generate_question.py` b?ng CLI\n",
407
- "\n",
408
- "Cell n?y minh h?a c?ch ch?y CLI tr?c ti?p m? kh?ng c?n m? giao di?n web.\n"
409
- ]
410
- },
411
- {
412
- "cell_type": "code",
413
- "metadata": {},
414
- "execution_count": null,
415
- "outputs": [],
416
- "source": [
417
- "cli_text = 'C? s? gi?o d?c ??i h?c th?c hi?n ho?t ??ng ??o t?o, nghi?n c?u khoa h?c v? ph?c v? c?ng ??ng theo quy ??nh c?a ph?p lu?t.'\n",
418
- "run_command([\n",
419
- " str(VENV_PYTHON),\n",
420
- " str(PROJECT_ROOT / 'generate_question.py'),\n",
421
- " '--text',\n",
422
- " cli_text,\n",
423
- " '--num_questions',\n",
424
- " '3',\n",
425
- " '--output_format',\n",
426
- " 'text',\n",
427
- "])\n"
428
- ]
429
- },
430
- {
431
- "cell_type": "markdown",
432
- "metadata": {},
433
- "source": [
434
- "## A9. Xem l?nh fine-tune m?u\n",
435
- "\n",
436
- "Fine-tune l? t?c v? n?ng, n?n notebook ch? in l?nh m?u ?? b?n copy khi c?n.\n"
437
- ]
438
- },
439
- {
440
- "cell_type": "code",
441
- "metadata": {},
442
- "execution_count": null,
443
- "outputs": [],
444
- "source": [
445
- "print_title('Fine-tune tr?n CPU')\n",
446
- "print(f'{VENV_PYTHON} fine_tune_qg.py --device cpu --output_dir t5-viet-qg-finetuned-cpu')\n",
447
- "\n",
448
- "print_title('Fine-tune tr?n GPU')\n",
449
- "print(\n",
450
- " f'{VENV_PYTHON} fine_tune_qg.py --device cuda --fp16 --gradient_checkpointing '\n",
451
- " '--output_dir t5-viet-qg-finetuned'\n",
452
- ")\n"
453
- ]
454
- },
455
- {
456
- "cell_type": "markdown",
457
- "metadata": {},
458
- "source": [
459
- "## A10. D?ng web app\n",
460
- "\n",
461
- "Khi kh?ng d?ng n?a, h?y ch?y cell n?y ?? d?ng server ?? b?t ? background.\n"
462
- ]
463
- },
464
- {
465
- "cell_type": "code",
466
- "metadata": {},
467
- "execution_count": null,
468
- "outputs": [],
469
- "source": [
470
- "if 'web_process' in globals() and web_process and web_process.poll() is None:\n",
471
- " web_process.terminate()\n",
472
- " try:\n",
473
- " web_process.wait(timeout=5)\n",
474
- " except subprocess.TimeoutExpired:\n",
475
- " web_process.kill()\n",
476
- " web_process.wait(timeout=5)\n",
477
- " print('?? d?ng web app. PID =', web_process.pid)\n",
478
- "else:\n",
479
- " print('Kh?ng c? web app n?o ?ang ch?y.')\n"
480
- ]
481
- },
482
- {
483
- "cell_type": "markdown",
484
- "metadata": {},
485
- "source": [
486
- "# Ph?n B - Ch?y nhanh b?ng tool\n",
487
- "\n",
488
- "Ph?n n?y m? ph?ng ??ng tr??ng h?p **ng??i d?ng ch? c? `HVU_QA_tool.py` ho?c `HVU_QA_tool.bat`** trong m?t th? m?c tr?ng.\n",
489
- "\n",
490
- "`HVU_QA_tool.py` m?i s?:\n",
491
- "- t? nh?n bi?t kh?ng c? full project c?nh n?\n",
492
- "- t? d?ng `HVU_QA_runtime/`\n",
493
- "- t? t?o virtualenv ri?ng n?u c?n\n",
494
- "- t? c?i dependencies runtime\n",
495
- "- t? t?i model t? Hugging Face\n",
496
- "- t? m? app\n"
497
- ]
498
- },
499
- {
500
- "cell_type": "markdown",
501
- "metadata": {},
502
- "source": [
503
- "## B1. T?o th? m?c demo ch? ch?a tool\n",
504
- "\n",
505
- "Cell n?y sao ch?p `HVU_QA_tool.py` v? `HVU_QA_tool.bat` sang m?t th? m?c demo ri?ng.\n"
506
- ]
507
- },
508
- {
509
- "cell_type": "code",
510
- "metadata": {},
511
- "execution_count": null,
512
- "outputs": [],
513
- "source": [
514
- "if QUICK_TOOL_DIR.exists():\n",
515
- " shutil.rmtree(QUICK_TOOL_DIR)\n",
516
- "QUICK_TOOL_DIR.mkdir(parents=True, exist_ok=True)\n",
517
- "shutil.copy2(PROJECT_ROOT / 'HVU_QA_tool.py', QUICK_TOOL_DIR / 'HVU_QA_tool.py')\n",
518
- "shutil.copy2(PROJECT_ROOT / 'HVU_QA_tool.bat', QUICK_TOOL_DIR / 'HVU_QA_tool.bat')\n",
519
- "\n",
520
- "print_title('Th? m?c quick tool')\n",
521
- "for item in QUICK_TOOL_DIR.iterdir():\n",
522
- " print(item.name)\n"
523
- ]
524
- },
525
- {
526
- "cell_type": "markdown",
527
- "metadata": {},
528
- "source": [
529
- "## B2. D?ng runtime standalone t? m?i file tool\n",
530
- "\n",
531
- "Cell n?y ch?y `HVU_QA_tool.py` trong th? m?c demo ? ch? ?? `--prepare-runtime-only` ?? ch?ng minh r?ng tool **kh?ng c?n ph? thu?c v?o full project local**.\n"
532
- ]
533
- },
534
- {
535
- "cell_type": "code",
536
- "metadata": {},
537
- "execution_count": null,
538
- "outputs": [],
539
- "source": [
540
- "run_command([\n",
541
- " str(VENV_PYTHON),\n",
542
- " str(QUICK_TOOL_DIR / 'HVU_QA_tool.py'),\n",
543
- " '--prepare-runtime-only',\n",
544
- "], cwd=QUICK_TOOL_DIR)\n"
545
- ]
546
- },
547
- {
548
- "cell_type": "markdown",
549
- "metadata": {},
550
- "source": [
551
- "## B3. Ki?m tra runtime ???c t?o ra\n",
552
- "\n",
553
- "Cell n?y li?t k? c?c file runtime t?i thi?u m? launcher ?? t? d?ng.\n"
554
- ]
555
- },
556
- {
557
- "cell_type": "code",
558
- "metadata": {},
559
- "execution_count": null,
560
- "outputs": [],
561
- "source": [
562
- "print_title('C?c file runtime standalone')\n",
563
- "for path in sorted(QUICK_TOOL_RUNTIME.rglob('*')):\n",
564
- " if path.is_file():\n",
565
- " print(path.relative_to(QUICK_TOOL_DIR).as_posix())\n"
566
- ]
567
- },
568
- {
569
- "cell_type": "markdown",
570
- "metadata": {},
571
- "source": [
572
- "## B4. L?nh th?t m? ng??i d?ng cu?i s? ch?y\n",
573
- "\n",
574
- "Trong th?c t?, ng??i d?ng ch? c?n ??t `HVU_QA_tool.py` ho?c c? c?p `HVU_QA_tool.py` + `HVU_QA_tool.bat` v?o m?t th? m?c r?i ch?y m?t trong c?c l?nh sau.\n"
575
- ]
576
- },
577
- {
578
- "cell_type": "code",
579
- "metadata": {},
580
- "execution_count": null,
581
- "outputs": [],
582
- "source": [
583
- "print_title('L?nh quick tool')\n",
584
- "print('python HVU_QA_tool.py')\n",
585
- "print('')\n",
586
- "print('Ho?c tr?n Windows: double-click HVU_QA_tool.bat')\n",
587
- "print('')\n",
588
- "print('Launcher s? t? t?o:')\n",
589
- "print('- .hvu_qa_tool_venv/ n?u m?y ch?a ? trong virtualenv')\n",
590
- "print('- HVU_QA_runtime/ n?u th? m?c hi?n t?i ch?a c? full project')\n",
591
- "print('- t5-viet-qg-finetuned/ trong runtime ?? ch?a model')\n"
592
- ]
593
- },
594
- {
595
- "cell_type": "markdown",
596
- "metadata": {},
597
- "source": [
598
- "## B5. Ch?y th?t ch? ?? quick tool\n",
599
- "\n",
600
- "Cell d??i ??y ?? **t?y ch?n**. M?c ??nh notebook s? kh?ng ch?y th?t v? b??c n?y c? th? t?i dependencies v? model t? Hugging Face.\n",
601
- "\n",
602
- "L?u ?:\n",
603
- "- `--best-model-only` ch? d?ng ???c khi repo tr?n Hugging Face th?t s? c? `best-model`.\n",
604
- "- N?u repo hi?n t?i ch? c? model g?c, launcher s? b?o l?i r? r?ng khi b?n ?p `--best-model-only`.\n"
605
- ]
606
- },
607
- {
608
- "cell_type": "code",
609
- "metadata": {},
610
- "execution_count": null,
611
- "outputs": [],
612
- "source": [
613
- "RUN_QUICK_TOOL_NOW = False\n",
614
- "\n",
615
- "quick_tool_command = [\n",
616
- " str(VENV_PYTHON),\n",
617
- " str(QUICK_TOOL_DIR / 'HVU_QA_tool.py'),\n",
618
- "]\n",
619
- "\n",
620
- "if RUN_QUICK_TOOL_NOW:\n",
621
- " run_command(quick_tool_command, cwd=QUICK_TOOL_DIR)\n",
622
- "else:\n",
623
- " print('B? qua ch?y th?t ?? tr?nh t?i dependency/model ngo?i ? mu?n.')\n",
624
- " print('Khi c?n, h?y ??t RUN_QUICK_TOOL_NOW = True r?i ch?y l?i cell n?y.')\n",
625
- " print('L?nh s? ch?y:')\n",
626
- " print(' '.join(quick_tool_command))\n"
627
- ]
628
- }
629
- ],
630
- "metadata": {
631
- "kernelspec": {
632
- "display_name": "Python 3",
633
- "language": "python",
634
- "name": "python3"
635
- },
636
- "language_info": {
637
- "name": "python",
638
- "version": "3.11"
639
- }
640
- },
641
- "nbformat": 4,
642
- "nbformat_minor": 5
643
- }