c-ho commited on
Commit
d1a4bde
·
verified ·
1 Parent(s): 7599b35

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -1
app.py CHANGED
@@ -54,6 +54,30 @@ def get_model(model_name):
54
  # -----------------------
55
  # NER function (SAFE OUTPUT)
56
  # -----------------------
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  def analyze_text(text, model_name):
58
  ner = get_model(model_name)
59
  results = ner(text)
@@ -67,7 +91,7 @@ def analyze_text(text, model_name):
67
  score = ent.get("score", 0.0)
68
  lines.append(f"{word} -> {label} ({score:.2f})")
69
  return "\n".join(lines)
70
-
71
  # -----------------------
72
  # UI
73
  # -----------------------
 
54
  # -----------------------
55
  # NER function (SAFE OUTPUT)
56
  # -----------------------
57
+
58
+ # Function to run NER on input text
59
+ def analyze_text(text, model_name):
60
+ ner = models[model_name]
61
+ ner_results = ner(text)
62
+ highlighted_text = []
63
+ last_idx = 0
64
+ for entity in ner_results:
65
+ start = entity["start"]
66
+ end = entity["end"]
67
+ label = entity["entity_group"]
68
+ # Add non-entity text
69
+ if start > last_idx:
70
+ highlighted_text.append((text[last_idx:start], None))
71
+ # Add entity text
72
+ highlighted_text.append((text[start:end], label))
73
+ last_idx = end
74
+ # Add any remaining text after the last entity
75
+ if last_idx < len(text):
76
+ highlighted_text.append((text[last_idx:], None))
77
+ return highlighted_text
78
+
79
+
80
+ '''
81
  def analyze_text(text, model_name):
82
  ner = get_model(model_name)
83
  results = ner(text)
 
91
  score = ent.get("score", 0.0)
92
  lines.append(f"{word} -> {label} ({score:.2f})")
93
  return "\n".join(lines)
94
+ '''
95
  # -----------------------
96
  # UI
97
  # -----------------------