Spaces:
Running on Zero
Running on Zero
Add Option models
Browse files
app.py
CHANGED
|
@@ -27,22 +27,48 @@ except ImportError:
|
|
| 27 |
return lambda f: f
|
| 28 |
spaces = _MockSpaces()
|
| 29 |
|
| 30 |
-
# 1.
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
# 2. Cấu hình nhãn & biểu tượng & màu sắc
|
| 48 |
LABEL_CONFIG = {
|
|
@@ -79,7 +105,20 @@ LABEL_CONFIG = {
|
|
| 79 |
ORDERED_LABELS = ["HARD_SKILL", "SOFT_SKILL", "EDUCATION", "MAJOR"]
|
| 80 |
|
| 81 |
@spaces.GPU
|
| 82 |
-
def analyze_ner(title, text, threshold=0.0):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
if not text or not text.strip():
|
| 84 |
empty_msg = """
|
| 85 |
<div style="padding: 24px; text-align: center; color: #6b7280; font-family: monospace;">
|
|
@@ -91,8 +130,29 @@ def analyze_ner(title, text, threshold=0.0):
|
|
| 91 |
title = title.strip() if title and title.strip() else "Kết quả phân tích JD"
|
| 92 |
raw_text = text.strip()
|
| 93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
# Thực hiện trích xuất
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
# Lọc theo ngưỡng tin cậy
|
| 98 |
entities = [
|
|
@@ -208,6 +268,7 @@ def analyze_ner(title, text, threshold=0.0):
|
|
| 208 |
<div class="jd-result-card">
|
| 209 |
<div class="border-line-double">===============================================================================================</div>
|
| 210 |
<div class="jd-title">📌 {html.escape(title)}</div>
|
|
|
|
| 211 |
<div class="border-line-single">-----------------------------------------------------------------------------------------------</div>
|
| 212 |
|
| 213 |
<div class="section-heading">Văn bản gốc:</div>
|
|
@@ -232,6 +293,7 @@ def analyze_ner(title, text, threshold=0.0):
|
|
| 232 |
# 4. Văn bản Plain Text hoàn chỉnh (sao chép nhanh)
|
| 233 |
plain_output = f"""===============================================================================================
|
| 234 |
📌 {title}
|
|
|
|
| 235 |
-----------------------------------------------------------------------------------------------
|
| 236 |
Văn bản gốc:
|
| 237 |
{raw_text}
|
|
@@ -245,15 +307,89 @@ Thống kê danh sách thực thể:
|
|
| 245 |
|
| 246 |
return card_html, plain_output, table_rows
|
| 247 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 248 |
# Custom CSS cho giao diện
|
| 249 |
custom_css = """
|
| 250 |
/* Font và định dạng tổng quát */
|
| 251 |
.container {
|
| 252 |
-
max-width:
|
| 253 |
margin: 0 auto !important;
|
| 254 |
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
| 255 |
}
|
| 256 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 257 |
/* Thẻ kết quả mô phỏng chính xác hình mẫu */
|
| 258 |
.jd-result-card {
|
| 259 |
background-color: #ffffff;
|
|
@@ -269,6 +405,23 @@ custom_css = """
|
|
| 269 |
|
| 270 |
/* Dark mode compatibility */
|
| 271 |
@media (prefers-color-scheme: dark) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
.jd-result-card {
|
| 273 |
background-color: #1e293b;
|
| 274 |
border-color: #334155;
|
|
@@ -305,7 +458,7 @@ custom_css = """
|
|
| 305 |
font-size: 16px;
|
| 306 |
font-weight: 700;
|
| 307 |
color: #111827;
|
| 308 |
-
margin: 6px 0;
|
| 309 |
}
|
| 310 |
@media (prefers-color-scheme: dark) {
|
| 311 |
.jd-title { color: #f8fafc; }
|
|
@@ -383,12 +536,40 @@ custom_css = """
|
|
| 383 |
# Khởi tạo giao diện Gradio
|
| 384 |
with gr.Blocks(title="XLM-RoBERTa NER Job Description") as demo:
|
| 385 |
gr.HTML(f"<style>{custom_css}</style>")
|
| 386 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 387 |
"""
|
| 388 |
-
|
| 389 |
-
Phân loại và trích xuất thực thể theo 4 nhãn chuẩn bằng mô hình **[XLM-RoBERTa NER 4Labels v2](https://huggingface.co/NhanSoHocCode/xlmr-ner-4labels-v2)**.
|
| 390 |
-
|
| 391 |
-
<div style="margin-top: 10px; margin-bottom: 15px;">
|
| 392 |
<span class="legend-pill" style="background-color: #ef4444;">🛠️ HARD_SKILL: Kỹ năng chuyên môn / Công nghệ</span>
|
| 393 |
<span class="legend-pill" style="background-color: #d97706;">🤝 SOFT_SKILL: Kỹ năng mềm / Giao tiếp</span>
|
| 394 |
<span class="legend-pill" style="background-color: #0284c7;">🎓 EDUCATION: Học vị / Bằng cấp</span>
|
|
@@ -439,20 +620,26 @@ with gr.Blocks(title="XLM-RoBERTa NER Job Description") as demo:
|
|
| 439 |
[
|
| 440 |
"Mẫu JD Senior Golang / Distributed Systems",
|
| 441 |
"Tuyển dụng Senior Backend Engineer yêu cầu tốt nghiệp Cử nhân chuyên ngành Công nghệ thông tin. Có từ 4 năm kinh nghiệm làm việc với Golang, gRPC, Microservices và Event-Driven Architecture. Thành thạo cơ sở dữ liệu PostgreSQL, Redis Caching và Apache Kafka. Kinh nghiệm triển khai trên Kubernetes, Docker, CI/CD. Sử dụng thành thạo Cursor, GitHub Copilot để tăng tốc lập trình. Yêu cầu kỹ năng làm việc nhóm, tư duy giải quyết vấn đề và tiếng Anh giao tiếp tốt.",
|
| 442 |
-
0.5
|
|
|
|
|
|
|
| 443 |
],
|
| 444 |
[
|
| 445 |
"Mẫu JD AI / Data Science Engineer",
|
| 446 |
"Tìm kiếm Kỹ sư AI tốt nghiệp Thạc sĩ hoặc Cử nhân ngành Khoa học Máy tính. Có kinh nghiệm với Python, PyTorch, Transformers và mô hình ngôn ngữ lớn (LLM). Thành thạo kỹ thuật RAG, Fine-tuning, triển khai mô hình với FastAPI, Docker trên GCP. Yêu cầu tư duy phản biện, kỹ năng nghiên cứu độc lập và khả năng tiếng Anh chuyên ngành xuất sắc.",
|
| 447 |
-
0.5
|
|
|
|
|
|
|
| 448 |
],
|
| 449 |
[
|
| 450 |
"Mẫu JD Frontend Lead Developer",
|
| 451 |
"Yêu cầu bằng Kỹ sư hoặc Đại học chuyên ngành Công nghệ phần mềm. Tối thiểu 5 năm kinh nghiệm với JavaScript, TypeScript, ReactJS, Next.js và TailwindCSS. Có kinh nghiệm tối ưu hiệu năng web, quản trị state với Redux Toolkit hoặc Zustand. Cần có kỹ năng lãnh đạo đội ngũ, khả năng giao tiếp và truyền đạt thông tin mạch lạc.",
|
| 452 |
-
0.5
|
|
|
|
|
|
|
| 453 |
]
|
| 454 |
],
|
| 455 |
-
inputs=[title_input, text_input, threshold_slider],
|
| 456 |
label="💡 Nhấp vào các mẫu JD để thử nghiệm nhanh:"
|
| 457 |
)
|
| 458 |
|
|
@@ -474,18 +661,34 @@ with gr.Blocks(title="XLM-RoBERTa NER Job Description") as demo:
|
|
| 474 |
label="Danh sách thực thể chi tiết"
|
| 475 |
)
|
| 476 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 477 |
# Xử lý sự kiện click nút
|
|
|
|
|
|
|
|
|
|
| 478 |
submit_btn.click(
|
| 479 |
fn=analyze_ner,
|
| 480 |
-
inputs=
|
| 481 |
-
outputs=
|
| 482 |
)
|
| 483 |
|
| 484 |
# Chạy lần đầu khi load trang
|
| 485 |
demo.load(
|
| 486 |
fn=analyze_ner,
|
| 487 |
-
inputs=
|
| 488 |
-
outputs=
|
| 489 |
)
|
| 490 |
|
| 491 |
if __name__ == "__main__":
|
|
|
|
| 27 |
return lambda f: f
|
| 28 |
spaces = _MockSpaces()
|
| 29 |
|
| 30 |
+
# 1. Quản lý danh sách mô hình & Caching Pipeline
|
| 31 |
+
DEFAULT_MODEL = "NhanSoHocCode/xlmr-ner-4labels-v2"
|
| 32 |
+
MODEL_OPTIONS = [
|
| 33 |
+
("✨ XLM-RoBERTa NER 4Labels v2 (Mới nhất / Khuyên dùng)", "NhanSoHocCode/xlmr-ner-4labels-v2"),
|
| 34 |
+
("🏷️ XLM-RoBERTa NER 4Labels v1 (Bản gốc)", "NhanSoHocCode/xlmr-ner-4labels"),
|
| 35 |
+
("⚙️ Tùy chỉnh (Nhập checkpoint Hugging Face khác...)", "custom")
|
| 36 |
+
]
|
| 37 |
+
|
| 38 |
+
PIPELINE_CACHE = {}
|
| 39 |
+
|
| 40 |
+
def get_ner_pipeline(model_id: str):
|
| 41 |
+
"""
|
| 42 |
+
Tải hoặc lấy từ cache pipeline trích xuất thực thể theo model_id.
|
| 43 |
+
Hỗ trợ cả checkpoint có sẵn hoặc checkpoint tùy chỉnh có cùng kiến trúc.
|
| 44 |
+
"""
|
| 45 |
+
model_id = model_id.strip() if model_id else DEFAULT_MODEL
|
| 46 |
+
if model_id in PIPELINE_CACHE:
|
| 47 |
+
return PIPELINE_CACHE[model_id], None
|
| 48 |
+
|
| 49 |
+
try:
|
| 50 |
+
print(f"Loading model checkpoint: {model_id} ...")
|
| 51 |
+
device = 0 if torch.cuda.is_available() else -1
|
| 52 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 53 |
+
model = AutoModelForTokenClassification.from_pretrained(model_id)
|
| 54 |
+
pipe = pipeline(
|
| 55 |
+
"token-classification",
|
| 56 |
+
model=model,
|
| 57 |
+
tokenizer=tokenizer,
|
| 58 |
+
aggregation_strategy="simple",
|
| 59 |
+
device=device
|
| 60 |
+
)
|
| 61 |
+
PIPELINE_CACHE[model_id] = pipe
|
| 62 |
+
print(f"Model loaded successfully: {model_id}")
|
| 63 |
+
return pipe, None
|
| 64 |
+
except Exception as e:
|
| 65 |
+
err_msg = f"Không thể tải mô hình '{model_id}'. Chi tiết lỗi: {str(e)}"
|
| 66 |
+
print(err_msg)
|
| 67 |
+
return None, err_msg
|
| 68 |
+
|
| 69 |
+
# Tải trước mô hình mặc định khi khởi động ứng dụng
|
| 70 |
+
print(f"Pre-loading default model: {DEFAULT_MODEL} ...")
|
| 71 |
+
get_ner_pipeline(DEFAULT_MODEL)
|
| 72 |
|
| 73 |
# 2. Cấu hình nhãn & biểu tượng & màu sắc
|
| 74 |
LABEL_CONFIG = {
|
|
|
|
| 105 |
ORDERED_LABELS = ["HARD_SKILL", "SOFT_SKILL", "EDUCATION", "MAJOR"]
|
| 106 |
|
| 107 |
@spaces.GPU
|
| 108 |
+
def analyze_ner(title, text, threshold=0.0, model_choice="NhanSoHocCode/xlmr-ner-4labels-v2", custom_model_id=""):
|
| 109 |
+
# Xác định checkpoint thực tế được chọn
|
| 110 |
+
if model_choice == "custom":
|
| 111 |
+
active_model = (custom_model_id or "").strip()
|
| 112 |
+
if not active_model:
|
| 113 |
+
err_html = """
|
| 114 |
+
<div style="padding: 18px; text-align: center; color: #dc2626; background: #fef2f2; border: 1px solid #fecaca; border-radius: 8px;">
|
| 115 |
+
⚠️ <b>Chưa nhập thông tin mô hình:</b> Vui lòng điền Hugging Face Repo ID hoặc checkpoint tùy chỉnh để tiếp tục.
|
| 116 |
+
</div>
|
| 117 |
+
"""
|
| 118 |
+
return err_html, "Lỗi: Bạn đã chọn mô hình tùy chỉnh nhưng chưa nhập Hugging Face Repo ID.", []
|
| 119 |
+
else:
|
| 120 |
+
active_model = model_choice.strip() if model_choice else DEFAULT_MODEL
|
| 121 |
+
|
| 122 |
if not text or not text.strip():
|
| 123 |
empty_msg = """
|
| 124 |
<div style="padding: 24px; text-align: center; color: #6b7280; font-family: monospace;">
|
|
|
|
| 130 |
title = title.strip() if title and title.strip() else "Kết quả phân tích JD"
|
| 131 |
raw_text = text.strip()
|
| 132 |
|
| 133 |
+
# Lấy pipeline mô hình
|
| 134 |
+
ner_pipe, load_err = get_ner_pipeline(active_model)
|
| 135 |
+
if load_err or ner_pipe is None:
|
| 136 |
+
err_html = f"""
|
| 137 |
+
<div style="padding: 18px; color: #dc2626; background: #fef2f2; border: 1px solid #fecaca; border-radius: 8px; font-family: sans-serif;">
|
| 138 |
+
<b>❌ Lỗi tải mô hình ({html.escape(active_model)}):</b><br/>
|
| 139 |
+
<span style="font-size: 13.5px;">{html.escape(load_err or 'Không thể khởi tạo mô hình.')}</span><br/><br/>
|
| 140 |
+
<small style="color: #6b7280;">Vui lòng kiểm tra lại tên repo trên Hugging Face hoặc đảm bảo mô hình có cùng kiến trúc Token Classification.</small>
|
| 141 |
+
</div>
|
| 142 |
+
"""
|
| 143 |
+
return err_html, f"Lỗi tải mô hình '{active_model}': {load_err}", []
|
| 144 |
+
|
| 145 |
# Thực hiện trích xuất
|
| 146 |
+
try:
|
| 147 |
+
raw_results = ner_pipe(raw_text)
|
| 148 |
+
except Exception as e:
|
| 149 |
+
err_msg = f"Lỗi trong quá trình trích xuất thực thể: {str(e)}"
|
| 150 |
+
err_html = f"""
|
| 151 |
+
<div style="padding: 18px; color: #dc2626; background: #fef2f2; border: 1px solid #fecaca; border-radius: 8px;">
|
| 152 |
+
<b>❌ Lỗi thực thi mô hình:</b> {html.escape(err_msg)}
|
| 153 |
+
</div>
|
| 154 |
+
"""
|
| 155 |
+
return err_html, err_msg, []
|
| 156 |
|
| 157 |
# Lọc theo ngưỡng tin cậy
|
| 158 |
entities = [
|
|
|
|
| 268 |
<div class="jd-result-card">
|
| 269 |
<div class="border-line-double">===============================================================================================</div>
|
| 270 |
<div class="jd-title">📌 {html.escape(title)}</div>
|
| 271 |
+
<div class="model-badge-info">🤖 Mô hình: <code>{html.escape(active_model)}</code></div>
|
| 272 |
<div class="border-line-single">-----------------------------------------------------------------------------------------------</div>
|
| 273 |
|
| 274 |
<div class="section-heading">Văn bản gốc:</div>
|
|
|
|
| 293 |
# 4. Văn bản Plain Text hoàn chỉnh (sao chép nhanh)
|
| 294 |
plain_output = f"""===============================================================================================
|
| 295 |
📌 {title}
|
| 296 |
+
🤖 Mô hình: {active_model}
|
| 297 |
-----------------------------------------------------------------------------------------------
|
| 298 |
Văn bản gốc:
|
| 299 |
{raw_text}
|
|
|
|
| 307 |
|
| 308 |
return card_html, plain_output, table_rows
|
| 309 |
|
| 310 |
+
# Helper tạo link Hugging Face
|
| 311 |
+
def render_model_link(model_choice, custom_id):
|
| 312 |
+
is_custom = (model_choice == "custom")
|
| 313 |
+
target = (custom_id or "").strip() if is_custom else model_choice
|
| 314 |
+
|
| 315 |
+
if target and not target.startswith("http"):
|
| 316 |
+
hf_url = f"https://huggingface.co/{target}"
|
| 317 |
+
return (
|
| 318 |
+
f'<div class="hf-link-wrapper">'
|
| 319 |
+
f' <span class="hf-icon">🤗</span>'
|
| 320 |
+
f' <span>Checkpoint hiện tại: </span>'
|
| 321 |
+
f' <a href="{hf_url}" target="_blank" class="hf-link"><b>{html.escape(target)}</b> ↗</a>'
|
| 322 |
+
f'</div>'
|
| 323 |
+
)
|
| 324 |
+
return (
|
| 325 |
+
'<div class="hf-link-wrapper">'
|
| 326 |
+
' <span class="hf-icon">💡</span>'
|
| 327 |
+
' <span>Nhập Hugging Face Repo ID hoặc checkpoint cục bộ tương thích với 4 nhãn chuẩn.</span>'
|
| 328 |
+
'</div>'
|
| 329 |
+
)
|
| 330 |
+
|
| 331 |
+
def handle_model_change(choice, custom_id):
|
| 332 |
+
show_custom = (choice == "custom")
|
| 333 |
+
link_html = render_model_link(choice, custom_id)
|
| 334 |
+
return gr.update(visible=show_custom), link_html
|
| 335 |
+
|
| 336 |
+
def handle_custom_id_change(custom_id):
|
| 337 |
+
return render_model_link("custom", custom_id)
|
| 338 |
+
|
| 339 |
# Custom CSS cho giao diện
|
| 340 |
custom_css = """
|
| 341 |
/* Font và định dạng tổng quát */
|
| 342 |
.container {
|
| 343 |
+
max-width: 1050px !important;
|
| 344 |
margin: 0 auto !important;
|
| 345 |
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
| 346 |
}
|
| 347 |
|
| 348 |
+
/* Khung chọn mô hình thay thế dòng chữ mô tả */
|
| 349 |
+
.model-selector-panel {
|
| 350 |
+
background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
|
| 351 |
+
border: 1px solid #e2e8f0;
|
| 352 |
+
border-radius: 12px;
|
| 353 |
+
padding: 14px 18px;
|
| 354 |
+
margin: 10px 0 16px 0;
|
| 355 |
+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
.hf-link-wrapper {
|
| 359 |
+
display: flex;
|
| 360 |
+
align-items: center;
|
| 361 |
+
gap: 6px;
|
| 362 |
+
font-size: 13px;
|
| 363 |
+
color: #475569;
|
| 364 |
+
margin-top: 6px;
|
| 365 |
+
padding-left: 2px;
|
| 366 |
+
}
|
| 367 |
+
|
| 368 |
+
.hf-link {
|
| 369 |
+
color: #2563eb !important;
|
| 370 |
+
text-decoration: none !important;
|
| 371 |
+
transition: color 0.15s ease;
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
.hf-link:hover {
|
| 375 |
+
color: #1d4ed8 !important;
|
| 376 |
+
text-decoration: underline !important;
|
| 377 |
+
}
|
| 378 |
+
|
| 379 |
+
.model-badge-info {
|
| 380 |
+
font-size: 13px;
|
| 381 |
+
color: #4b5563;
|
| 382 |
+
margin: 4px 0 6px 0;
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
+
.model-badge-info code {
|
| 386 |
+
background-color: #f3f4f6;
|
| 387 |
+
color: #1f2937;
|
| 388 |
+
padding: 2px 6px;
|
| 389 |
+
border-radius: 4px;
|
| 390 |
+
font-size: 12.5px;
|
| 391 |
+
}
|
| 392 |
+
|
| 393 |
/* Thẻ kết quả mô phỏng chính xác hình mẫu */
|
| 394 |
.jd-result-card {
|
| 395 |
background-color: #ffffff;
|
|
|
|
| 405 |
|
| 406 |
/* Dark mode compatibility */
|
| 407 |
@media (prefers-color-scheme: dark) {
|
| 408 |
+
.model-selector-panel {
|
| 409 |
+
background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
|
| 410 |
+
border-color: #334155;
|
| 411 |
+
}
|
| 412 |
+
.hf-link-wrapper {
|
| 413 |
+
color: #94a3b8;
|
| 414 |
+
}
|
| 415 |
+
.hf-link {
|
| 416 |
+
color: #60a5fa !important;
|
| 417 |
+
}
|
| 418 |
+
.model-badge-info {
|
| 419 |
+
color: #94a3b8;
|
| 420 |
+
}
|
| 421 |
+
.model-badge-info code {
|
| 422 |
+
background-color: #334155;
|
| 423 |
+
color: #f1f5f9;
|
| 424 |
+
}
|
| 425 |
.jd-result-card {
|
| 426 |
background-color: #1e293b;
|
| 427 |
border-color: #334155;
|
|
|
|
| 458 |
font-size: 16px;
|
| 459 |
font-weight: 700;
|
| 460 |
color: #111827;
|
| 461 |
+
margin: 6px 0 2px 0;
|
| 462 |
}
|
| 463 |
@media (prefers-color-scheme: dark) {
|
| 464 |
.jd-title { color: #f8fafc; }
|
|
|
|
| 536 |
# Khởi tạo giao diện Gradio
|
| 537 |
with gr.Blocks(title="XLM-RoBERTa NER Job Description") as demo:
|
| 538 |
gr.HTML(f"<style>{custom_css}</style>")
|
| 539 |
+
|
| 540 |
+
# Tiêu đề chính
|
| 541 |
+
gr.Markdown("# 🏷️ Trích xuất Kỹ năng & Thực thể từ Job Description")
|
| 542 |
+
|
| 543 |
+
# VỊ TRÍ THAY THẾ DÒNG CHỮ CŨ: KHỐI CHỨC NĂNG CHỌN MÔ HÌNH
|
| 544 |
+
with gr.Group(elem_classes=["model-selector-panel"]):
|
| 545 |
+
with gr.Row():
|
| 546 |
+
model_dropdown = gr.Dropdown(
|
| 547 |
+
label="🎯 Chọn mô hình trích xuất (Model Checkpoint)",
|
| 548 |
+
choices=MODEL_OPTIONS,
|
| 549 |
+
value=DEFAULT_MODEL,
|
| 550 |
+
interactive=True,
|
| 551 |
+
scale=5,
|
| 552 |
+
info="Chuyển đổi giữa 2 checkpoint v1 / v2 đã huấn luyện hoặc tùy chỉnh checkpoint mới."
|
| 553 |
+
)
|
| 554 |
+
custom_model_textbox = gr.Textbox(
|
| 555 |
+
label="🔗 Hugging Face Repo ID hoặc Checkpoint tùy chỉnh",
|
| 556 |
+
placeholder="Ví dụ: NhanSoHocCode/xlmr-ner-4labels hoặc username/model-name",
|
| 557 |
+
value="",
|
| 558 |
+
interactive=True,
|
| 559 |
+
visible=False,
|
| 560 |
+
scale=5,
|
| 561 |
+
info="Mô hình cần có cùng kiến trúc Token Classification và 4 nhãn thực thể chuẩn."
|
| 562 |
+
)
|
| 563 |
+
|
| 564 |
+
model_link_html = gr.HTML(
|
| 565 |
+
value=render_model_link(DEFAULT_MODEL, ""),
|
| 566 |
+
elem_classes=["hf-link-container"]
|
| 567 |
+
)
|
| 568 |
+
|
| 569 |
+
# Dải hiển thị 4 nhóm nhãn thực thể chuẩn
|
| 570 |
+
gr.HTML(
|
| 571 |
"""
|
| 572 |
+
<div style="margin-top: 4px; margin-bottom: 16px;">
|
|
|
|
|
|
|
|
|
|
| 573 |
<span class="legend-pill" style="background-color: #ef4444;">🛠️ HARD_SKILL: Kỹ năng chuyên môn / Công nghệ</span>
|
| 574 |
<span class="legend-pill" style="background-color: #d97706;">🤝 SOFT_SKILL: Kỹ năng mềm / Giao tiếp</span>
|
| 575 |
<span class="legend-pill" style="background-color: #0284c7;">🎓 EDUCATION: Học vị / Bằng cấp</span>
|
|
|
|
| 620 |
[
|
| 621 |
"Mẫu JD Senior Golang / Distributed Systems",
|
| 622 |
"Tuyển dụng Senior Backend Engineer yêu cầu tốt nghiệp Cử nhân chuyên ngành Công nghệ thông tin. Có từ 4 năm kinh nghiệm làm việc với Golang, gRPC, Microservices và Event-Driven Architecture. Thành thạo cơ sở dữ liệu PostgreSQL, Redis Caching và Apache Kafka. Kinh nghiệm triển khai trên Kubernetes, Docker, CI/CD. Sử dụng thành thạo Cursor, GitHub Copilot để tăng tốc lập trình. Yêu cầu kỹ năng làm việc nhóm, tư duy giải quyết vấn đề và tiếng Anh giao tiếp tốt.",
|
| 623 |
+
0.5,
|
| 624 |
+
"NhanSoHocCode/xlmr-ner-4labels-v2",
|
| 625 |
+
""
|
| 626 |
],
|
| 627 |
[
|
| 628 |
"Mẫu JD AI / Data Science Engineer",
|
| 629 |
"Tìm kiếm Kỹ sư AI tốt nghiệp Thạc sĩ hoặc Cử nhân ngành Khoa học Máy tính. Có kinh nghiệm với Python, PyTorch, Transformers và mô hình ngôn ngữ lớn (LLM). Thành thạo kỹ thuật RAG, Fine-tuning, triển khai mô hình với FastAPI, Docker trên GCP. Yêu cầu tư duy phản biện, kỹ năng nghiên cứu độc lập và khả năng tiếng Anh chuyên ngành xuất sắc.",
|
| 630 |
+
0.5,
|
| 631 |
+
"NhanSoHocCode/xlmr-ner-4labels-v2",
|
| 632 |
+
""
|
| 633 |
],
|
| 634 |
[
|
| 635 |
"Mẫu JD Frontend Lead Developer",
|
| 636 |
"Yêu cầu bằng Kỹ sư hoặc Đại học chuyên ngành Công nghệ phần mềm. Tối thiểu 5 năm kinh nghiệm với JavaScript, TypeScript, ReactJS, Next.js và TailwindCSS. Có kinh nghiệm tối ưu hiệu năng web, quản trị state với Redux Toolkit hoặc Zustand. Cần có kỹ năng lãnh đạo đội ngũ, khả năng giao tiếp và truyền đạt thông tin mạch lạc.",
|
| 637 |
+
0.5,
|
| 638 |
+
"NhanSoHocCode/xlmr-ner-4labels",
|
| 639 |
+
""
|
| 640 |
]
|
| 641 |
],
|
| 642 |
+
inputs=[title_input, text_input, threshold_slider, model_dropdown, custom_model_textbox],
|
| 643 |
label="💡 Nhấp vào các mẫu JD để thử nghiệm nhanh:"
|
| 644 |
)
|
| 645 |
|
|
|
|
| 661 |
label="Danh sách thực thể chi tiết"
|
| 662 |
)
|
| 663 |
|
| 664 |
+
# Sự kiện tương tác bộ chọn mô hình
|
| 665 |
+
model_dropdown.change(
|
| 666 |
+
fn=handle_model_change,
|
| 667 |
+
inputs=[model_dropdown, custom_model_textbox],
|
| 668 |
+
outputs=[custom_model_textbox, model_link_html]
|
| 669 |
+
)
|
| 670 |
+
|
| 671 |
+
custom_model_textbox.input(
|
| 672 |
+
fn=handle_custom_id_change,
|
| 673 |
+
inputs=[custom_model_textbox],
|
| 674 |
+
outputs=[model_link_html]
|
| 675 |
+
)
|
| 676 |
+
|
| 677 |
# Xử lý sự kiện click nút
|
| 678 |
+
common_inputs = [title_input, text_input, threshold_slider, model_dropdown, custom_model_textbox]
|
| 679 |
+
common_outputs = [card_output, raw_output, table_output]
|
| 680 |
+
|
| 681 |
submit_btn.click(
|
| 682 |
fn=analyze_ner,
|
| 683 |
+
inputs=common_inputs,
|
| 684 |
+
outputs=common_outputs
|
| 685 |
)
|
| 686 |
|
| 687 |
# Chạy lần đầu khi load trang
|
| 688 |
demo.load(
|
| 689 |
fn=analyze_ner,
|
| 690 |
+
inputs=common_inputs,
|
| 691 |
+
outputs=common_outputs
|
| 692 |
)
|
| 693 |
|
| 694 |
if __name__ == "__main__":
|