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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -46
app.py CHANGED
@@ -1,46 +1,55 @@
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
- prob = model.predict_proba(
12
- [prompt]
13
- )[0][1]
14
-
15
- if prob >= 0.5:
16
-
17
- result = "🚨 Prompt Injection Detected"
18
-
19
- else:
20
-
21
- result = "✅ Safe Prompt"
22
-
23
- return result, f"{prob:.2%}"
24
- ```
25
-
26
- demo = gr.Interface(
27
-
28
- fn=detect,
29
-
30
- inputs="textbox",
31
-
32
- outputs=[
33
-
34
- "text",
35
-
36
- "text"
37
-
38
- ],
39
-
40
- title="🛡️ Prompt Injection Detector",
41
-
42
- description="English + Urdu + Roman Urdu"
43
-
44
- )
45
-
46
- demo.launch()
 
 
 
 
 
 
 
 
 
 
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()