Benedikt Veith commited on
Commit
1ccafce
·
1 Parent(s): d43bc72
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -12,7 +12,7 @@ pipe_ner = pipeline("ner", model=MODEL_2_ID, token=TOKEN, aggregation_strategy="
12
 
13
  def analyze(text):
14
  if not text or len(text.strip()) < 1:
15
- return gr.update(visible=False), "", ""
16
 
17
  res_cls = pipe_cls(text)[0]
18
  is_attack = res_cls['label'] == "LABEL_1"
@@ -21,9 +21,8 @@ def analyze(text):
21
 
22
  if is_attack:
23
  return (
24
- gr.update(visible=True),
25
- "Prompt Injection detected",
26
- [(text, "ATTACK")] # Text komplett rot markieren
27
  )
28
 
29
  has_high_ner = False
@@ -42,9 +41,9 @@ def analyze(text):
42
  highlighted_data.append((text[last_idx:], None))
43
 
44
  if has_high_ner:
45
- return gr.update(visible=True), "Entities detected", highlighted_data
46
  else:
47
- return gr.update(visible=True), "Nothing detected", [(text, "CLEAN")]
48
 
49
  ACCENT_COLOR = "#F5C77A"
50
 
@@ -71,13 +70,14 @@ with gr.Blocks(css=css, theme=theme) as demo:
71
  show_legend=False,
72
  color_map={"ATTACK": "red", "CLEAN": "green"}
73
  )
74
- status_msg = gr.Markdown()
75
 
76
  input_text.change(
77
  fn=analyze,
78
  inputs=input_text,
79
- outputs=[results_col, status_msg, display_output],
80
- show_progress="minimal"
 
 
81
  )
82
 
83
  demo.launch()
 
12
 
13
  def analyze(text):
14
  if not text or len(text.strip()) < 1:
15
+ return gr.update(visible=False), ""
16
 
17
  res_cls = pipe_cls(text)[0]
18
  is_attack = res_cls['label'] == "LABEL_1"
 
21
 
22
  if is_attack:
23
  return (
24
+ gr.update(visible=True),
25
+ [(text, "ATTACK")]
 
26
  )
27
 
28
  has_high_ner = False
 
41
  highlighted_data.append((text[last_idx:], None))
42
 
43
  if has_high_ner:
44
+ return gr.update(visible=True), highlighted_data
45
  else:
46
+ return gr.update(visible=True), [(text, "CLEAN")]
47
 
48
  ACCENT_COLOR = "#F5C77A"
49
 
 
70
  show_legend=False,
71
  color_map={"ATTACK": "red", "CLEAN": "green"}
72
  )
 
73
 
74
  input_text.change(
75
  fn=analyze,
76
  inputs=input_text,
77
+ outputs=[results_col, display_output],
78
+ show_progress="minimal",
79
+ concurrency_limit=1,
80
+ trigger_mode="always_last"
81
  )
82
 
83
  demo.launch()