Building a Stable Diffusion text-to-image pipeline with Gradio
With all preparations ready, now let’s build a Stable Diffusion text-to-image pipeline with Gradio. The UI interface will include the following:
- A prompt input box
- A negative prompt input box
- A button with the
Generate
label - A progress bar when the
Generate
button is clicked - An output image
Here is the code that implements these five elements:
import gradio gradio.close_all(verbose = True) import torch from diffusers import StableDiffusionPipeline text2img_pipe = StableDiffusionPipeline.from_pretrained( "stablediffusionapi/deliberate-v2", torch_dtype = torch.float16, safety_checker = None ).to("cuda:0") def text2img( prompt:str, neg_prompt:str, progress_bar = gradio.Progress() ): return text2img_pipe...