Skip to content

Commit 08210b8

Browse files
committed
feat: mesop cloudrun gemini app
1 parent d2d888b commit 08210b8

File tree

6 files changed

+1827
-0
lines changed

6 files changed

+1827
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: gunicorn --bind :8080 main:me
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Cloud Run application utilizing Mesop that demonstrates working with Vertex AI Gemini API
2+
3+
| | |
4+
| --------- | ---------------------------------------------- |
5+
| Author(s) | [Hussain Chinoy](https://github.com/ghchinoy) |
6+
7+
This application demonstrates a Cloud Run application that uses the [Mesop](https://github.com/google/mesop) UI framework.
8+
9+
Sample screenshots and video demos of the application are shown below:
10+
11+
## Application screenshots
12+
13+
![image playground](images/imageplayground.png)
14+
15+
## Run the Application locally (on Cloud Shell)
16+
17+
> NOTE: **Before you move forward, ensure that you have followed the instructions in [SETUP.md](../SETUP.md).**
18+
> Additionally, ensure that you have cloned this repository and you are currently in the `gemini-mesop-cloudrun` folder. This should be your active working directory for the rest of the commands.
19+
20+
To run the Mesop application locally (on cloud shell), we need to perform the following steps:
21+
22+
1. Setup the Python virtual environment and install the dependencies:
23+
24+
In Cloud Shell, execute the following commands:
25+
26+
```bash
27+
python3 -m venv gemini-mesop
28+
. gemini-mesop/bin/activate
29+
pip install -r requirements.txt
30+
```
31+
32+
2. Your application requires access to two environment variables:
33+
34+
- `GOOGLE_CLOUD_PROJECT` : This the Google Cloud project ID.
35+
- `GOOGLE_CLOUD_REGION` : This is the region in which you are deploying your Cloud Run app. For e.g. us-central1.
36+
37+
These variables are needed since the Vertex AI initialization needs the Google Cloud project ID and the region. The specific code line from the `main.py`
38+
function is shown here:
39+
`vertexai.init(project=PROJECT_ID, location=LOCATION)`
40+
41+
In Cloud Shell, execute the following commands:
42+
43+
```bash
44+
export GOOGLE_CLOUD_PROJECT=$(gcloud config get project) # this will populate your current project ID
45+
export GOOGLE_CLOUD_REGION='us-central1' # If you change this, make sure the region is supported.
46+
```
47+
48+
3. To run the application locally, execute the following command:
49+
50+
In Cloud Shell, execute the following command:
51+
52+
```bash
53+
mesop --port 8080 main.py
54+
```
55+
56+
The application will startup and you will be provided a URL to the application. Use Cloud Shell's [web preview](https://cloud.google.com/shell/docs/using-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.
57+
58+
## Build and Deploy the Application to Cloud Run
59+
60+
To deploy the Mesop Application in [Cloud Run](https://cloud.google.com/run/docs/quickstarts/deploy-container), we need to perform the following steps:
61+
62+
1. Your Cloud Run app requires access to two environment variables:
63+
64+
- `GOOGLE_CLOUD_PROJECT` : This the Google Cloud project ID.
65+
- `GOOGLE_CLOUD_REGION` : This is the region in which you are deploying your Cloud Run app. For e.g. us-central1.
66+
67+
These variables are needed since the Vertex AI initialization needs the Google Cloud project ID and the region. The specific code line from the `main.py`
68+
function is shown here:
69+
`vertexai.init(project=PROJECT_ID, location=LOCATION)`
70+
71+
In Cloud Shell, execute the following commands:
72+
73+
```bash
74+
export GOOGLE_CLOUD_PROJECT=$(gcloud config get project) # Use this or manually change this
75+
export GOOGLE_CLOUD_REGION='us-central1' # If you change this, make sure the region is supported.
76+
```
77+
78+
2. Build and deploy the service to Cloud Run:
79+
80+
In Cloud Shell, execute the following command to name the Cloud Run service:
81+
82+
```bash
83+
export SERVICE_NAME='mesop-gemini' # this is the name of our Application and Cloud Run service. Change this if you'd like to.
84+
```
85+
86+
87+
In Cloud Shell, execute the following command:
88+
89+
```bash
90+
gcloud run deploy $SERVICE_NAME \
91+
--source . \
92+
--port=8080 --allow-unauthenticated \
93+
--project=$GOOGLE_CLOUD_PROJECT --region=$GOOGLE_CLOUD_REGION \
94+
--set-env-vars=GOOGLE_CLOUD_PROJECT=$GOOGLE_CLOUD_PROJECT \
95+
--set-env-vars=GOOGLE_CLOUD_REGION=$GOOGLE_CLOUD_REGION
96+
```
97+
98+
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.
99+
100+
Congratulations!
Loading

0 commit comments

Comments
 (0)