zekun-li commited on
Commit
58dd7a5
·
verified ·
1 Parent(s): 45ce31e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -2
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
- # Extract token spans labeled as toponyms
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((start, end, "Toponym"))
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,