Spaces:
Sleeping
Sleeping
Asanaly
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
# app.py
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import torch
|
| 4 |
import numpy as np
|
|
@@ -11,6 +12,7 @@ model_checkpoint = "bert-base-multilingual-cased"
|
|
| 11 |
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
|
| 12 |
model = AutoModelForTokenClassification.from_pretrained(model_checkpoint, num_labels=7)
|
| 13 |
|
|
|
|
| 14 |
label_list = ["O", "B-PER", "I-PER", "B-ORG", "I-ORG", "B-LOC", "I-LOC"]
|
| 15 |
|
| 16 |
# ============================
|
|
@@ -50,6 +52,7 @@ def highlight_ner(text):
|
|
| 50 |
color = "blue"
|
| 51 |
elif label.startswith("LOC"):
|
| 52 |
color = "green"
|
|
|
|
| 53 |
colored_text = colored_text.replace(word, f"<span style='color:{color}; font-weight:bold'>{word}</span>")
|
| 54 |
return colored_text
|
| 55 |
|
|
|
|
| 1 |
# app.py
|
| 2 |
+
|
| 3 |
import gradio as gr
|
| 4 |
import torch
|
| 5 |
import numpy as np
|
|
|
|
| 12 |
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
|
| 13 |
model = AutoModelForTokenClassification.from_pretrained(model_checkpoint, num_labels=7)
|
| 14 |
|
| 15 |
+
# Қазақ NER үшін label тізімі
|
| 16 |
label_list = ["O", "B-PER", "I-PER", "B-ORG", "I-ORG", "B-LOC", "I-LOC"]
|
| 17 |
|
| 18 |
# ============================
|
|
|
|
| 52 |
color = "blue"
|
| 53 |
elif label.startswith("LOC"):
|
| 54 |
color = "green"
|
| 55 |
+
# Мәтіндегі сөзді HTML span тегпен орау
|
| 56 |
colored_text = colored_text.replace(word, f"<span style='color:{color}; font-weight:bold'>{word}</span>")
|
| 57 |
return colored_text
|
| 58 |
|