Spaces:
Running
Running
Benedikt Veith commited on
Commit ·
7f6e108
1
Parent(s): 6b2b5a6
Fix?
Browse files
app.py
CHANGED
|
@@ -29,18 +29,29 @@ def analyze(text):
|
|
| 29 |
|
| 30 |
has_high_ner = False
|
| 31 |
|
| 32 |
-
|
| 33 |
-
highlighted_data = []
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
has_high_ner = True
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
last_idx = ent['end']
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
-
|
|
|
|
| 44 |
|
| 45 |
if has_high_ner:
|
| 46 |
return gr.update(visible=True), highlighted_data
|
|
|
|
| 29 |
|
| 30 |
has_high_ner = False
|
| 31 |
|
| 32 |
+
res_ner = sorted(res_ner, key=lambda x: x['start'])
|
|
|
|
| 33 |
|
| 34 |
+
highlighted_data = []
|
| 35 |
+
last_idx = 0
|
|
|
|
| 36 |
|
| 37 |
+
for ent in res_ner:
|
| 38 |
+
if ent['start'] < last_idx:
|
| 39 |
+
continue
|
| 40 |
+
|
| 41 |
+
if ent['score'] > 0.90:
|
| 42 |
+
if ent['start'] > last_idx:
|
| 43 |
+
highlighted_data.append((text[last_idx:ent['start']], None))
|
| 44 |
+
|
| 45 |
+
label_text = f"{ent['entity_group']} ({ent['score']:.0%})"
|
| 46 |
+
highlighted_data.append((text[ent['start']:ent['end']], label_text))
|
| 47 |
+
|
| 48 |
last_idx = ent['end']
|
| 49 |
+
has_high_ner = True
|
| 50 |
+
else:
|
| 51 |
+
continue
|
| 52 |
|
| 53 |
+
if last_idx < len(text):
|
| 54 |
+
highlighted_data.append((text[last_idx:], None))
|
| 55 |
|
| 56 |
if has_high_ner:
|
| 57 |
return gr.update(visible=True), highlighted_data
|