Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
6ee4c37
1
Parent(s):
0d4b622
update app
Browse files
app.py
CHANGED
@@ -11,7 +11,7 @@ from transformers import pipeline
|
|
11 |
|
12 |
@spaces.GPU # <-- required for ZeroGPU
|
13 |
def classify_tokens(text):
|
14 |
-
|
15 |
color_dict = {'None': '#6adf97',
|
16 |
'O': '#f18621',
|
17 |
'B-p.Purpose-p.Purpose': '#554065',
|
@@ -22,6 +22,7 @@ def classify_tokens(text):
|
|
22 |
'B-p.Originator-p.Source': '#a08323',
|
23 |
'B-p.Recipient-p.Goal': '#725be0',
|
24 |
'B-p.Possessor-p.Possessor': '#b5ce9e',
|
|
|
25 |
'B-p.Gestalt-p.Gestalt': '#34a8a9',
|
26 |
'B-p.Ancillary-p.Ancillary': '#73f29f',
|
27 |
'I-p.Ancillary-p.Ancillary': '#73f29f',
|
@@ -30,10 +31,12 @@ def classify_tokens(text):
|
|
30 |
'I-p.Source-p.Source': '#5cc334',
|
31 |
'B-p.Theme-p.Theme': '#5b88c8',
|
32 |
'B-p.Locus-p.Locus': '#4c39c8',
|
|
|
33 |
'B-p.Characteristic-p.Characteristic': '#661943',
|
34 |
'B-p.Explanation-p.Explanation': '#852e58',
|
35 |
'B-p.OrgMember-p.Possessor': '#e3bd42',
|
36 |
'B-p.Goal-p.Goal': '#6bfc3c',
|
|
|
37 |
'B-p.Manner-p.Manner': '#436097',
|
38 |
'B-p.ComparisonRef-p.ComparisonRef': '#4df5a9',
|
39 |
'B-p.Cost-p.Locus': '#fe5990',
|
@@ -240,28 +243,23 @@ def classify_tokens(text):
|
|
240 |
|
241 |
results = token_classifier(text)
|
242 |
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
start = prep["start"]
|
249 |
-
end = prep["end"]
|
250 |
-
label = prep["entity_group"]
|
251 |
word = html.escape(text[start:end])
|
252 |
-
|
253 |
-
# Add untagged text before the entity
|
254 |
output += html.escape(text[last_idx:start])
|
255 |
|
256 |
-
|
257 |
-
|
258 |
-
output +=
|
259 |
-
|
|
|
|
|
260 |
last_idx = end
|
261 |
|
262 |
-
# Add remaining text
|
263 |
output += html.escape(text[last_idx:])
|
264 |
-
|
265 |
return f"<div style='font-family: sans-serif; line-height: 1.6;'>{output}</div>"
|
266 |
|
267 |
|
|
|
11 |
|
12 |
@spaces.GPU # <-- required for ZeroGPU
|
13 |
def classify_tokens(text):
|
14 |
+
|
15 |
color_dict = {'None': '#6adf97',
|
16 |
'O': '#f18621',
|
17 |
'B-p.Purpose-p.Purpose': '#554065',
|
|
|
22 |
'B-p.Originator-p.Source': '#a08323',
|
23 |
'B-p.Recipient-p.Goal': '#725be0',
|
24 |
'B-p.Possessor-p.Possessor': '#b5ce9e',
|
25 |
+
'p.Possessor-p.Possessor': '#b5ce9e',
|
26 |
'B-p.Gestalt-p.Gestalt': '#34a8a9',
|
27 |
'B-p.Ancillary-p.Ancillary': '#73f29f',
|
28 |
'I-p.Ancillary-p.Ancillary': '#73f29f',
|
|
|
31 |
'I-p.Source-p.Source': '#5cc334',
|
32 |
'B-p.Theme-p.Theme': '#5b88c8',
|
33 |
'B-p.Locus-p.Locus': '#4c39c8',
|
34 |
+
'p.Locus-p.Locus': '#4c39c8',
|
35 |
'B-p.Characteristic-p.Characteristic': '#661943',
|
36 |
'B-p.Explanation-p.Explanation': '#852e58',
|
37 |
'B-p.OrgMember-p.Possessor': '#e3bd42',
|
38 |
'B-p.Goal-p.Goal': '#6bfc3c',
|
39 |
+
'p.Goal-p.Goal': '#6bfc3c',
|
40 |
'B-p.Manner-p.Manner': '#436097',
|
41 |
'B-p.ComparisonRef-p.ComparisonRef': '#4df5a9',
|
42 |
'B-p.Cost-p.Locus': '#fe5990',
|
|
|
243 |
|
244 |
results = token_classifier(text)
|
245 |
|
246 |
+
for entity in sorted_results:
|
247 |
+
start = entity["start"]
|
248 |
+
end = entity["end"]
|
249 |
+
label = entity["entity_group"]
|
250 |
+
score = entity["score"]
|
|
|
|
|
|
|
251 |
word = html.escape(text[start:end])
|
|
|
|
|
252 |
output += html.escape(text[last_idx:start])
|
253 |
|
254 |
+
color = color_dict.get(label, "#D3D3D3")
|
255 |
+
tooltip = f"{label} ({score:.2f})"
|
256 |
+
output += (
|
257 |
+
f"<span style='background-color: {color}; padding: 2px; border-radius: 4px;' "
|
258 |
+
f"title='{tooltip}'>{word}</span>"
|
259 |
+
)
|
260 |
last_idx = end
|
261 |
|
|
|
262 |
output += html.escape(text[last_idx:])
|
|
|
263 |
return f"<div style='font-family: sans-serif; line-height: 1.6;'>{output}</div>"
|
264 |
|
265 |
|