mirror of
https://github.com/GoogleCloudPlatform/vertex-ai-samples.git
synced 2026-09-26 14:42:04 +00:00
Update Gradio notebook to use the latest Gradio version and fix some bugs. (#2958)
* Add controlnet-canny to the Gradio playground, and some additional UX enhancement. * Minor fixes. * Minor fixes * Add additional document regarding the list of supported models, and some UI enhancement. * Minor update to the hyperlink. * Rewrite the SD2.1 dreambooth finetune notebook. * Add code owners. * Some minor changes to the stable diffusion 2.1 and sd-xl notebooks. * some additional minor fixes. * additional fixes. * Create a notebook to demonstrate dreambooth LoRA finetune for SD-XL model. * minor updates * add to the codeowner list. * merge conflict. * minor fix to the Gradio UI workshop notebook. * Some minor updates to the SD2.1 deployment notebook. * Minor update the `sd-xl` deployment notebook, based on the QA feedback. * Add a few community models to the Gradio workshop. * Switch `mediapipe-train` docker container from `vertex-ai-restricted` to `vertex-ai`, in the `mediapipe-train` notebooks. * Create a notebook for model `instantx/instantid`. * Update Gradio notebook to use the latest Gradio version and fix some bugs. 1. Update Gradio version to 4.29.0, as it complains 3.50.0 is too old. 2. Uninstall nest-asyncio and uvloop as a workaround to b/339301920 and https://github.com/gradio-app/gradio/issues/8238#issuecomment-2101066984. * Resolve merge conflict. * minor updates. * minor updates.
This commit is contained in:
+41
-21
@@ -99,7 +99,9 @@
|
||||
"# @markdown not considered a match for a single region covered by the multi-region range (eg. \"us-central1\").\n",
|
||||
"# @markdown If not set, a unique GCS bucket will be created instead.\n",
|
||||
"\n",
|
||||
"! pip3 install --upgrade gradio==3.50.0 opencv-python\n",
|
||||
"! pip3 install --upgrade gradio==4.29.0 opencv-python\n",
|
||||
"# Uninstall nest-asyncio and uvloop as a workaround to https://github.com/gradio-app/gradio/issues/8238#issuecomment-2101066984\n",
|
||||
"! pip3 uninstall --yes nest-asyncio uvloop\n",
|
||||
"\n",
|
||||
"import os\n",
|
||||
"from datetime import datetime\n",
|
||||
@@ -233,7 +235,7 @@
|
||||
"import gradio as gr\n",
|
||||
"import numpy as np\n",
|
||||
"from google.cloud import aiplatform, storage\n",
|
||||
"from PIL import Image\n",
|
||||
"from PIL import Image, ImageOps\n",
|
||||
"\n",
|
||||
"style_list = [\n",
|
||||
" {\n",
|
||||
@@ -458,7 +460,7 @@
|
||||
" serving_env = {\n",
|
||||
" \"MODEL_ID\": deploy_model_id,\n",
|
||||
" \"TASK\": task_name,\n",
|
||||
" \"DEPLOY_SOURCE\": \"notebook\",\n",
|
||||
" \"DEPLOY_SOURCE\": \"notebook_gradio\",\n",
|
||||
" }\n",
|
||||
" if model_id == \"stabilityai/stable-diffusion-xl-base-1.0 - refiner\":\n",
|
||||
" serving_env = {\n",
|
||||
@@ -502,7 +504,11 @@
|
||||
" return dimension\n",
|
||||
"\n",
|
||||
" model_name = model_name.lower()\n",
|
||||
" if \"stable-diffusion-xl\" in model_name or \"xl\" in model_name:\n",
|
||||
" if (\n",
|
||||
" \"stable-diffusion-xl\" in model_name\n",
|
||||
" or \"xl\" in model_name\n",
|
||||
" or \"lightning\" in model_name\n",
|
||||
" ):\n",
|
||||
" dimension = 1024\n",
|
||||
" if \"stable-diffusion-2-1\" in model_name:\n",
|
||||
" dimension = 768\n",
|
||||
@@ -532,7 +538,7 @@
|
||||
" if \"dreamshaper-xl-v2-turbo\" in model_name:\n",
|
||||
" guidance_scale = 2\n",
|
||||
"\n",
|
||||
" if \"lightning\" or \"turbovision_xl\" in model_name:\n",
|
||||
" if \"lightning\" in model_name or \"turbovision_xl\" in model_name:\n",
|
||||
" guidance_scale = 1.5\n",
|
||||
"\n",
|
||||
" return guidance_scale\n",
|
||||
@@ -624,9 +630,15 @@
|
||||
" default_dimension = 1024\n",
|
||||
"\n",
|
||||
" init_image = (\n",
|
||||
" dict[\"image\"].convert(\"RGB\").resize((default_dimension, default_dimension))\n",
|
||||
" dict[\"background\"]\n",
|
||||
" .convert(mode=\"RGB\")\n",
|
||||
" .resize((default_dimension, default_dimension))\n",
|
||||
" )\n",
|
||||
" mask = dict[\"mask\"].convert(\"RGB\").resize((default_dimension, default_dimension))\n",
|
||||
" # Replace the transparent pixels with white. Required in rgba -> rgb conversion.\n",
|
||||
" mask_rgba = np.array(dict[\"layers\"][0])\n",
|
||||
" mask_rgba[mask_rgba[..., -1] == 0] = [255, 255, 255, 0]\n",
|
||||
" mask = Image.fromarray(mask_rgba).convert(mode=\"L\")\n",
|
||||
" mask = ImageOps.invert(mask).resize((default_dimension, default_dimension))\n",
|
||||
"\n",
|
||||
" instances = [\n",
|
||||
" {\n",
|
||||
@@ -784,6 +796,7 @@
|
||||
" if interface_name == \"Text2Image\":\n",
|
||||
" return {\n",
|
||||
" image_input: gr.update(visible=False, value=None, label=\"Upload\"),\n",
|
||||
" inpainting_input: gr.update(visible=False),\n",
|
||||
" image_output: gr.update(value=None),\n",
|
||||
" generate_button: gr.update(visible=True),\n",
|
||||
" inpaint_generate_button: gr.update(visible=False),\n",
|
||||
@@ -796,9 +809,8 @@
|
||||
"\n",
|
||||
" elif interface_name == \"Inpainting\":\n",
|
||||
" return {\n",
|
||||
" image_input: gr.update(\n",
|
||||
" visible=True, value=None, tool=\"sketch\", label=\"Upload\"\n",
|
||||
" ),\n",
|
||||
" image_input: gr.update(visible=False),\n",
|
||||
" inpainting_input: gr.update(visible=True, value=None, label=\"Upload\"),\n",
|
||||
" image_output: gr.update(value=None),\n",
|
||||
" generate_button: gr.update(visible=False),\n",
|
||||
" inpaint_generate_button: gr.update(visible=True),\n",
|
||||
@@ -811,9 +823,8 @@
|
||||
"\n",
|
||||
" elif interface_name == \"Instruct pix2pix\":\n",
|
||||
" return {\n",
|
||||
" image_input: gr.update(\n",
|
||||
" visible=True, value=None, tool=\"None\", label=\"Upload\"\n",
|
||||
" ),\n",
|
||||
" image_input: gr.update(visible=True, value=None, label=\"Upload\"),\n",
|
||||
" inpainting_input: gr.update(visible=False),\n",
|
||||
" image_output: gr.update(value=None),\n",
|
||||
" generate_button: gr.update(visible=False),\n",
|
||||
" inpaint_generate_button: gr.update(visible=False),\n",
|
||||
@@ -829,9 +840,9 @@
|
||||
" image_input: gr.update(\n",
|
||||
" visible=True,\n",
|
||||
" value=None,\n",
|
||||
" tool=\"None\",\n",
|
||||
" label=\"Upload a reference image\",\n",
|
||||
" ),\n",
|
||||
" inpainting_input: gr.update(visible=False),\n",
|
||||
" image_output: gr.update(value=None),\n",
|
||||
" generate_button: gr.update(visible=False),\n",
|
||||
" inpaint_generate_button: gr.update(visible=False),\n",
|
||||
@@ -844,9 +855,8 @@
|
||||
"\n",
|
||||
" elif interface_name == \"SD 4x Upscaler\":\n",
|
||||
" return {\n",
|
||||
" image_input: gr.update(\n",
|
||||
" visible=True, value=None, tool=\"None\", label=\"Upload\"\n",
|
||||
" ),\n",
|
||||
" image_input: gr.update(visible=True, value=None, label=\"Upload\"),\n",
|
||||
" inpainting_input: gr.update(visible=False),\n",
|
||||
" image_output: gr.update(value=None),\n",
|
||||
" generate_button: gr.update(visible=False),\n",
|
||||
" inpaint_generate_button: gr.update(visible=False),\n",
|
||||
@@ -984,9 +994,18 @@
|
||||
" with gr.Column(scale=5):\n",
|
||||
" with gr.Row(equal_height=True):\n",
|
||||
" image_input = gr.Image(\n",
|
||||
" tool=\"sketch\",\n",
|
||||
" type=\"pil\",\n",
|
||||
" label=\"Upload\",\n",
|
||||
" sources=\"upload\",\n",
|
||||
" height=500,\n",
|
||||
" interactive=True,\n",
|
||||
" visible=False,\n",
|
||||
" )\n",
|
||||
" inpainting_input = gr.ImageMask(\n",
|
||||
" type=\"pil\",\n",
|
||||
" label=\"Upload\",\n",
|
||||
" sources=\"upload\",\n",
|
||||
" eraser=None,\n",
|
||||
" height=500,\n",
|
||||
" interactive=True,\n",
|
||||
" visible=False,\n",
|
||||
@@ -1003,6 +1022,7 @@
|
||||
" interfaces_box,\n",
|
||||
" [\n",
|
||||
" image_input,\n",
|
||||
" inpainting_input,\n",
|
||||
" image_output,\n",
|
||||
" generate_button,\n",
|
||||
" inpaint_generate_button,\n",
|
||||
@@ -1055,7 +1075,7 @@
|
||||
" num_samples,\n",
|
||||
" guidance_scale,\n",
|
||||
" num_inference_steps,\n",
|
||||
" image_input,\n",
|
||||
" inpainting_input,\n",
|
||||
" image_dimension,\n",
|
||||
" ],\n",
|
||||
" outputs=image_output,\n",
|
||||
@@ -1386,8 +1406,8 @@
|
||||
" with gr.TabItem(\"Dreambooth Finetune\"):\n",
|
||||
" create_dreambooth_workshop()\n",
|
||||
"\n",
|
||||
"demo.queue(concurrency_count=5, max_size=10)\n",
|
||||
"demo.launch(share=True, inline=False, inbrowser=True, debug=True, show_error=True)"
|
||||
"demo.queue()\n",
|
||||
"demo.launch(share=True, inline=False, debug=True, show_error=True)"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user