# database.py """ Supabase database client """ from supabase import create_client, Client import os # Supabase credentials (set in Hugging Face Spaces secrets) SUPABASE_URL = os.getenv("SUPABASE_URL", "https://xxxxx.supabase.co") SUPABASE_KEY = os.getenv("SUPABASE_KEY", "your-anon-key-here") # Global Supabase client supabase_client: Client = None def init_supabase(): """Initialize Supabase client""" global supabase_client try: supabase_client = create_client(SUPABASE_URL, SUPABASE_KEY) print("✅ Supabase connected successfully") return supabase_client except Exception as e: print(f"❌ Supabase connection failed: {e}") return None def get_supabase() -> Client: """Get Supabase client instance""" global supabase_client if supabase_client is None: supabase_client = init_supabase() return supabase_client