Spaces:
Runtime error
Runtime error
paul hilders
commited on
Commit
•
2910b3b
1
Parent(s):
e71dad4
Add NER test
Browse files
app.py
CHANGED
@@ -27,7 +27,7 @@ clip.clip._MODELS = {
|
|
27 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
28 |
model, preprocess = clip.load("ViT-B/32", device=device, jit=False)
|
29 |
|
30 |
-
|
31 |
|
32 |
# Gradio Section:
|
33 |
def run_demo(image, text):
|
@@ -48,13 +48,13 @@ def run_demo(image, text):
|
|
48 |
|
49 |
# Apply NER to extract named entities, and run the explainability method
|
50 |
# for each named entity.
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
|
57 |
-
|
58 |
|
59 |
return overlapped, highlighted_text
|
60 |
|
|
|
27 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
28 |
model, preprocess = clip.load("ViT-B/32", device=device, jit=False)
|
29 |
|
30 |
+
nlp = spacy.load("en_core_web_sm")
|
31 |
|
32 |
# Gradio Section:
|
33 |
def run_demo(image, text):
|
|
|
48 |
|
49 |
# Apply NER to extract named entities, and run the explainability method
|
50 |
# for each named entity.
|
51 |
+
highlighed_entities = []
|
52 |
+
for ent in nlp(text).ents:
|
53 |
+
ent_text = ent.text
|
54 |
+
ent_label = ent.label_
|
55 |
+
highlighed_entities.append((ent_text, ent_label))
|
56 |
|
57 |
+
print(highlighed_entities)
|
58 |
|
59 |
return overlapped, highlighted_text
|
60 |
|