Spaces:
Sleeping
Sleeping
Ankit19102004 commited on
Commit ·
3589264
1
Parent(s): 93621ed
Update honeypot_api and README
Browse files- honeypot_api.py +78 -30
honeypot_api.py
CHANGED
|
@@ -8,7 +8,7 @@ from transformers import BertTokenizer, BertForSequenceClassification
|
|
| 8 |
|
| 9 |
API_KEY = os.getenv("HONEYPOT_API_KEY")
|
| 10 |
GUVI_CALLBACK_URL = "https://hackathon.guvi.in/api/updateHoneyPotFinalResult"
|
| 11 |
-
MIN_MESSAGES_FOR_CALLBACK =
|
| 12 |
|
| 13 |
logging.basicConfig(level=logging.INFO)
|
| 14 |
|
|
@@ -141,33 +141,79 @@ def extract_intelligence(text):
|
|
| 141 |
def generate_agent_reply(session_id):
|
| 142 |
|
| 143 |
history = conversation_store[session_id]
|
| 144 |
-
turn = len(history)
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
"
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
|
| 172 |
if not reply.endswith("?"):
|
| 173 |
reply += "?"
|
|
@@ -239,7 +285,8 @@ def send_callback(session_id):
|
|
| 239 |
engagement = compute_engagement_score(session_id)
|
| 240 |
intel = intelligence_store[session_id]
|
| 241 |
|
| 242 |
-
|
|
|
|
| 243 |
|
| 244 |
conf_values = confidence_store.get(session_id, [])
|
| 245 |
if conf_values:
|
|
@@ -338,7 +385,8 @@ def honeypot_message():
|
|
| 338 |
conversation_store[session_id].append({"sender": "agent", "text": reply})
|
| 339 |
|
| 340 |
if scam and not callback_done[session_id]:
|
| 341 |
-
|
|
|
|
| 342 |
send_callback(session_id)
|
| 343 |
|
| 344 |
engagement = compute_engagement_score(session_id)
|
|
|
|
| 8 |
|
| 9 |
API_KEY = os.getenv("HONEYPOT_API_KEY")
|
| 10 |
GUVI_CALLBACK_URL = "https://hackathon.guvi.in/api/updateHoneyPotFinalResult"
|
| 11 |
+
MIN_MESSAGES_FOR_CALLBACK = 10
|
| 12 |
|
| 13 |
logging.basicConfig(level=logging.INFO)
|
| 14 |
|
|
|
|
| 141 |
def generate_agent_reply(session_id):
|
| 142 |
|
| 143 |
history = conversation_store[session_id]
|
| 144 |
+
turn = len([m for m in history if m["sender"] == "scammer"])
|
| 145 |
+
|
| 146 |
+
last_scammer_text = ""
|
| 147 |
+
for m in reversed(history):
|
| 148 |
+
if m["sender"] == "scammer":
|
| 149 |
+
last_scammer_text = m["text"]
|
| 150 |
+
break
|
| 151 |
+
|
| 152 |
+
text_lower = last_scammer_text.lower()
|
| 153 |
+
|
| 154 |
+
upi_hint = None
|
| 155 |
+
email_hint = None
|
| 156 |
+
amount_hint = None
|
| 157 |
+
|
| 158 |
+
upi_match = re.search(r"[a-zA-Z0-9.\-_+]+@[a-zA-Z]+", last_scammer_text)
|
| 159 |
+
if upi_match:
|
| 160 |
+
upi_hint = upi_match.group(0)
|
| 161 |
+
|
| 162 |
+
email_match = re.search(r"[a-zA-Z0-9.\-_+]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]+", last_scammer_text)
|
| 163 |
+
if email_match:
|
| 164 |
+
email_hint = email_match.group(0)
|
| 165 |
+
|
| 166 |
+
amount_match = re.search(r"rs\.?\s*([\d,]+)", text_lower)
|
| 167 |
+
if amount_match:
|
| 168 |
+
amount_hint = amount_match.group(1)
|
| 169 |
+
|
| 170 |
+
otp_flag = "otp" in text_lower
|
| 171 |
+
fee_flag = "fee" in text_lower or "charges" in text_lower or "processing" in text_lower
|
| 172 |
+
account_flag = "account" in text_lower
|
| 173 |
+
link_flag = "http://" in text_lower or "https://" in text_lower or "link" in text_lower
|
| 174 |
+
|
| 175 |
+
if upi_hint:
|
| 176 |
+
reply = (
|
| 177 |
+
f"I see you are asking me to send money to UPI ID {upi_hint}. "
|
| 178 |
+
"I am not comfortable sending any payment until I can verify this is really from the bank. "
|
| 179 |
+
"Can you share an official way I can confirm that this UPI ID actually belongs to your organisation?"
|
| 180 |
+
)
|
| 181 |
+
elif otp_flag:
|
| 182 |
+
reply = (
|
| 183 |
+
"You are asking for my OTP and that makes me very uncomfortable. "
|
| 184 |
+
"I was always told never to share an OTP with anyone. "
|
| 185 |
+
"Why do you need my OTP at all if you already have my details?"
|
| 186 |
+
)
|
| 187 |
+
elif fee_flag or amount_hint:
|
| 188 |
+
if amount_hint:
|
| 189 |
+
reply = (
|
| 190 |
+
f"You mentioned a payment of around Rs.{amount_hint} plus extra charges. "
|
| 191 |
+
"This sounds unusual for a security check. "
|
| 192 |
+
"Can you explain clearly why this amount is required and whether there is any official receipt?"
|
| 193 |
+
)
|
| 194 |
+
else:
|
| 195 |
+
reply = (
|
| 196 |
+
"You keep talking about fees and charges and I do not fully understand them. "
|
| 197 |
+
"Can you break down every fee and confirm if there are any hidden costs?"
|
| 198 |
+
)
|
| 199 |
+
elif link_flag:
|
| 200 |
+
reply = (
|
| 201 |
+
"You are asking me to trust this without showing me any proper website or link I can verify. "
|
| 202 |
+
"Can you give me an official page from my bank's website where this process is explained clearly?"
|
| 203 |
+
)
|
| 204 |
+
elif account_flag:
|
| 205 |
+
reply = (
|
| 206 |
+
"You keep mentioning my account but I still do not know if you are really from the bank. "
|
| 207 |
+
"Can you prove your identity in some official way before I share any account details?"
|
| 208 |
+
)
|
| 209 |
+
else:
|
| 210 |
+
generic_questions = [
|
| 211 |
+
"Can you explain step by step what exactly you want me to do?",
|
| 212 |
+
"Is there any other safe way to handle this without me sharing sensitive details right now?",
|
| 213 |
+
"Can you clearly confirm how my account will be affected if I wait a bit?",
|
| 214 |
+
"Can you tell me which branch or department you are actually calling from?",
|
| 215 |
+
]
|
| 216 |
+
reply = random.choice(generic_questions)
|
| 217 |
|
| 218 |
if not reply.endswith("?"):
|
| 219 |
reply += "?"
|
|
|
|
| 285 |
engagement = compute_engagement_score(session_id)
|
| 286 |
intel = intelligence_store[session_id]
|
| 287 |
|
| 288 |
+
scammer_count = len([m for m in conv if m["sender"] == "scammer"])
|
| 289 |
+
duration_seconds = max(240, scammer_count * 24)
|
| 290 |
|
| 291 |
conf_values = confidence_store.get(session_id, [])
|
| 292 |
if conf_values:
|
|
|
|
| 385 |
conversation_store[session_id].append({"sender": "agent", "text": reply})
|
| 386 |
|
| 387 |
if scam and not callback_done[session_id]:
|
| 388 |
+
scammer_msgs = [m for m in conversation_store[session_id] if m["sender"] == "scammer"]
|
| 389 |
+
if len(scammer_msgs) >= MIN_MESSAGES_FOR_CALLBACK:
|
| 390 |
send_callback(session_id)
|
| 391 |
|
| 392 |
engagement = compute_engagement_score(session_id)
|