MSU576 commited on
Commit
6eb1af3
·
verified ·
1 Parent(s): 2fb3b69

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -12
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 tempfile
31
 
32
- service_account = os.environ.get("EE_SERVICE_ACCOUNT") # e.g. [email protected]
33
- key_json = os.environ.get("EE_PRIVATE_KEY") # full JSON with { } and newlines
34
 
35
  if service_account and key_json:
36
- # Save the secret JSON into 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 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):