-
Clone/upload this folder (
gemini-streamlit-demo
) to Cloud Shell, or use Cloud Shell Editor. The important files are:app.py
requirements.txt
Dockerfile
-
Setup the Python virtual environment:
In Cloud Shell, execute the following commands:
python3 -m venv gemini-streamlit-env source gemini-streamlit-env/bin/activate pip install -r requirements.txt
-
Setup environment variables:
In Cloud Shell, execute the following commands:
export GCP_PROJECT=[PROJECT_ID] export GCP_REGION='us-central1'
-
To run the application locally, execute the following command:
In Cloud Shell, execute the following command:
streamlit run app.py \ --browser.serverAddress=localhost \ --server.enableCORS=false \ --server.enableXsrfProtection=false \ --server.port 8080
-
View the output at http://localhost:8080
-
Setup environment variables:
In Cloud Shell, execute the following commands:
export GCP_PROJECT=[PROJECT_ID] export GCP_REGION='us-central1'
-
Build the Docker image for the application and push it to Artifact Registry
In Cloud Shell, execute the following commands:
export AR_REPO='gemini-streamlit-repo' # Dashes, no underscores export SERVICE_NAME='gemini-streamlit-demo' # Dashes, no underscores #make sure you are in the active directory for 'gemini-streamlit-demo' gcloud artifacts repositories create "$AR_REPO" --location="$GCP_REGION" --repository-format=Docker gcloud builds submit --tag "$GCP_REGION-docker.pkg.dev/$GCP_PROJECT/$AR_REPO/$SERVICE_NAME"
-
Deploy the service in Cloud Run with the image that we had built and had pushed to the Artifact Registry in the previous step:
In Cloud Shell, execute the following command:
gcloud run deploy "$SERVICE_NAME" \ --port=8080 \ --image="$GCP_REGION-docker.pkg.dev/$GCP_PROJECT/$AR_REPO/$SERVICE_NAME" \ --allow-unauthenticated \ --region=$GCP_REGION \ --platform=managed \ --project=$GCP_PROJECT \ --set-env-vars=GCP_PROJECT=$GCP_PROJECT,GCP_REGION=$GCP_REGION