-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
300 lines (281 loc) · 11.5 KB
/
config.py
File metadata and controls
300 lines (281 loc) · 11.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
"""
Configuration file for GemmaSOS Crisis Intervention System
"""
import os
from typing import Dict, List, Any
class Config:
"""Configuration settings for the crisis intervention system"""
# Model Configuration
MODEL_NAME = "google/gemma-2b-it"
MODEL_CACHE_DIR = os.path.join(os.path.expanduser("~"), ".cache", "huggingface", "transformers")
# Safety Thresholds
SAFETY_THRESHOLDS = {
"immediate_risk": 0.8,
"high_risk": 0.6,
"medium_risk": 0.4,
"low_risk": 0.2
}
# Gemma Safety Categories Configuration
GEMMA_SAFETY_CATEGORIES = {
"self_harm": {
"description": "Content expressing intent to harm oneself, including suicide ideation, self-injury, or self-destructive behavior",
"severity_levels": ["low", "medium", "high"],
"crisis_mapping": "self_harm"
},
"violence": {
"description": "Content expressing intent to harm others, threats of violence, or promoting violence",
"severity_levels": ["low", "medium", "high"],
"crisis_mapping": "violence"
},
"harassment": {
"description": "Content that is abusive, threatening, or intended to intimidate or harm others",
"severity_levels": ["low", "medium", "high"],
"crisis_mapping": "abuse"
},
"dangerous_content": {
"description": "Content that promotes dangerous activities, substance abuse, or harmful behaviors",
"severity_levels": ["low", "medium", "high"],
"crisis_mapping": "overdose"
}
}
# Safety Analysis Configuration
SAFETY_ANALYSIS_CONFIG = {
"confidence_threshold": 0.3,
"high_severity_threshold": 0.7,
"immediate_risk_indicators": ["high", "immediate", "urgent"],
"response_temperature": 0.6,
"max_safety_tokens": 300
}
# Content Filtering Rules
CONTENT_FILTERS = {
"harmful_content": [
"detailed methods", "step by step", "how to", "instructions",
"tutorial", "guide", "detailed", "specific", "exact"
],
"triggering_content": [
"graphic", "explicit", "detailed description", "gory",
"disturbing", "traumatic", "triggering"
],
"dangerous_advice": [
"ignore professional help", "don't tell anyone", "keep it secret",
"you're alone", "no one cares", "give up"
]
}
# Crisis Resources
CRISIS_RESOURCES = {
"general": [
{
"name": "National Suicide Prevention Lifeline",
"number": "988",
"text": "Text HOME to 741741",
"description": "24/7 crisis support for suicide prevention",
"available": "24/7"
},
{
"name": "Crisis Text Line",
"number": "Text HOME to 741741",
"description": "Free, 24/7 crisis support via text",
"available": "24/7"
}
],
"self_harm": [
{
"name": "Self-Injury Outreach & Support",
"website": "sioutreach.org",
"description": "Resources and support for self-injury recovery"
},
{
"name": "To Write Love on Her Arms",
"website": "twloha.com",
"description": "Hope and help for people struggling with depression, addiction, self-injury, and suicide"
}
],
"suicide": [
{
"name": "National Suicide Prevention Lifeline",
"number": "988",
"text": "Text HOME to 741741",
"description": "24/7 crisis support for suicide prevention",
"available": "24/7"
},
{
"name": "American Foundation for Suicide Prevention",
"website": "afsp.org",
"description": "Resources, support groups, and prevention programs"
}
],
"violence": [
{
"name": "National Domestic Violence Hotline",
"number": "1-800-799-7233",
"text": "Text START to 88788",
"description": "24/7 support for domestic violence",
"available": "24/7"
},
{
"name": "National Sexual Assault Hotline",
"number": "1-800-656-4673",
"description": "24/7 support for sexual assault survivors",
"available": "24/7"
}
],
"abuse": [
{
"name": "National Domestic Violence Hotline",
"number": "1-800-799-7233",
"text": "Text START to 88788",
"description": "24/7 support for domestic violence",
"available": "24/7"
},
{
"name": "Childhelp National Child Abuse Hotline",
"number": "1-800-4-A-CHILD (1-800-422-4453)",
"description": "24/7 support for child abuse",
"available": "24/7"
}
],
"overdose": [
{
"name": "SAMHSA National Helpline",
"number": "1-800-662-4357",
"description": "24/7 treatment referral and information service",
"available": "24/7"
},
{
"name": "National Poison Control Center",
"number": "1-800-222-1222",
"description": "24/7 poison emergency support",
"available": "24/7"
}
]
}
# Response Templates
RESPONSE_TEMPLATES = {
"self_harm": {
"immediate": [
"I can hear that you're in a lot of pain right now. You don't have to go through this alone.",
"I'm really concerned about you. Your life has value, even when it doesn't feel that way.",
"I want you to know that what you're feeling right now is valid, and there are people who care about you."
],
"supportive": [
"It takes courage to reach out when you're struggling. I'm glad you did.",
"You're not alone in this. Many people have felt this way and found ways to cope.",
"Your feelings are important, and so are you."
]
},
"suicide": {
"immediate": [
"I'm very concerned about you right now. Your life matters, and I want to help you stay safe.",
"I can hear how much pain you're in. Please know that you don't have to face this alone.",
"I care about you, and I want to make sure you're safe. Can we talk about what's happening?"
],
"supportive": [
"Thank you for sharing this with me. It takes incredible strength to be so honest.",
"I'm here with you. You don't have to carry this burden alone.",
"Your life has meaning, even when it's hard to see right now."
]
},
"violence": {
"immediate": [
"I'm concerned about your safety. Violence is never the answer, and there are better ways to handle this.",
"I can hear that you're very angry right now. Let's talk about what's really bothering you.",
"I want to help you find a safer way to express these feelings."
],
"supportive": [
"It's okay to feel angry, but we need to find safe ways to express it.",
"I'm here to listen and help you work through these feelings.",
"There are people who can help you resolve this situation safely."
]
},
"abuse": {
"immediate": [
"I'm so sorry this is happening to you. You don't deserve to be treated this way.",
"Your safety is the most important thing right now. You're not alone.",
"I believe you, and I want to help you get to safety."
],
"supportive": [
"It took courage to share this with me. You're not to blame for what happened.",
"You deserve to be treated with respect and kindness.",
"I'm here to support you in whatever way you need."
]
},
"overdose": {
"immediate": [
"I'm very concerned about your safety right now. Please don't take any more.",
"Your life is valuable, and I want to help you stay safe.",
"If you've already taken something, please call emergency services immediately."
],
"supportive": [
"I'm glad you're reaching out. You don't have to face this alone.",
"There are people who care about you and want to help you through this.",
"Recovery is possible, and you deserve support."
]
}
}
# UI Configuration
UI_CONFIG = {
"title": "GemmaSOS - Crisis Support",
"description": "Your privacy is protected - Everything processes on your device. Nothing is sent to external servers.",
"server_name": "0.0.0.0",
"server_port": 7860,
"share": False,
"show_error": True
}
# Logging Configuration
LOGGING_CONFIG = {
"level": "INFO",
"format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s",
"file": "logs/gemma_sos.log"
}
# Privacy Configuration
PRIVACY_CONFIG = {
"data_retention_hours": 24,
"max_session_duration_hours": 8,
"auto_cleanup_interval_hours": 1,
"max_log_entries": 100
}
# Image Processing Configuration
IMAGE_CONFIG = {
"max_file_size_mb": 10,
"allowed_formats": ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.webp'],
"max_dimensions": (2048, 2048)
}
# Model Processing Configuration
MODEL_CONFIG = {
"max_tokens": 512,
"temperature": 0.7,
"max_new_tokens": 200,
"do_sample": True
}
@classmethod
def get_config(cls) -> Dict[str, Any]:
"""Get all configuration as a dictionary"""
return {
"model_name": cls.MODEL_NAME,
"safety_thresholds": cls.SAFETY_THRESHOLDS,
"gemma_safety_categories": cls.GEMMA_SAFETY_CATEGORIES,
"safety_analysis_config": cls.SAFETY_ANALYSIS_CONFIG,
"content_filters": cls.CONTENT_FILTERS,
"crisis_resources": cls.CRISIS_RESOURCES,
"response_templates": cls.RESPONSE_TEMPLATES,
"ui_config": cls.UI_CONFIG,
"logging_config": cls.LOGGING_CONFIG,
"privacy_config": cls.PRIVACY_CONFIG,
"image_config": cls.IMAGE_CONFIG,
"model_config": cls.MODEL_CONFIG
}
@classmethod
def update_config(cls, **kwargs):
"""Update configuration values"""
for key, value in kwargs.items():
if hasattr(cls, key.upper()):
setattr(cls, key.upper(), value)
else:
raise ValueError(f"Unknown configuration key: {key}")
# Environment-specific overrides
if os.getenv("GEMMA_SOS_DEBUG"):
Config.LOGGING_CONFIG["level"] = "DEBUG"
if os.getenv("GEMMA_SOS_PORT"):
Config.UI_CONFIG["server_port"] = int(os.getenv("GEMMA_SOS_PORT"))
if os.getenv("GEMMA_SOS_MODEL"):
Config.MODEL_NAME = os.getenv("GEMMA_SOS_MODEL")