pgzmnk commited on
Commit
7a95d7a
1 Parent(s): 8b27e73

Update gee login to use env var.

Browse files
Files changed (2) hide show
  1. README.md +1 -1
  2. app.py +10 -4
README.md CHANGED
@@ -1,6 +1,6 @@
1
  ---
2
  title: Bioscore calculator
3
- emoji: {{emoji}}
4
  colorFrom: indigo
5
  colorTo: pink
6
  sdk: gradio
 
1
  ---
2
  title: Bioscore calculator
3
+ emoji: 🌳
4
  colorFrom: indigo
5
  colorTo: pink
6
  sdk: gradio
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import datetime
 
2
  import logging
3
  import os
4
 
@@ -8,9 +9,10 @@ import gradio as gr
8
  import pandas as pd
9
  import plotly.graph_objects as go
10
  import yaml
 
11
 
12
  # Logging
13
- logging.basicConfig(format="%(levelname)s:%(message)s", level=logging.DEBUG)
14
 
15
  # Define constants
16
  DATE = "2020-01-01"
@@ -198,10 +200,12 @@ def set_up_duckdb():
198
 
199
 
200
  def authenticate_gee(gee_service_account, gee_service_account_credentials_file):
 
 
 
201
  logging.info("authenticate_gee")
202
- # to-do: alert if dataset filter date nan
203
  credentials = ee.ServiceAccountCredentials(
204
- gee_service_account, gee_service_account_credentials_file
205
  )
206
  ee.Initialize(credentials)
207
 
@@ -314,8 +318,10 @@ def push_to_md():
314
 
315
 
316
  with gr.Blocks() as demo:
317
- con = set_up_duckdb()
318
  authenticate_gee(GEE_SERVICE_ACCOUNT, GEE_SERVICE_ACCOUNT_CREDENTIALS_FILE)
 
 
319
  # Create circle buffer over point
320
  roi = ee.Geometry.Point(*LOCATION).buffer(ROI_RADIUS)
321
 
 
1
  import datetime
2
+ import json
3
  import logging
4
  import os
5
 
 
9
  import pandas as pd
10
  import plotly.graph_objects as go
11
  import yaml
12
+ from google.oauth2 import service_account
13
 
14
  # Logging
15
+ logging.basicConfig(format="%(levelname)s:%(message)s", level=logging.INFO)
16
 
17
  # Define constants
18
  DATE = "2020-01-01"
 
200
 
201
 
202
  def authenticate_gee(gee_service_account, gee_service_account_credentials_file):
203
+ """
204
+ Huggingface Spaces does not support secret files, therefore authenticate with an environment variable containing the JSON.
205
+ """
206
  logging.info("authenticate_gee")
 
207
  credentials = ee.ServiceAccountCredentials(
208
+ gee_service_account, key_data=os.environ["ee_service_account"]
209
  )
210
  ee.Initialize(credentials)
211
 
 
318
 
319
 
320
  with gr.Blocks() as demo:
321
+ # Environment setup
322
  authenticate_gee(GEE_SERVICE_ACCOUNT, GEE_SERVICE_ACCOUNT_CREDENTIALS_FILE)
323
+ con = set_up_duckdb()
324
+
325
  # Create circle buffer over point
326
  roi = ee.Geometry.Point(*LOCATION).buffer(ROI_RADIUS)
327