Update app.py
Browse files
app.py
CHANGED
|
@@ -27,18 +27,22 @@ from reportlab.lib import colors
|
|
| 27 |
# ---------------------------
|
| 28 |
# Authenticate Earth Engine (with HF Secrets)
|
| 29 |
# ---------------------------
|
| 30 |
-
import ee, os,
|
| 31 |
|
| 32 |
service_account = os.environ.get("EE_SERVICE_ACCOUNT") # service account email
|
| 33 |
-
key_json = os.environ.get("EE_PRIVATE_KEY") #
|
| 34 |
|
| 35 |
if service_account and key_json:
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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):
|
|
|
|
| 27 |
# ---------------------------
|
| 28 |
# Authenticate Earth Engine (with HF Secrets)
|
| 29 |
# ---------------------------
|
| 30 |
+
import ee, os, tempfile
|
| 31 |
|
| 32 |
service_account = os.environ.get("EE_SERVICE_ACCOUNT") # service account email
|
| 33 |
+
key_json = os.environ.get("EE_PRIVATE_KEY") # the JSON text as stored in HF Secrets
|
| 34 |
|
| 35 |
if service_account and key_json:
|
| 36 |
+
# Write the JSON string to a temporary file
|
| 37 |
+
with tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False) as f:
|
| 38 |
+
f.write(key_json)
|
| 39 |
+
temp_key_path = f.name
|
| 40 |
+
|
| 41 |
+
# Authenticate using the file path
|
| 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 |
# Helper Functions
|
| 47 |
# ---------------------------
|
| 48 |
def _fmt_pct(x):
|