GithubHelp home page GithubHelp logo

gemini-furniture-rec-cloud's Introduction

Cloud Run application utilizing Streamlit Framework that demonstrates working with Vertex AI Gemini API

https://github.com/GoogleCloudPlatform/generative-ai/tree/main/gemini/sample-apps/gemini-streamlit-cloudrun

Author(s) Lavi Nigam

This application demonstrates a Cloud Run application that uses the Streamlit framework.

Sample screenshots and video demos of the application are shown below:

Application screenshots

Run the Application locally (on Cloud Shell)

NOTE: Before you move forward, ensure that you have followed the instructions in SETUP.md. Additionally, ensure that you have cloned this repository and you are currently in the gemini-streamlit-cloudrun folder. This should be your active working directory for the rest of the commands.

To run the Streamlit Application locally (on cloud shell), we need to perform the following steps:

  1. Setup the Python virtual environment and install the dependencies:

    In Cloud Shell, execute the following commands:

    python3 -m venv gemini-streamlit
    source gemini-streamlit/bin/activate
    pip install -r requirements.txt
  2. Your application requires access to two environment variables:

    • GCP_PROJECT : This the Google Cloud project ID.
    • GCP_REGION : This is the region in which you are deploying your Cloud Run app. For e.g. us-central1.

    These variables are needed since the Vertex AI initialization needs the Google Cloud project ID and the region. The specific code line from the app.py function is shown here: vertexai.init(project=PROJECT_ID, location=LOCATION)

    In Cloud Shell, execute the following commands:

    export GCP_PROJECT='wpok-399501'  # Change this
    export GCP_REGION='us-central1'             # If you change this, make sure the region is supported.
  3. 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

The application will startup and you will be provided a URL to the application. Use Cloud Shell's web preview function to launch the preview page. You may also visit that in the browser to view the application. Choose the functionality that you would like to check out and the application will prompt the Vertex AI Gemini API and display the responses.

Build and Deploy the Application to Cloud Run

NOTE: Before you move forward, ensure that you have followed the instructions in SETUP.md. Additionally, ensure that you have cloned this repository and you are currently in the gemini-streamlit-cloudrun folder. This should be your active working directory for the rest of the commands.

To deploy the Streamlit Application in Cloud Run, we need to perform the following steps:

  1. Your Cloud Run app requires access to two environment variables:

    • GCP_PROJECT : This the Google Cloud project ID.
    • GCP_REGION : This is the region in which you are deploying your Cloud Run app. For e.g. us-central1.

    These variables are needed since the Vertex AI initialization needs the Google Cloud project ID and the region. The specific code line from the app.py function is shown here: vertexai.init(project=PROJECT_ID, location=LOCATION)

    In Cloud Shell, execute the following commands:

    export GCP_PROJECT='wpok-399501'  # Change this
    export GCP_REGION='us-central1'             # If you change this, make sure the region is supported.
  2. Now you can build the Docker image for the application and push it to Artifact Registry. To do this, you will need one environment variable set that will point to the Artifact Registry name. Included in the script below is a command that will create this Artifact Registry repository for you.

    In Cloud Shell, execute the following commands:

    export AR_REPO='gemini-furniture-rec'  # Change this
    export SERVICE_NAME='gemini-furniture-rec' # This is the name of our Application and Cloud Run service. Change it if you'd like. 
    
    #make sure you are in the active directory for 'gemini-furniture-rec'
    gcloud artifacts repositories create "$AR_REPO" --location="$GCP_REGION" --repository-format=Docker
    gcloud auth configure-docker "$GCP_REGION-docker.pkg.dev"
    gcloud builds submit --tag "$GCP_REGION-docker.pkg.dev/$GCP_PROJECT/$AR_REPO/$SERVICE_NAME"
  3. The final step is to 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

On successful deployment, you will be provided a URL to the Cloud Run service. You can visit that in the browser to view the Cloud Run application that you just deployed. Choose the functionality that you would like to check out and the application will prompt the Vertex AI Gemini API and display the responses.

Congratulations!

gemini-furniture-rec-cloud's People

Contributors

wpok-google avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.