Spaces:
Sleeping
Sleeping
Merge pull request #19 from mapaction/develop
Browse files
app/pages/1_π_Flood_extent_analysis.py
CHANGED
@@ -36,7 +36,7 @@ st.markdown("# Flood extent analysis")
|
|
36 |
set_tool_page_style()
|
37 |
|
38 |
# Initialise Google Earth Engine
|
39 |
-
ee_initialize()
|
40 |
|
41 |
|
42 |
# Output_created is useful to decide whether the bottom panel with the
|
|
|
36 |
set_tool_page_style()
|
37 |
|
38 |
# Initialise Google Earth Engine
|
39 |
+
ee_initialize(force_use_service_account=True)
|
40 |
|
41 |
|
42 |
# Output_created is useful to decide whether the bottom panel with the
|
app/src/utils_ee.py
CHANGED
@@ -7,9 +7,24 @@ from src.utils import is_app_on_streamlit
|
|
7 |
|
8 |
|
9 |
@st.experimental_memo
|
10 |
-
def ee_initialize():
|
11 |
-
"""Initialise Google Earth Engine.
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
service_account_keys = st.secrets["ee_keys"]
|
14 |
credentials = service_account.Credentials.from_service_account_info(
|
15 |
service_account_keys, scopes=oauth.SCOPES
|
|
|
7 |
|
8 |
|
9 |
@st.experimental_memo
|
10 |
+
def ee_initialize(force_use_service_account: bool = False):
|
11 |
+
"""Initialise Google Earth Engine.
|
12 |
+
|
13 |
+
Checks whether the app is deployed on Streamlit Cloud and, based on the
|
14 |
+
result, initialises Google Earth Engine in different ways: if the app is
|
15 |
+
run locally, the credentials are retrieved from the user's credentials
|
16 |
+
stored in the local system (personal Google account is used). If the app
|
17 |
+
is deployed on Streamlit Cloud, credentials are taken from the secrets
|
18 |
+
field in the cloud (a dedicated service account is used).
|
19 |
+
Inputs:
|
20 |
+
force_use_service_account (bool): If True, the dedicated Google
|
21 |
+
service account is used, regardless of whether the app is run
|
22 |
+
locally or in the cloud.
|
23 |
+
|
24 |
+
Returns:
|
25 |
+
None
|
26 |
+
"""
|
27 |
+
if force_use_service_account or is_app_on_streamlit():
|
28 |
service_account_keys = st.secrets["ee_keys"]
|
29 |
credentials = service_account.Credentials.from_service_account_info(
|
30 |
service_account_keys, scopes=oauth.SCOPES
|