Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,23 +1,7 @@
|
|
1 |
from typing import Dict, Union
|
2 |
import sys
|
3 |
-
|
4 |
-
from GLiNER.model import GLiNER
|
5 |
import gradio as gr
|
6 |
-
import os
|
7 |
-
from transformers import AutoModel, AutoTokenizer, logging
|
8 |
-
from huggingface_hub import HfFolder
|
9 |
-
|
10 |
-
# Set the Hugging Face logging to error only to avoid sensitive info in logs
|
11 |
-
logging.set_verbosity_error()
|
12 |
-
|
13 |
-
# Retrieve the HF API key from the environment
|
14 |
-
hf_api_key = os.getenv('HF_KEY')
|
15 |
-
|
16 |
-
# If the key is found, use it to authenticate
|
17 |
-
if hf_api_key:
|
18 |
-
HfFolder.save_token(hf_api_key) # This authenticates you for this session
|
19 |
-
else:
|
20 |
-
print("No HF_KEY found. Please make sure you've set up your Hugging Face API key as an environment variable.")
|
21 |
|
22 |
|
23 |
model = GLiNER.from_pretrained("DeepMount00/universal_ner_ita").eval()
|
@@ -76,7 +60,9 @@ examples = [
|
|
76 |
],
|
77 |
]
|
78 |
|
79 |
-
def ner(
|
|
|
|
|
80 |
labels = labels.split(",")
|
81 |
return {
|
82 |
"text": text,
|
@@ -88,7 +74,9 @@ def ner(text, labels: str, nested_ner: bool) -> Dict[str, Union[str, int, float]
|
|
88 |
"end": entity["end"],
|
89 |
"score": 0,
|
90 |
}
|
91 |
-
for entity in model.predict_entities(
|
|
|
|
|
92 |
],
|
93 |
}
|
94 |
|
|
|
1 |
from typing import Dict, Union
|
2 |
import sys
|
3 |
+
from gliner import GLiNER
|
|
|
4 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
|
7 |
model = GLiNER.from_pretrained("DeepMount00/universal_ner_ita").eval()
|
|
|
60 |
],
|
61 |
]
|
62 |
|
63 |
+
def ner(
|
64 |
+
text, labels: str, threshold: float, nested_ner: bool
|
65 |
+
) -> Dict[str, Union[str, int, float]]:
|
66 |
labels = labels.split(",")
|
67 |
return {
|
68 |
"text": text,
|
|
|
74 |
"end": entity["end"],
|
75 |
"score": 0,
|
76 |
}
|
77 |
+
for entity in model.predict_entities(
|
78 |
+
text, labels, flat_ner=not nested_ner, threshold=threshold
|
79 |
+
)
|
80 |
],
|
81 |
}
|
82 |
|