File size: 962 Bytes
dcecbc7
460c13f
dcecbc7
bc13cb3
3dae07f
7e22700
bc13cb3
460c13f
 
bc13cb3
3dae07f
460c13f
 
 
bc13cb3
460c13f
 
5ca5ab3
bc13cb3
 
 
 
 
 
 
5ca5ab3
bc13cb3
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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()