import os | |
import json | |
import firebase_admin | |
from firebase_admin import credentials, firestore | |
# Get the Firebase credentials from environment variable | |
firebase_creds = os.environ.get('firebase_creds') | |
if not firebase_creds: | |
raise ValueError("β ERROR: The environment variable 'firebase_creds' is NOT set. Please set it in Hugging Face Secrets.") | |
# Convert the JSON string back into a dictionary | |
firebase_config = json.loads(firebase_creds) | |
# Initialize Firebase with the credentials | |
cred = credentials.Certificate(firebase_config) | |
firebase_admin.initialize_app(cred) | |
db = firestore.client() | |
print("β Firebase initialized successfully!") | |