File size: 11,246 Bytes
27caffe | 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 301 302 303 304 305 306 307 308 309 | """
Mindfull AI Avatar Chatbot Configuration
Comprehensive configuration for Ollama, F5-TTS, and SadTalker integration
"""
import os
import logging
from pathlib import Path
from typing import Dict, Any, Optional
class MindfullConfig:
"""Configuration class for Mindfull AI Avatar Chatbot"""
# =========================================================================
# ENVIRONMENT CONFIGURATION
# =========================================================================
# Project Paths
PROJECT_ROOT = Path(__file__).parent.absolute()
VENV_PATH = PROJECT_ROOT / "venv"
PYTHON_EXECUTABLE = (
VENV_PATH / "Scripts" / "python.exe" if os.name == 'nt'
else VENV_PATH / "bin" / "python"
)
# Output Directories
OUTPUT_DIR = PROJECT_ROOT / "outputs"
AUDIO_OUTPUT_DIR = OUTPUT_DIR / "audio"
VIDEO_OUTPUT_DIR = OUTPUT_DIR / "video"
TEMP_DIR = OUTPUT_DIR / "temp"
# Avatar Assets
AVATAR_ASSETS_DIR = PROJECT_ROOT / "avatar_assets"
DEFAULT_AVATAR_IMAGE = AVATAR_ASSETS_DIR / "officer.png"
# Create directories if they don't exist
for directory in [OUTPUT_DIR, AUDIO_OUTPUT_DIR, VIDEO_OUTPUT_DIR, TEMP_DIR]:
directory.mkdir(parents=True, exist_ok=True)
# =========================================================================
# OLLAMA CONFIGURATION
# =========================================================================
# Ollama Settings
OLLAMA_BASE_URL = "http://localhost:11434"
OLLAMA_GENERATE_URL = f"{OLLAMA_BASE_URL}/api/generate"
OLLAMA_MODELS_URL = f"{OLLAMA_BASE_URL}/api/tags"
OLLAMA_TIMEOUT = 60
# Model Configuration
DEFAULT_MODEL = "mindfull"
FALLBACK_MODEL = "mistral:7b"
# Model Parameters
MODEL_PARAMS = {
"temperature": 0.7,
"top_p": 0.9,
"top_k": 40,
"repeat_penalty": 1.1,
"num_ctx": 2048,
"stream": False
}
# =========================================================================
# F5-TTS CONFIGURATION
# =========================================================================
# F5-TTS Model Paths
F5TTS_MODEL_DIR = PROJECT_ROOT / "my_finetuned_model"
F5TTS_MODEL_PATH = F5TTS_MODEL_DIR / "model.pth"
F5TTS_CONFIG_PATH = F5TTS_MODEL_DIR / "config.json"
F5TTS_VOCAB_PATH = F5TTS_MODEL_DIR / "vocab.json"
# Reference Audio for Voice Cloning
REFERENCE_AUDIO_DIR = PROJECT_ROOT / "datasets-1" / "wavs"
DEFAULT_REFERENCE_AUDIO = REFERENCE_AUDIO_DIR / "0029.wav"
REFERENCE_TEXT = "Namaskara! How are you feeling today? I'm here to support you."
# TTS Settings
TTS_SETTINGS = {
"language": "en",
"speed": 1.0,
"remove_silence": True,
"normalize_audio": True,
"sample_rate": 24000
}
# =========================================================================
# SADTALKER CONFIGURATION
# =========================================================================
# SadTalker Paths
SADTALKER_DIR = PROJECT_ROOT / "sadtalker+wav2lip"
SADTALKER_SCRIPT = SADTALKER_DIR / "simple_pipeline.py"
SADTALKER_CHECKPOINTS = SADTALKER_DIR / "sadtalker" / "checkpoints"
# SadTalker Settings
SADTALKER_SETTINGS = {
"pose_style": 1,
"exp_scale": 1.3,
"use_enhancer": True,
"use_face_parse": True,
"background_enhance": True,
"face_restore": True,
"face_model": "normal",
"preprocess": "crop",
"still": False, # *** CRITICAL: This was True causing static images! ***
"use_idle_mode": False,
"length_of_audio": 0,
"use_ref_video": False,
"ref_video": None,
"ref_info": None,
"use_idle_mode": False,
"length_of_audio": 0
}
# =========================================================================
# WEB API CONFIGURATION
# =========================================================================
# Web Server Settings
WEB_HOST = "0.0.0.0"
WEB_PORT = 5000
WEB_DEBUG = False
WEB_THREADED = True
# CORS Settings
CORS_ORIGINS = ["*"]
CORS_METHODS = ["GET", "POST", "PUT", "DELETE", "OPTIONS"]
CORS_HEADERS = ["Content-Type", "Authorization"]
# =========================================================================
# SECURITY AND VALIDATION
# =========================================================================
# Input Validation
MAX_TEXT_LENGTH = 500
MIN_TEXT_LENGTH = 1
ALLOWED_LANGUAGES = ["en", "kn"] # English and Kannada
# Rate Limiting
RATE_LIMIT_REQUESTS = 60 # requests per minute
RATE_LIMIT_WINDOW = 60 # seconds
# Session Management
SESSION_TIMEOUT = 3600 # 1 hour
MAX_CONCURRENT_SESSIONS = 10
# =========================================================================
# EMOTIONAL ANALYSIS
# =========================================================================
# Emotion Keywords
EMOTION_KEYWORDS = {
"stress": [
"stressed", "pressure", "overwhelmed", "burned out", "exhausted",
"tense", "worried", "anxious", "strained", "difficult", "hard",
"challenging", "demanding", "intense", "tough"
],
"sadness": [
"sad", "depressed", "down", "low", "unhappy", "miserable",
"lonely", "isolated", "hopeless", "discouraged", "disappointed",
"upset", "hurt", "broken", "empty"
],
"anger": [
"angry", "furious", "frustrated", "irritated", "annoyed",
"mad", "enraged", "outraged", "livid", "aggravated",
"resentful", "bitter", "hostile"
],
"anxiety": [
"anxious", "nervous", "panicked", "worried", "fearful",
"scared", "terrified", "uneasy", "restless", "agitated",
"on edge", "jumpy", "troubled"
],
"positive": [
"good", "great", "happy", "fine", "okay", "well", "excellent",
"fantastic", "wonderful", "amazing", "content", "peaceful",
"calm", "relaxed", "energetic", "motivated", "confident"
]
}
# =========================================================================
# WELLNESS INTERVENTIONS
# =========================================================================
# Wellness Suggestions
WELLNESS_INTERVENTIONS = {
"stress": [
"Take 5 deep, slow breaths",
"Step away for a 2-minute break",
"Drink some water and stay hydrated",
"Do some shoulder rolls and neck stretches",
"Focus on one task at a time",
"Practice the 4-7-8 breathing technique"
],
"sadness": [
"Remember that your service makes a real difference",
"Consider talking to a trusted colleague",
"Reach out to the Well-Being Officer when ready",
"Take a short walk if possible",
"Practice self-compassion - you're doing important work",
"Listen to some calming music during your break"
],
"anger": [
"Take 10 deep breaths before responding",
"Count to 10 slowly in your mind",
"Step away from the situation if safely possible",
"Use the STOP technique: Stop, Take a breath, Observe, Proceed mindfully",
"Channel that energy into problem-solving",
"Remember your training and protocols"
],
"anxiety": [
"Use the 5-4-3-2-1 grounding technique",
"Focus on what you can control right now",
"Practice progressive muscle relaxation",
"Remind yourself of your training and capabilities",
"Take slow, controlled breaths",
"Connect with your support network"
],
"general": [
"Maintain regular meal times",
"Stay hydrated throughout your shift",
"Take brief mental breaks when possible",
"Practice good posture",
"Get adequate rest between shifts",
"Remember your important role in the community"
]
}
# =========================================================================
# LOGGING CONFIGURATION
# =========================================================================
# Logging Settings
LOG_LEVEL = logging.INFO
LOG_FORMAT = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
LOG_FILE = OUTPUT_DIR / "mindfull.log"
# =========================================================================
# ERROR HANDLING
# =========================================================================
# Retry Settings
MAX_RETRIES = 3
RETRY_DELAY = 1 # seconds
# Fallback Messages
FALLBACK_MESSAGES = {
"ollama_error": "I'm having trouble connecting right now. Please try again in a moment.",
"tts_error": "I'm having trouble with speech generation. Let me try a different approach.",
"avatar_error": "The video generation is temporarily unavailable, but I can still help you.",
"general_error": "I encountered an issue, but I'm here to help. Please try again."
}
@classmethod
def validate_paths(cls) -> bool:
"""Validate that all required paths exist"""
required_paths = [
cls.F5TTS_MODEL_PATH,
cls.F5TTS_CONFIG_PATH,
cls.DEFAULT_REFERENCE_AUDIO,
cls.DEFAULT_AVATAR_IMAGE
]
missing_paths = [path for path in required_paths if not path.exists()]
if missing_paths:
print(f"Warning: Missing required files: {missing_paths}")
return False
return True
@classmethod
def get_model_status(cls) -> Dict[str, bool]:
"""Check status of all models"""
return {
"f5tts_model": cls.F5TTS_MODEL_PATH.exists(),
"f5tts_config": cls.F5TTS_CONFIG_PATH.exists(),
"reference_audio": cls.DEFAULT_REFERENCE_AUDIO.exists(),
"avatar_image": cls.DEFAULT_AVATAR_IMAGE.exists(),
"sadtalker_script": cls.SADTALKER_SCRIPT.exists()
}
# Create global config instance
config = MindfullConfig()
# Configure logging
logging.basicConfig(
level=config.LOG_LEVEL,
format=config.LOG_FORMAT,
handlers=[
logging.FileHandler(config.LOG_FILE, encoding='utf-8'),
logging.StreamHandler()
]
)
logger = logging.getLogger(__name__)
if __name__ == "__main__":
print("Mindfull Configuration Status:")
print("=" * 50)
print(f"Project Root: {config.PROJECT_ROOT}")
print(f"Python Executable: {config.PYTHON_EXECUTABLE}")
print(f"Output Directory: {config.OUTPUT_DIR}")
print("\nModel Status:")
for model, status in config.get_model_status().items():
status_icon = "✅" if status else "❌"
print(f"{status_icon} {model}: {status}")
print(f"\nPath Validation: {'✅ Passed' if config.validate_paths() else '❌ Failed'}")
|