Spaces:
Running
Running
Delete gliner_file.py
Browse files- gliner_file.py +0 -20
gliner_file.py
DELETED
@@ -1,20 +0,0 @@
|
|
1 |
-
from gliner import GLiNER
|
2 |
-
|
3 |
-
def run_ner(model, text, labels_list, threshold=0.4):
|
4 |
-
|
5 |
-
entities = model.predict_entities(text, labels_list, threshold=threshold)
|
6 |
-
|
7 |
-
# Loading the GLiNER model
|
8 |
-
model = GLiNER.from_pretrained("urchade/gliner_multi-v2.1")
|
9 |
-
model.eval() # Put the model in evaluation mode
|
10 |
-
|
11 |
-
# Initializing the dictionary to store the results
|
12 |
-
ner_results = {label: [] for label in labels_list}
|
13 |
-
|
14 |
-
# Iterating over the recognized entities and storing them in the dictionary
|
15 |
-
for entity in entities:
|
16 |
-
if entity['label'] in ner_results:
|
17 |
-
# Adds the entity's text to the corresponding list for the label
|
18 |
-
ner_results[entity['label']].append(entity['text'])
|
19 |
-
|
20 |
-
return ner_results
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|