retereum commited on
Commit
f934c22
·
0 Parent(s):

Initial commit

Browse files
.gitignore ADDED
@@ -0,0 +1,268 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Warning!!! Generated by Copilot, haven't checked it fully yet.
2
+
3
+ # Visual Studio Code
4
+ .vscode/
5
+ .settings/
6
+
7
+ # Gradio
8
+ flagged/
9
+
10
+ # Python
11
+ __pycache__/
12
+ *.pyc
13
+ *.pyo
14
+ *.pyd
15
+ *.pyz
16
+ *.pyw
17
+ *.pyi
18
+ *.egg-info/
19
+ dist/
20
+ build/
21
+ *.egg
22
+ *.whl
23
+ *.swp
24
+ *.swo
25
+ *.swn
26
+ *.swm
27
+ *.swl
28
+ *.swk
29
+ *.swj
30
+ *.swi
31
+ *.swg
32
+ *.swf
33
+ *.swe
34
+ *.swd
35
+ *.swc
36
+ *.swb
37
+ *.swa
38
+ *.sw9
39
+ *.sw8
40
+ *.sw7
41
+ *.sw6
42
+ *.sw5
43
+ *.sw4
44
+ *.sw3
45
+ *.sw2
46
+ *.sw1
47
+ *.sw0
48
+ *.s9
49
+ *.s8
50
+ *.s7
51
+ *.s6
52
+ *.s5
53
+ *.s4
54
+ *.s3
55
+ *.s2
56
+ *.s1
57
+ *.s0
58
+ *.s
59
+ *.r9
60
+ *.r8
61
+ *.r7
62
+ *.r6
63
+ *.r5
64
+ *.r4
65
+ *.r3
66
+ *.r2
67
+ *.r1
68
+ *.r0
69
+ *.r
70
+ *.q9
71
+ *.q8
72
+ *.q7
73
+ *.q6
74
+ *.q5
75
+ *.q4
76
+ *.q3
77
+ *.q2
78
+ *.q1
79
+ *.q0
80
+ *.q
81
+ *.p9
82
+ *.p8
83
+ *.p7
84
+ *.p6
85
+ *.p5
86
+ *.p4
87
+ *.p3
88
+ *.p2
89
+ *.p1
90
+ *.p0
91
+ *.p
92
+ *.o9
93
+ *.o8
94
+ *.o7
95
+ *.o6
96
+ *.o5
97
+ *.o4
98
+ *.o3
99
+ *.o2
100
+ *.o1
101
+ *.o0
102
+ *.o
103
+ *.n9
104
+ *.n8
105
+ *.n7
106
+ *.n6
107
+ *.n5
108
+ *.n4
109
+ *.n3
110
+ *.n2
111
+ *.n1
112
+ *.n0
113
+ *.n
114
+ *.m9
115
+ *.m8
116
+ *.m7
117
+ *.m6
118
+ *.m5
119
+ *.m4
120
+ *.m3
121
+ *.m2
122
+ *.m1
123
+ *.m0
124
+ *.m
125
+ *.l9
126
+ *.l8
127
+ *.l7
128
+ *.l6
129
+ *.l5
130
+ *.l4
131
+ *.l3
132
+ *.l2
133
+ *.l1
134
+ *.l0
135
+ *.l
136
+ *.k9
137
+ *.k8
138
+ *.k7
139
+ *.k6
140
+ *.k5
141
+ *.k4
142
+ *.k3
143
+ *.k2
144
+ *.k1
145
+ *.k0
146
+ *.k
147
+ *.j9
148
+ *.j8
149
+ *.j7
150
+ *.j6
151
+ *.j5
152
+ *.j4
153
+ *.j3
154
+ *.j2
155
+ *.j1
156
+ *.j0
157
+ *.j
158
+ *.i9
159
+ *.i8
160
+ *.i7
161
+ *.i6
162
+ *.i5
163
+ *.i4
164
+ *.i3
165
+ *.i2
166
+ *.i1
167
+ *.i0
168
+ *.i
169
+ *.h9
170
+ *.h8
171
+ *.h7
172
+ *.h6
173
+ *.h5
174
+ *.h4
175
+ *.h3
176
+ *.h2
177
+ *.h1
178
+ *.h0
179
+ *.h
180
+ *.g9
181
+ *.g8
182
+ *.g7
183
+ *.g6
184
+ *.g5
185
+ *.g4
186
+ *.g3
187
+ *.g2
188
+ *.g1
189
+ *.g0
190
+ *.g
191
+ *.f9
192
+ *.f8
193
+ *.f7
194
+ *.f6
195
+ *.f5
196
+ *.f4
197
+ *.f3
198
+ *.f2
199
+ *.f1
200
+ *.f0
201
+ *.f
202
+ *.e9
203
+ *.e8
204
+ *.e7
205
+ *.e6
206
+ *.e5
207
+ *.e4
208
+ *.e3
209
+ *.e2
210
+ *.e1
211
+ *.e0
212
+ *.e
213
+ *.d9
214
+ *.d8
215
+ *.d7
216
+ *.d6
217
+ *.d5
218
+ *.d4
219
+ *.d3
220
+ *.d2
221
+ *.d1
222
+ *.d0
223
+ *.d
224
+ *.c9
225
+ *.c8
226
+ *.c7
227
+ *.c6
228
+ *.c5
229
+ *.c4
230
+ *.c3
231
+ *.c2
232
+ *.c1
233
+ *.c0
234
+ *.c
235
+ *.b9
236
+ *.b8
237
+ *.b7
238
+ *.b6
239
+ *.b5
240
+ *.b4
241
+ *.b3
242
+ *.b2
243
+ *.b1
244
+ *.b0
245
+ *.b
246
+ *.a9
247
+ *.a8
248
+ *.a7
249
+ *.a6
250
+ *.a5
251
+ *.a4
252
+ *.a3
253
+ *.a2
254
+ *.a1
255
+ *.a0
256
+ *.a
257
+ *.9
258
+ *.8
259
+ *.7
260
+ *.6
261
+ *.5
262
+ *.4
263
+ *.3
264
+ *.2
265
+ *.1
266
+ *.0
267
+ *.~
268
+ *~
LLM/LLMGuard/GuardProcessor.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from llm_guard.input_scanners import Anonymize
2
+ from llm_guard.vault import Vault
3
+ from llm_guard.input_scanners.anonymize_helpers import BERT_LARGE_NER_CONF
4
+
5
+
6
+ def process_output_with_llmguard(output):
7
+ print(f"Processed with LLMGuard: {output}")
8
+
9
+ # Need to not disclose student id or other sensitive information using LLMGuard
10
+
11
+ # Use the LLMGuard to scan the output
12
+ vault = Vault()
13
+ scanner = Anonymize(vault, preamble="Insert before prompt", recognizer_conf=BERT_LARGE_NER_CONF, language="en")
14
+
15
+ # Anonymize the output
16
+ anonymized_output, is_valid, risk_score = scanner.scan(output)
17
+
18
+ return anonymized_output
19
+
20
+
21
+ def process_input_with_llmguard(input):
22
+ print(f"Processed with LLMGuard: {input}")
23
+
24
+ # Need to not disclose student id or other sensitive information using LLMGuard
25
+
26
+ # Use the LLMGuard to scan the output
27
+ vault = Vault()
28
+ scanner = Anonymize(vault, preamble="Insert before prompt", recognizer_conf=BERT_LARGE_NER_CONF, language="en")
29
+
30
+ # Anonymize the output
31
+ anonymized_output, is_valid, risk_score = scanner.scan(input)
32
+
33
+ return anonymized_output
LLM/LLMGuard/InputScanners/IDScanner.py ADDED
File without changes
LLM/LLMGuard/InputScanners/NNumberScanner.py ADDED
File without changes
LLM/LLMGuard/InputScanners/StudentIDScanner.py ADDED
File without changes
LLM/MockLLM.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ def generate_mock_output(prompt):
2
+ # Simple mock output for testing
3
+ return f"Mock output for: {prompt}"
README.md ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ LLMGuard is a project that utilizes Gradio and LLMGuard to protect users from leaking personal information in a university environment.
2
+
3
+ ## Installation
4
+
5
+ To install LLMGuard, follow these steps:
6
+
7
+ 1. Clone the repository: `git clone https://github.com/your-username/LLMGuard.git`
8
+ 2. Install the required dependencies: `pip install -r requirements.txt`
9
+
10
+ ## Usage
11
+
12
+ To run this project, follow these steps:
13
+
14
+ 1. Run `main.py`: `python main.py`
15
+
16
+ ## TODO
17
+
18
+ - [] Implement scanners to detect personal information leakage. :mag:
19
+ - [] Consider using regex scanner for more accurate detection. :dart:
20
+ - [] Implement real LLM (Leakage Limiting Mechanism) instead of the mock version. :gear:
21
+ - [] Generate tests to automate the testing process. :test_tube:
main.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from LLM.MockLLM import generate_mock_output
3
+ from LLM.LLMGuard.GuardProcessor import process_output_with_llmguard, process_input_with_llmguard
4
+
5
+ def run_llm_guard(prompt):
6
+ # Generate mock LLM output
7
+ mock_output = generate_mock_output(process_input_with_llmguard(prompt))
8
+
9
+ # Process the output with LLMGuard (placeholder)
10
+ processed_output = process_output_with_llmguard(mock_output)
11
+
12
+ return processed_output
13
+
14
+ # Gradio Interface
15
+ iface = gr.Interface(
16
+ fn=run_llm_guard,
17
+ inputs="text",
18
+ outputs="text",
19
+ title="LLMGuard Tester",
20
+ description="Enter a prompt to generate mock LLM output and process it with LLMGuard."
21
+ )
22
+
23
+ if __name__ == "__main__":
24
+ iface.launch()
requirements.txt ADDED
Binary file (36 Bytes). View file