""" 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'}")