File size: 1,279 Bytes
10fba92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""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}")