gliner / app.py
Bobotriere's picture
Update app.py
bc13cb3 verified
raw
history blame contribute delete
962 Bytes
import gradio as gr
from gliner import GLiNER
# Load model
model = GLiNER.from_pretrained("DeepMount00/GLiNER_PII_ITA")
# Labels to extract
labels = ["PERSON", "LOCATION", "ORGANIZATION", "EMAIL", "PHONE", "DATE", "ADDRESS", "TAX_ID"]
# Inference function
def predict(text):
if not text or not isinstance(text, str) or len(text.strip()) < 5:
return []
try:
return model.predict_entities(text, labels)
except Exception as e:
return [{"error": str(e)}]
# Use Blocks style (recommended for latest gradio)
with gr.Blocks() as demo:
gr.Markdown("# GLiNER PII Extractor ๐Ÿ‡ฎ๐Ÿ‡น")
gr.Markdown("Named Entity Recognition for PII in Italian legal texts using GLiNER.")
inp = gr.Textbox(label="Testo da analizzare", placeholder="Inserisci qui il testo...")
out = gr.Json(label="Output")
btn = gr.Button("Analizza")
btn.click(fn=predict, inputs=inp, outputs=out)
# Launch properly
demo.queue().launch()