kevinhug commited on
Commit
3d3fe99
·
1 Parent(s): 21d7fc9

fraud prevention

Browse files
Files changed (2) hide show
  1. app.py +43 -0
  2. controls.py +89 -0
app.py CHANGED
@@ -3,6 +3,7 @@ import gradio as gr
3
  from classify import judge
4
  from entity import resolve
5
  from graphrag import marketingPlan
 
6
  from human import email, feedback
7
  from knowledge import graph
8
  from pii import derisk
@@ -239,6 +240,48 @@ Agents include:
239
  - Refactor assistant agent: Suggests how to fix the issue, with references to existing secure modules.
240
  """)
241
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
242
  with gr.Tab("Graphrag Marketing"):
243
  gr.Markdown("""
244
  Objective: Develop a Targeted Marketing Plan Aligned with Customer Personas
 
3
  from classify import judge
4
  from entity import resolve
5
  from graphrag import marketingPlan
6
+ from controls import conan
7
  from human import email, feedback
8
  from knowledge import graph
9
  from pii import derisk
 
240
  - Refactor assistant agent: Suggests how to fix the issue, with references to existing secure modules.
241
  """)
242
 
243
+ with gr.Tab("Fraud Controls"):
244
+ gr.Markdown("""
245
+ Objective: Develop a preventive, detective controls for red flags
246
+ =======================
247
+
248
+ """)
249
+
250
+ in_question = gr.Textbox(label="Story")
251
+ out_product = gr.Textbox(label="Controls")
252
+
253
+ gr.Examples(
254
+ [
255
+ [
256
+ """
257
+ Dear Sir,
258
+
259
+ I am DR Lucas Chiebo, the personal Assistance to the late Nigerian Minister of Justice and the Attorney General of the Federal ChiefBola Ige, who was murdered on 23rd of December 2001 by unknown persons. Before he became the minister of Justice and the Attorney General of the Federation, he was once the Minister of Mines and Power. During his time as a Minister of Mines and Power, the Federal Government of Nigeria gave to his ministry the sum of US$200 Million, which is to be used for the completion of the Ajaokuta Steel Industry and the purchasing of electrical transformers and able for the Nigerian Electric Power Authority (NEPA). Then this jobs and the supply of the transformers and cables were done, but of low Quality standard and the transformers he imported were of low quality standard and of low power capacity.
260
+
261
+ Because of the low quality standard of this jobs, the sum of US$22 Million was realized of which he deposited US$15 Million to a security company abroad and was looking for a reliable person or company whom he will transact business with before he meet his un-timely death on the 23rd of December, 2001. He informed the security company about his foreign partner who will be coming to pick the money although no company’s name was given to the security company before he died it was only I and the late Chief Bola Ige knew about the money.
262
+
263
+ Therefore, if you can be trusted in fairness to your honesty to safe keep that money pending when I will be coming to meet you in your country. Please, if you are not interested with this business, kindly inform me As soon as you received this proposals. At the same time, if you are interested, kindly send me as a matter of urgency: your company’s name and address, your private phone and fax number. This will be used to send to you the fund deposit certificate which you will use to claim the money from the Security company.
264
+
265
+ I am awaiting to hear from you.
266
+
267
+ Best regard.
268
+
269
+ DR Lucas Chiebo
270
+ """]
271
+ ],
272
+ [in_question]
273
+ )
274
+ btn_recommend = gr.Button("Preventive, Detective Controls")
275
+ btn_recommend.click(fn=conan, inputs=[in_verbatim], outputs=out_product)
276
+
277
+ gr.Markdown("""
278
+ Example Output
279
+ ==========
280
+ To mitigate this risk, we should verify the authenticity of DR Chiebo's identity and gather more information before proceeding. This can be done by conducting thorough research, verifying the individual's credentials, and being cautious when sharing sensitive information. It is also essential to be aware of common scams targeting grieving individuals and to take steps to protect their personal financial information.
281
+
282
+
283
+ """)
284
+
285
  with gr.Tab("Graphrag Marketing"):
286
  gr.Markdown("""
287
  Objective: Develop a Targeted Marketing Plan Aligned with Customer Personas
controls.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import dspy
2
+ import os
3
+
4
+ from dspy.predict.react import Tool
5
+ from tavily import TavilyClient
6
+
7
+
8
+ lm = dspy.LM('ollama_chat/llama3.2', api_base='http://localhost:11434', api_key='')
9
+ #lm = dspy.LM('ollama_chat/deepseek-r1', api_base='http://localhost:11434', api_key='')
10
+ #lm = dspy.LM('ollama_chat/qwq', api_base='http://localhost:11434', api_key='')
11
+ #lm = dspy.LM('ollama_chat/deepscaler', api_base='http://localhost:11434', api_key='')
12
+ #lm = dspy.LM('huggingface/Qwen/Qwen2.5-Coder-32B-Instruct')
13
+ #lm = dspy.LM('huggingface/meta-llama/Llama-3.2-1B')
14
+ #lm = dspy.LM('groq/qwen-qwq-32b')
15
+ dspy.configure(lm=lm)
16
+
17
+ search_client = TavilyClient(api_key=os.environ["T_TOKEN"])
18
+
19
+ class RedFlagsGenerator(dspy.Signature):
20
+ """Generate red flags based on story in fraud topologies"""
21
+ story: str = dspy.InputField()
22
+ red_flag: str = dspy.OutputField()
23
+
24
+ class ControlsGenerator(dspy.Signature):
25
+ """Generate preventive, detective, corrective controls based on red flag"""
26
+ red_flag: str = dspy.InputField()
27
+ control: str = dspy.OutputField()
28
+
29
+ def search_wikipedia(query: str) -> list[str]:
30
+ """Query ColBERT endpoint, which is a knowledge source based on wikipedia data"""
31
+ results = dspy.ColBERTv2(url='http://20.102.90.50:2017/wiki17_abstracts')(query, k=1)
32
+ return [x["text"] for x in results]
33
+
34
+
35
+ def control_search(query: str) -> list[str]:
36
+ """Run a web search to return the top 3 control to verify red flags is a hoax or false positive"""
37
+ response = search_client.search(query)
38
+ return [r["content"] for r in response["results"]]
39
+
40
+ class Detective(dspy.Module):
41
+ """
42
+ As a fraud investigator, analyze the following case story to assess the likelihood of fraud. Use a structured framework that includes:
43
+
44
+ Fraudster Profile & Actions
45
+ Identify the behavioral profile of the fraudster (e.g., boaster, manipulator, deceiver).
46
+ Map their actions to common fraud typologies (social engineering, impersonation, identity theft, financial asset targeting).
47
+
48
+ Highlight red flags (fake phone numbers, urgent secrecy, impersonation of authorities, threats of jail).
49
+ Use control to validate whether each red flag is hoax or a false positive.
50
+
51
+ Examples: cross-checking official contact numbers on verified government websites, confirming with independent third parties, requesting written documentation, checking with financial institutions’ fraud units, or using telecom records (Rogers, etc.) for number spoofing.
52
+
53
+ Risk Assessment
54
+ - Provide a reasoned judgment on whether the case represents fraud, hoax, or a legitimate investigation.
55
+ - Explain potential impact (identity theft, wealth destruction, reputational damage).
56
+ """
57
+ def __init__(self):
58
+ self.redFlags_generator = dspy.ChainOfThought(RedFlagsGenerator)
59
+ self.controls_generator = dspy.ReAct(ControlsGenerator, tools=[Tool(control_search), Tool(search_wikipedia)])
60
+
61
+ def forward(self, story, **kwargs):
62
+ fraud = self.redFlags_generator(story=story).red_flag
63
+ return self.controls_generator(red_flag=fraud).control
64
+
65
+
66
+
67
+ story = """
68
+ Dear Sir,
69
+
70
+ I am DR Lucas Chiebo, the personal Assistance to the late Nigerian Minister of Justice and the Attorney General of the Federal ChiefBola Ige, who was murdered on 23rd of December 2001 by unknown persons. Before he became the minister of Justice and the Attorney General of the Federation, he was once the Minister of Mines and Power. During his time as a Minister of Mines and Power, the Federal Government of Nigeria gave to his ministry the sum of US$200 Million, which is to be used for the completion of the Ajaokuta Steel Industry and the purchasing of electrical transformers and able for the Nigerian Electric Power Authority (NEPA). Then this jobs and the supply of the transformers and cables were done, but of low Quality standard and the transformers he imported were of low quality standard and of low power capacity.
71
+
72
+ Because of the low quality standard of this jobs, the sum of US$22 Million was realized of which he deposited US$15 Million to a security company abroad and was looking for a reliable person or company whom he will transact business with before he meet his un-timely death on the 23rd of December, 2001. He informed the security company about his foreign partner who will be coming to pick the money although no company’s name was given to the security company before he died it was only I and the late Chief Bola Ige knew about the money.
73
+
74
+ Therefore, if you can be trusted in fairness to your honesty to safe keep that money pending when I will be coming to meet you in your country. Please, if you are not interested with this business, kindly inform me As soon as you received this proposals. At the same time, if you are interested, kindly send me as a matter of urgency: your company’s name and address, your private phone and fax number. This will be used to send to you the fund deposit certificate which you will use to claim the money from the Security company.
75
+
76
+ I am awaiting to hear from you.
77
+
78
+ Best regard.
79
+
80
+ DR Lucas Chiebo
81
+ """
82
+
83
+ conan = Detective()
84
+ #dspy.inspect_history()
85
+
86
+ if __name__=='__main__':
87
+ #recommend(story)
88
+
89
+ print(conan(story=story))