File size: 2,321 Bytes
e042129 87ae0d9 e042129 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
import gradio as gr
import os
from PIL import Image
import random
import torch
from diffusers import StableDiffusionPipeline, AutoencoderKL
def gen_seed():
random_data = os.urandom(3)
seed = int.from_bytes(random_data, byteorder="big")
return seed
repo = "IDKiro/sdxs-512-0.9"
weight_type = torch.float32 # or float16
# Load model.
pipe = StableDiffusionPipeline.from_pretrained(repo, torch_dtype=weight_type)
# use original VAE
# pipe.vae = AutoencoderKL.from_pretrained("IDKiro/sdxs-512-0.9/vae_large")
#pipe.to("cuda")
prompt = "portrait photo of a girl, photograph, highly detailed face, depth of field, moody light, golden hour"
def sdxs_run(prompt, steps, guidance, seed):
# Ensure using 1 inference step and CFG set to 0.
image = pipe(
prompt,
num_inference_steps=steps,
guidance_scale=guidance,
generator=torch.Generator(device="cpu").manual_seed(seed)
).images[0]
return image
#image.save("output.png")
def update_seed(rand, seed):
if rand:
return gen_seed()
else:
return seed
desc = """# SDXS CPU Test Space
Just a quick test. Model is `sdxs-512-0.9` for txt2img.
"""
with gr.Blocks() as demo:
gr.Markdown(desc)
with gr.Group():
with gr.Row():
img = gr.Image(label='SDXS Generated Image')
with gr.Row():
prompt = gr.Textbox(label='Enter your prompt (English)', scale=8, value="portrait photo of a girl, photograph, highly detailed face, depth of field, moody light, golden hour")
with gr.Row():
with gr.Accordion("More options", open=False):
steps = gr.Slider(label="Number of steps", value=1, minimum=1, maximum=20, step=1)
guidance = gr.Slider(label="Guidance", value=0, minimum=0, maximum=2, step=0.1)
seed = gr.Slider(label="Seed", minimum=20, maximum=100000000, step=1, randomize=True)
rand = gr.Checkbox(label="Randomize Seed After Generation?", value=True)
with gr.Row():
submit = gr.Button(scale=1, variant='primary')
#clear = gr.ClearButton(components=[])
submit.click(fn=sdxs_run, inputs=[prompt, steps, guidance, seed], outputs=img).then(fn=update_seed, inputs=[rand, seed], outputs=seed)
demo.queue(max_size=20).launch()
|