Bobotriere commited on
Commit
bc13cb3
·
verified ·
1 Parent(s): 460c13f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -16
app.py CHANGED
@@ -1,31 +1,31 @@
1
  import gradio as gr
2
  from gliner import GLiNER
3
 
4
- # Load the PII model
5
  model = GLiNER.from_pretrained("DeepMount00/GLiNER_PII_ITA")
6
 
7
- # Define labels for entity extraction
8
  labels = ["PERSON", "LOCATION", "ORGANIZATION", "EMAIL", "PHONE", "DATE", "ADDRESS", "TAX_ID"]
9
 
10
- # Define the prediction function
11
  def predict(text):
12
  if not text or not isinstance(text, str) or len(text.strip()) < 5:
13
  return []
14
  try:
15
- results = model.predict_entities(text, labels)
16
- return results
17
  except Exception as e:
18
  return [{"error": str(e)}]
19
 
20
- # Build Gradio Interface (no enable_queue here!)
21
- demo = gr.Interface(
22
- fn=predict,
23
- inputs=gr.Textbox(label="Testo da analizzare", placeholder="Inserisci qui il testo..."),
24
- outputs=gr.Json(label="output"),
25
- title="GLiNER PII Extractor 🇮🇹",
26
- description="Named Entity Recognition for PII in Italian legal texts using GLiNER.",
27
- allow_flagging="never"
28
- )
29
 
30
- # Launch Space with queuing enabled
31
- demo.launch(queue=True)
 
 
 
 
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()