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...