|
import gradio as gr |
|
from diffusers import StableDiffusionPipeline |
|
import torch |
|
|
|
model_id = "runwayml/stable-diffusion-v1-5" |
|
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float32, safety_checker=None) |
|
|
|
|
|
def infer(prompt): |
|
|
|
prompt = "a photo of an astronaut riding a horse on mars" |
|
image = pipe(prompt=prompt, guidance_scale=10.0, num_inference_steps=6, width=256, height=256).images[0] |
|
|
|
return image |
|
|
|
css=""" |
|
#col-container { |
|
margin: 0 auto; |
|
max-width: 720px; |
|
} |
|
""" |
|
|
|
with gr.Blocks(css=css) as demo: |
|
|
|
with gr.Column(elem_id="col-container"): |
|
|
|
with gr.Row(): |
|
prompt = gr.Text( |
|
label="Prompt", |
|
show_label=False, |
|
max_lines=1, |
|
placeholder="Enter your prompt", |
|
container=False, |
|
) |
|
run_button = gr.Button("Run", scale=0) |
|
|
|
result = gr.Image(label="Result", show_label=False) |
|
|
|
run_button.click( |
|
fn = infer, |
|
inputs = [prompt], |
|
outputs = [result] |
|
) |
|
|
|
demo.queue().launch() |