Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -68,9 +68,9 @@ def predict_ner(model, tokenizer, text, label_map, device):
|
|
| 68 |
if token.startswith('▁'):
|
| 69 |
# Add space if not the first token
|
| 70 |
if current_word:
|
| 71 |
-
html_output += f'<span style="background-color: {BACKGROUND_COLOR_MAP[current_label]}; padding: 2px 5px;">{current_word}</span> '
|
| 72 |
# Start a new word
|
| 73 |
-
current_word = token[1:]
|
| 74 |
current_label = label
|
| 75 |
else:
|
| 76 |
# Append to the current word
|
|
@@ -78,13 +78,12 @@ def predict_ner(model, tokenizer, text, label_map, device):
|
|
| 78 |
|
| 79 |
# Append the last word
|
| 80 |
if current_word:
|
| 81 |
-
html_output += f'<span style="background-color: {BACKGROUND_COLOR_MAP[current_label]}; padding: 2px 5px;">{current_word}</span>'
|
| 82 |
|
| 83 |
html_output += "</div>"
|
| 84 |
|
| 85 |
return html_output
|
| 86 |
|
| 87 |
-
|
| 88 |
# Load the model and tokenizer
|
| 89 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 90 |
model, tokenizer, label_map = load_model("./pretrained_models/xlmr.base", "./model.pt", device)
|
|
|
|
| 68 |
if token.startswith('▁'):
|
| 69 |
# Add space if not the first token
|
| 70 |
if current_word:
|
| 71 |
+
html_output += f'<span style="background-color: {BACKGROUND_COLOR_MAP[current_label]}; padding: 2px 5px; margin: 0;">{current_word}</span> '
|
| 72 |
# Start a new word
|
| 73 |
+
current_word = token[1:]
|
| 74 |
current_label = label
|
| 75 |
else:
|
| 76 |
# Append to the current word
|
|
|
|
| 78 |
|
| 79 |
# Append the last word
|
| 80 |
if current_word:
|
| 81 |
+
html_output += f'<span style="background-color: {BACKGROUND_COLOR_MAP[current_label]}; padding: 2px 5px; margin: 0;">{current_word}</span>'
|
| 82 |
|
| 83 |
html_output += "</div>"
|
| 84 |
|
| 85 |
return html_output
|
| 86 |
|
|
|
|
| 87 |
# Load the model and tokenizer
|
| 88 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 89 |
model, tokenizer, label_map = load_model("./pretrained_models/xlmr.base", "./model.pt", device)
|