umrr commited on
Commit
4089165
·
verified ·
1 Parent(s): 4eb3a08

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -42
app.py CHANGED
@@ -1,55 +1,32 @@
1
  import gradio as gr
2
  import joblib
3
 
4
- model = joblib.load(
5
- "prompt_injection_multilingual.pkl"
6
- )
7
-
8
- def detect(prompt):
9
-
10
- ```
11
- probability = model.predict_proba(
12
- [prompt]
13
- )[0][1]
14
 
15
- if probability >= 0.5:
16
 
17
- verdict = "🚨 Prompt Injection Detected"
 
18
 
19
- else:
 
 
 
20
 
21
- verdict = "✅ Safe Prompt"
22
 
23
- return verdict, f"{probability:.2%}"
24
- ```
25
 
26
  demo = gr.Interface(
27
-
28
- ```
29
- fn=detect,
30
-
31
- inputs=gr.Textbox(
32
- lines=5,
33
- label="Enter Prompt"
34
- ),
35
-
36
- outputs=[
37
-
38
- gr.Textbox(
39
- label="Result"
40
  ),
41
-
42
- gr.Textbox(
43
- label="Injection Probability"
44
- )
45
-
46
- ],
47
-
48
- title="🛡️ Prompt Injection Detector",
49
-
50
- description="English + Urdu + Roman Urdu"
51
- ```
52
-
53
  )
54
 
55
- demo.launch()
 
1
  import gradio as gr
2
  import joblib
3
 
4
+ model = joblib.load("prompt_injection_multilingual.pkl")
 
 
 
 
 
 
 
 
 
5
 
 
6
 
7
+ def detect(prompt):
8
+ probability = model.predict_proba([prompt])[0][1]
9
 
10
+ if probability >= 0.5:
11
+ verdict = "🚨 Prompt Injection Detected"
12
+ else:
13
+ verdict = "✅ Safe Prompt"
14
 
15
+ return verdict, f"{probability:.2%}"
16
 
 
 
17
 
18
  demo = gr.Interface(
19
+ fn=detect,
20
+ inputs=gr.Textbox(
21
+ lines=5,
22
+ label="Enter Prompt"
 
 
 
 
 
 
 
 
 
23
  ),
24
+ outputs=[
25
+ gr.Textbox(label="Result"),
26
+ gr.Textbox(label="Injection Probability")
27
+ ],
28
+ title="🛡️ Prompt Injection Detector",
29
+ description="English + Urdu + Roman Urdu"
 
 
 
 
 
 
30
  )
31
 
32
+ demo.launch()