Skip to content

Commit 5a9126a

Browse files
feat: add Gradio sample
1 parent fcb0005 commit 5a9126a

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

run/helloworld-gradio/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Cloud Run Hello World Gradio Sample
2+
3+
This sample shows how to deploy a Hello World Gradio application to Cloud Run.
4+
5+
[![Run in Google Cloud][run_img]][run_link]
6+
7+
[run_img]: https://storage.googleapis.com/cloudrun/button.svg
8+
[run_link]: https://console.cloud.google.com/cloudshell/editor?shellonly=true&cloudshell_image=gcr.io/cloudrun/button&cloudshell_git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&cloudshell_working_dir=run/helloworld-gradio
9+
10+
## Deploy
11+
12+
```sh
13+
# Ensure you have set your Google Cloud Project ID
14+
gcloud config set project <PROJECT_ID>
15+
16+
# Deploy to Cloud Run
17+
gcloud run deploy helloworld-gradio --source .
18+
```
19+
20+
For more details on how to work with this sample, read the [Python Cloud Run Samples README](https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/run)

run/helloworld-gradio/main.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# [START cloudrun_helloworld_gradio]
16+
import gradio as gr
17+
18+
def hello(name, intensity):
19+
"""Return a friendly greeting."""
20+
return "Hello " + name + "!" * int(intensity)
21+
22+
demo = gr.Interface(
23+
fn=hello,
24+
inputs=["text", "slider"],
25+
outputs=["text"],
26+
title="Hello World 👋🌎",
27+
description=("Type your name below and hit 'Submit', and try the slider to "
28+
"make the greeting louder!"),
29+
theme="soft",
30+
flagging_mode="never",
31+
)
32+
33+
demo.launch()
34+
# [END cloudrun_helloworld_gradio]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
gradio==5.39.0

0 commit comments

Comments
 (0)