Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -89,8 +89,8 @@ def check_for_drug_content(input_text):
|
|
89 |
# Sidebar with options
|
90 |
selected = option_menu(
|
91 |
"Main Menu",
|
92 |
-
["Home", "Registration","Chat"
|
93 |
-
icons=['house', 'person','chat-dots'
|
94 |
menu_icon="cast",
|
95 |
default_index=0,
|
96 |
orientation="horizontal",
|
@@ -125,36 +125,48 @@ def get_chatmodel_response(user_message):
|
|
125 |
#from registration
|
126 |
#remove debugging
|
127 |
|
128 |
-
PROMPT_TEMPLATE = """
|
|
|
129 |
|
130 |
-
Key substances to focus on:
|
131 |
-
- MDMA
|
132 |
-
- LSD
|
133 |
-
- Mephedrone
|
134 |
-
- Cocaine
|
135 |
-
- Heroin
|
136 |
-
- Marijuana
|
137 |
-
- Ecstasy
|
138 |
-
- Crack
|
139 |
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
|
|
145 |
|
146 |
-
|
|
|
|
|
|
|
|
|
147 |
|
148 |
-
|
149 |
-
{phone_number}
|
150 |
-
drug word detected: {{drug_word_detected}}
|
151 |
|
152 |
-
|
|
|
|
|
|
|
153 |
|
154 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
155 |
|
156 |
-
Response:
|
157 |
-
"""
|
158 |
|
159 |
|
160 |
memory = ConversationBufferWindowMemory(k=5, return_messages=True)
|
@@ -408,7 +420,7 @@ elif selected == "Chat":
|
|
408 |
st.session_state.messages.append({"message": response, "is_user": False})
|
409 |
|
410 |
# Rerun to refresh the UI with new messages
|
411 |
-
st.
|
412 |
else:
|
413 |
st.warning("Please enter a message.")
|
414 |
|
@@ -416,42 +428,42 @@ elif selected == "Chat":
|
|
416 |
traffitrack_chatbot()
|
417 |
|
418 |
|
419 |
-
elif selected == "Statistics":
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
|
456 |
# Custom CSS for a better user interface
|
457 |
st.markdown(f"""
|
|
|
89 |
# Sidebar with options
|
90 |
selected = option_menu(
|
91 |
"Main Menu",
|
92 |
+
["Home", "Registration","Chat"],
|
93 |
+
icons=['house', 'person','chat-dots'],
|
94 |
menu_icon="cast",
|
95 |
default_index=0,
|
96 |
orientation="horizontal",
|
|
|
125 |
#from registration
|
126 |
#remove debugging
|
127 |
|
128 |
+
PROMPT_TEMPLATE = """
|
129 |
+
You are an expert assistant specializing in detecting drug-related messages for monitoring illegal drug activities. Your role is to analyze user messages carefully to identify mentions of illegal substances or any activity related to drug trafficking, sales, or use. Your task is not just to detect specific drug names but to understand the context of the conversation, even if indirect or slang terms are used.
|
130 |
|
131 |
+
Key substances and related slang to focus on:
|
132 |
+
- MDMA (Molly, Mandy)
|
133 |
+
- LSD (Acid, Tabs)
|
134 |
+
- Mephedrone (Meow Meow)
|
135 |
+
- Cocaine (Coke, Snow, Blow, White, Charlie)
|
136 |
+
- Heroin (Smack, H, Brown)
|
137 |
+
- Marijuana (Weed, Pot, Mary Jane, Ganja, Bud)
|
138 |
+
- Ecstasy (X, XTC, E)
|
139 |
+
- Crack (Rock, Freebase)
|
140 |
|
141 |
+
Common phrases to consider:
|
142 |
+
- “Looking for Molly” (MDMA reference)
|
143 |
+
- “I need some snow” (Cocaine reference)
|
144 |
+
- “Got any tabs?” (LSD reference)
|
145 |
+
- “Can you hook me up with some blow?” (Cocaine reference)
|
146 |
+
- “I don’t want to mess with Charlie” (Cocaine reference in a negative context)
|
147 |
|
148 |
+
Instructions:
|
149 |
+
1. If you detect any mention of the above substances, slang, or any activities related to drug sales, trafficking, or use, respond with a simple confirmation of detection, including the drug name or slang term detected.
|
150 |
+
2. Be aware of **negations** or sentences where the user may **refuse** the drugs (e.g., "I don’t want cocaine"). Do not flag these as positive detections.
|
151 |
+
3. **Do not** include the original user message in your response.
|
152 |
+
4. Ensure the format includes the following fields: sender's name, phone number, and the detected drug word/slang. However, if there is **no drug-related content**, respond with only the message "drug word detected: none."
|
153 |
|
154 |
+
Below is the required format for your response:
|
|
|
|
|
155 |
|
156 |
+
If a drug word is detected:
|
157 |
+
{name}
|
158 |
+
{phone_number}
|
159 |
+
drug word detected: {{drug_word_detected}}
|
160 |
|
161 |
+
If no drug word is detected:
|
162 |
+
drug word detected: none
|
163 |
+
|
164 |
+
Below is the user message
|
165 |
+
|
166 |
+
User message: {user_message}
|
167 |
+
|
168 |
+
Response: """
|
169 |
|
|
|
|
|
170 |
|
171 |
|
172 |
memory = ConversationBufferWindowMemory(k=5, return_messages=True)
|
|
|
420 |
st.session_state.messages.append({"message": response, "is_user": False})
|
421 |
|
422 |
# Rerun to refresh the UI with new messages
|
423 |
+
st.experimental_rerun()
|
424 |
else:
|
425 |
st.warning("Please enter a message.")
|
426 |
|
|
|
428 |
traffitrack_chatbot()
|
429 |
|
430 |
|
431 |
+
# elif selected == "Statistics":
|
432 |
+
# st.title('Drug Trafficking Statistics 📊')
|
433 |
+
|
434 |
+
# # Generate sample data
|
435 |
+
# data = generate_sample_data()
|
436 |
+
|
437 |
+
# # Display data
|
438 |
+
# st.subheader("Overview of Detected Drugs")
|
439 |
+
# st.dataframe(data)
|
440 |
+
|
441 |
+
# # Plotting the data
|
442 |
+
# st.subheader("Detected Instances of Drugs")
|
443 |
+
# fig, ax = plt.subplots(figsize=(8, 5))
|
444 |
+
# ax.bar(data["Drug Name"], data["Detected Instances"], color="#50B498")
|
445 |
+
# plt.title("Detected Instances of Drugs")
|
446 |
+
# plt.xlabel("Drug Name")
|
447 |
+
# plt.ylabel("Detected Instances")
|
448 |
+
# st.pyplot(fig)
|
449 |
+
|
450 |
+
# # Plotting flagged users
|
451 |
+
# st.subheader("Flagged Users")
|
452 |
+
# fig, ax = plt.subplots(figsize=(8, 5))
|
453 |
+
# ax.bar(data["Drug Name"], data["Flagged Users"], color="#468585")
|
454 |
+
# plt.title("Flagged Users")
|
455 |
+
# plt.xlabel("Drug Name")
|
456 |
+
# plt.ylabel("Flagged Users")
|
457 |
+
# st.pyplot(fig)
|
458 |
+
|
459 |
+
# # Plotting IP addresses
|
460 |
+
# st.subheader("Detected IP Addresses")
|
461 |
+
# fig, ax = plt.subplots(figsize=(8, 5))
|
462 |
+
# ax.bar(data["Drug Name"], data["IP Addresses"], color="#9CDBA6")
|
463 |
+
# plt.title("Detected IP Addresses")
|
464 |
+
# plt.xlabel("Drug Name")
|
465 |
+
# plt.ylabel("Detected IP Addresses")
|
466 |
+
# st.pyplot(fig)
|
467 |
|
468 |
# Custom CSS for a better user interface
|
469 |
st.markdown(f"""
|