Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,31 +1,31 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from gliner import GLiNER
|
| 3 |
|
| 4 |
-
# Load
|
| 5 |
model = GLiNER.from_pretrained("DeepMount00/GLiNER_PII_ITA")
|
| 6 |
|
| 7 |
-
#
|
| 8 |
labels = ["PERSON", "LOCATION", "ORGANIZATION", "EMAIL", "PHONE", "DATE", "ADDRESS", "TAX_ID"]
|
| 9 |
|
| 10 |
-
#
|
| 11 |
def predict(text):
|
| 12 |
if not text or not isinstance(text, str) or len(text.strip()) < 5:
|
| 13 |
return []
|
| 14 |
try:
|
| 15 |
-
|
| 16 |
-
return results
|
| 17 |
except Exception as e:
|
| 18 |
return [{"error": str(e)}]
|
| 19 |
|
| 20 |
-
#
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
allow_flagging="never"
|
| 28 |
-
)
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from gliner import GLiNER
|
| 3 |
|
| 4 |
+
# Load model
|
| 5 |
model = GLiNER.from_pretrained("DeepMount00/GLiNER_PII_ITA")
|
| 6 |
|
| 7 |
+
# Labels to extract
|
| 8 |
labels = ["PERSON", "LOCATION", "ORGANIZATION", "EMAIL", "PHONE", "DATE", "ADDRESS", "TAX_ID"]
|
| 9 |
|
| 10 |
+
# Inference function
|
| 11 |
def predict(text):
|
| 12 |
if not text or not isinstance(text, str) or len(text.strip()) < 5:
|
| 13 |
return []
|
| 14 |
try:
|
| 15 |
+
return model.predict_entities(text, labels)
|
|
|
|
| 16 |
except Exception as e:
|
| 17 |
return [{"error": str(e)}]
|
| 18 |
|
| 19 |
+
# Use Blocks style (recommended for latest gradio)
|
| 20 |
+
with gr.Blocks() as demo:
|
| 21 |
+
gr.Markdown("# GLiNER PII Extractor 🇮🇹")
|
| 22 |
+
gr.Markdown("Named Entity Recognition for PII in Italian legal texts using GLiNER.")
|
| 23 |
+
|
| 24 |
+
inp = gr.Textbox(label="Testo da analizzare", placeholder="Inserisci qui il testo...")
|
| 25 |
+
out = gr.Json(label="Output")
|
|
|
|
|
|
|
| 26 |
|
| 27 |
+
btn = gr.Button("Analizza")
|
| 28 |
+
btn.click(fn=predict, inputs=inp, outputs=out)
|
| 29 |
+
|
| 30 |
+
# Launch properly
|
| 31 |
+
demo.queue().launch()
|