ARQ-RAG / shared /supabase_client.py
neshaki091
add backendhug
0451cfe
raw
history blame contribute delete
868 Bytes
import os
from supabase import create_client, Client
class SupabaseManager:
def __init__(self):
url = os.getenv("SUPABASE_URL")
key = os.getenv("SUPABASE_SERVICE_ROLE_KEY")
if not url or not key:
raise Exception("Thiếu cấu hình Supabase trên Hugging Face!")
self.client = create_client(url, key)
def download_weights(self, local_path="data/model_weights.pkl"):
"""Tải chìa khóa từ Supabase Storage về Hugging Face Space."""
os.makedirs(os.path.dirname(local_path), exist_ok=True)
try:
res = self.client.storage.from_("models").download("model_weights.pkl")
with open(local_path, "wb") as f:
f.write(res)
return True
except Exception as e:
print(f"Lỗi tải trọng số: {e}")
return False