opengeos / solara-geospatial

A collection of solara web apps for geospatial applications
https://giswqs-solara-geospatial.hf.space
MIT License
120 stars 21 forks source link

How to authenticate GEE for Solara/geemap app on Hugging Face #5

Closed gregorhd closed 5 months ago

gregorhd commented 5 months ago

Thanks for your excellent tutorial on integrating Solara and Hugging Face.

If I were to not duplicate your repo but start out from scratch, what's the proper way to make sure a Solara/Geemap script on the HF Docker image is authenticated properly with GEE? I have my EARTHENGINE_TOKEN saved as a Spaces secret and use the same Dockerfile as you.

I noticed none of your scripts under /pages/ uses ee.Authenticate() or ee.Initialise(), so I didn't as well, yet when I push my Solara/Geemap script (which runs fine locally) to Hugging Face and the script is run after Builtime, I get:

ee.ee_exception.EEException: Earth Engine client library not initialized. Runee.Initialize()``

2) So I add ee.Initialize() to the script, git pushagain, and get:

ee.ee_exception.EEException: Please authorize access to your Earth Engine account by running

earthengine authenticate 

in your command line, or ee.Authenticate() in Python, and then retry.

3) When I then add ee.Authenticate() I get:

Exception: gcloud command not found.

...which then makes me think I need to install the gcloud CLI on the image (managed that as well but more issues...).

This all makes me think, there's something simple I'm missing here. I tried duplicating your repo initially, but was also asked to ee.Initialize(ee) etc. after adding my own script to /pages/.

Thanks!

giswqs commented 5 months ago

Use geemap.ee_initialize() for or geemap.Map(), which can read the EARTHENGINE_TOKEN from the environment variable and authenticate EE. Never use ee.Authenticate() in the web app.

gregorhd commented 5 months ago

Beautiful! That was it. Thanks so much!