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

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +46 -0
  2. prompt_injection_multilingual.pkl +3 -0
  3. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()
prompt_injection_multilingual.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:561a432cfdb7469c8f7a0075e0eceecccca3719d8dec08c84f90f42a0448a19d
3
+ size 513316
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ gradio
2
+ joblib
3
+ scikit-learn
4
+ numpy
5
+ pandas