Spaces:
Running
on
T4
Running
on
T4
Update app.py
Browse files
app.py
CHANGED
|
@@ -29,7 +29,7 @@ from botocore.client import Config
|
|
| 29 |
from io import BytesIO
|
| 30 |
from typing import Optional
|
| 31 |
import requests
|
| 32 |
-
|
| 33 |
# --------------------- Logging ---------------------
|
| 34 |
logging.basicConfig(level=logging.INFO)
|
| 35 |
logger = logging.getLogger(__name__)
|
|
@@ -59,9 +59,21 @@ from firebase_admin import credentials, auth
|
|
| 59 |
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
|
| 60 |
|
| 61 |
if not firebase_admin._apps:
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
firebase_admin.initialize_app(cred)
|
| 64 |
-
logger.info("✅ Firebase initialized successfully")
|
| 65 |
|
| 66 |
security = HTTPBearer()
|
| 67 |
|
|
|
|
| 29 |
from io import BytesIO
|
| 30 |
from typing import Optional
|
| 31 |
import requests
|
| 32 |
+
import json
|
| 33 |
# --------------------- Logging ---------------------
|
| 34 |
logging.basicConfig(level=logging.INFO)
|
| 35 |
logger = logging.getLogger(__name__)
|
|
|
|
| 59 |
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
|
| 60 |
|
| 61 |
if not firebase_admin._apps:
|
| 62 |
+
FIREBASE_CREDENTIALS = os.getenv("FIREBASE_CREDENTIALS_PATH")
|
| 63 |
+
if not FIREBASE_CREDENTIALS:
|
| 64 |
+
raise RuntimeError("❌ FIREBASE_CREDENTIALS_PATH not set in environment variables")
|
| 65 |
+
|
| 66 |
+
try:
|
| 67 |
+
# Try parsing as JSON string
|
| 68 |
+
cred_dict = json.loads(FIREBASE_CREDENTIALS)
|
| 69 |
+
cred = credentials.Certificate(cred_dict)
|
| 70 |
+
logger.info("✅ Firebase initialized from JSON string in environment variable")
|
| 71 |
+
except json.JSONDecodeError:
|
| 72 |
+
# Fallback: assume it's a file path
|
| 73 |
+
cred = credentials.Certificate(FIREBASE_CREDENTIALS)
|
| 74 |
+
logger.info("✅ Firebase initialized from JSON file path")
|
| 75 |
+
|
| 76 |
firebase_admin.initialize_app(cred)
|
|
|
|
| 77 |
|
| 78 |
security = HTTPBearer()
|
| 79 |
|