mike23415 commited on
Commit
e26c947
·
verified ·
1 Parent(s): ed59ef2

Create database.py

Browse files
Files changed (1) hide show
  1. database.py +28 -0
database.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ from supabase import create_client, Client
3
+ import os
4
+
5
+ # Supabase credentials (set in Hugging Face Spaces secrets)
6
+ SUPABASE_URL = os.getenv("SUPABASE_URL", "https://xxxxx.supabase.co")
7
+ SUPABASE_KEY = os.getenv("SUPABASE_KEY", "your-anon-key-here")
8
+
9
+ # Global Supabase client
10
+ supabase_client: Client = None
11
+
12
+ def init_supabase():
13
+ """Initialize Supabase client"""
14
+ global supabase_client
15
+ try:
16
+ supabase_client = create_client(SUPABASE_URL, SUPABASE_KEY)
17
+ print("✅ Supabase connected successfully")
18
+ return supabase_client
19
+ except Exception as e:
20
+ print(f"❌ Supabase connection failed: {e}")
21
+ return None
22
+
23
+ def get_supabase() -> Client:
24
+ """Get Supabase client instance"""
25
+ global supabase_client
26
+ if supabase_client is None:
27
+ supabase_client = init_supabase()
28
+ return supabase_client