Update app.py
Browse files
app.py
CHANGED
@@ -9,7 +9,7 @@ model = AutoModelForTokenClassification.from_pretrained(model_name)
|
|
9 |
model.to("cpu") # Use "cuda" if you have GPU
|
10 |
model.eval()
|
11 |
|
12 |
-
|
13 |
def get_toponym_entities(text):
|
14 |
inputs = tokenizer(
|
15 |
text,
|
@@ -30,10 +30,11 @@ def get_toponym_entities(text):
|
|
30 |
if label_id != 0 and idx < len(offset_mapping):
|
31 |
start, end = offset_mapping[idx].tolist()
|
32 |
if end > start:
|
33 |
-
entities.append(
|
34 |
|
35 |
return {"text": text, "entities": entities}
|
36 |
|
|
|
37 |
# Launch Gradio app
|
38 |
demo = gr.Interface(
|
39 |
fn=get_toponym_entities,
|
|
|
9 |
model.to("cpu") # Use "cuda" if you have GPU
|
10 |
model.eval()
|
11 |
|
12 |
+
|
13 |
def get_toponym_entities(text):
|
14 |
inputs = tokenizer(
|
15 |
text,
|
|
|
30 |
if label_id != 0 and idx < len(offset_mapping):
|
31 |
start, end = offset_mapping[idx].tolist()
|
32 |
if end > start:
|
33 |
+
entities.append({"start": start, "end": end, "entity": "Toponym"})
|
34 |
|
35 |
return {"text": text, "entities": entities}
|
36 |
|
37 |
+
|
38 |
# Launch Gradio app
|
39 |
demo = gr.Interface(
|
40 |
fn=get_toponym_entities,
|