Update app.py
Browse files
app.py
CHANGED
|
@@ -25,25 +25,20 @@ from reportlab.lib import colors
|
|
| 25 |
# Authenticate Earth Engine (HF Secrets)
|
| 26 |
# ---------------------------
|
| 27 |
# ---------------------------
|
| 28 |
-
# Authenticate Earth Engine (HF Secrets)
|
| 29 |
# ---------------------------
|
| 30 |
-
import
|
| 31 |
|
| 32 |
-
service_account = os.environ.get("EE_SERVICE_ACCOUNT") #
|
| 33 |
-
key_json = os.environ.get("EE_PRIVATE_KEY") #
|
| 34 |
|
| 35 |
if service_account and key_json:
|
| 36 |
-
#
|
| 37 |
-
|
| 38 |
-
f.write(key_json)
|
| 39 |
-
temp_key_path = f.name
|
| 40 |
-
|
| 41 |
-
# Authenticate with EE
|
| 42 |
-
creds = ee.ServiceAccountCredentials(service_account, temp_key_path)
|
| 43 |
ee.Initialize(creds)
|
| 44 |
else:
|
| 45 |
raise RuntimeError("Earth Engine authentication failed. Did you set HF secrets?")
|
| 46 |
-
|
| 47 |
# Helper Functions
|
| 48 |
# ---------------------------
|
| 49 |
def _fmt_pct(x):
|
|
|
|
| 25 |
# Authenticate Earth Engine (HF Secrets)
|
| 26 |
# ---------------------------
|
| 27 |
# ---------------------------
|
| 28 |
+
# Authenticate Earth Engine (with HF Secrets)
|
| 29 |
# ---------------------------
|
| 30 |
+
import ee, os, json
|
| 31 |
|
| 32 |
+
service_account = os.environ.get("EE_SERVICE_ACCOUNT") # service account email
|
| 33 |
+
key_json = os.environ.get("EE_PRIVATE_KEY") # should be one-line JSON
|
| 34 |
|
| 35 |
if service_account and key_json:
|
| 36 |
+
key_dict = json.loads(key_json) # 👈 this only works if EE_PRIVATE_KEY is compact JSON (no line breaks)
|
| 37 |
+
creds = ee.ServiceAccountCredentials(service_account, key_dict)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
ee.Initialize(creds)
|
| 39 |
else:
|
| 40 |
raise RuntimeError("Earth Engine authentication failed. Did you set HF secrets?")
|
| 41 |
+
|
| 42 |
# Helper Functions
|
| 43 |
# ---------------------------
|
| 44 |
def _fmt_pct(x):
|