"""MrrrMe Backend - Utility Helper Functions""" import os import requests def get_avatar_api_url(): """Get correct avatar API URL based on environment""" # For Hugging Face Spaces, use same host if os.path.exists('/.dockerenv') or os.environ.get('SPACE_ID'): # Running in Docker/HF Spaces - use internal networking return "http://127.0.0.1:8765" else: # Local development return "http://localhost:8765" async def check_avatar_service(avatar_api: str): """Check if avatar TTS service is running""" try: response = requests.get(f"{avatar_api}/", timeout=2) if response.status_code == 200: print(f"[Backend] ✅ Avatar TTS service available at {avatar_api}") else: print(f"[Backend] ⚠️ Avatar TTS service responded with {response.status_code}") except requests.exceptions.ConnectionError: print(f"[Backend] ⚠️ Avatar TTS service NOT available at {avatar_api}") print(f"[Backend] 💡 Text-only mode will be used (no avatar speech)") print(f"[Backend] 📝 To enable avatar:") print(f"[Backend] cd avatar && python speak_server.py") except Exception as e: print(f"[Backend] ⚠️ Error checking avatar service: {e}")