vsrinivas's picture
Update app.py
512088f
raw
history blame
No virus
2.01 kB
import gradio as gr
from transformers import pipeline
import torch
from diffusers import StableDiffusionPipeline
def get_completion(prompt,negative_prompt,steps,guidance,width,height):
return pipeline(prompt=prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=guidance, negative_prompt=negative_prompt)['sample'][0]
def generate(prompt,negative_prompt,steps,guidance,width,height):
output = get_completion(prompt=prompt, height=height, width=width, steps=steps, guidance=guidance, negative_prompt=negative_prompt)
return output
pipeline = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16)
with gr.Blocks() as demo:
gr.Markdown("# Image Generation with Stable Diffusion")
with gr.Row():
with gr.Column(scale=4):
prompt = gr.Textbox(label="Your prompt") #Give prompt some real estate
with gr.Column(scale=1, min_width=50):
btn = gr.Button("Submit") #Submit button side by side!
with gr.Accordion("Advanced options", open=False): #Let's hide the advanced options!
negative_prompt = gr.Textbox(label="Negative prompt")
with gr.Row():
with gr.Column():
steps = gr.Slider(label="Inference Steps", minimum=1, maximum=100, value=25,
info="In many steps will the denoiser denoise the image?")
guidance = gr.Slider(label="Guidance Scale", minimum=1, maximum=20, value=7,
info="Controls how much the text prompt influences the result")
with gr.Column():
width = gr.Slider(label="Width", minimum=64, maximum=512, step=64, value=512)
height = gr.Slider(label="Height", minimum=64, maximum=512, step=64, value=512)
output = gr.Image(label="Result") #Move the output up too
btn.click(fn=generate, inputs=[prompt,negative_prompt,steps,guidance,width,height], outputs=[output])
demo.launch()