File size: 2,424 Bytes
9cc7145
 
 
 
9030333
9cc7145
e99f9d3
12d56e7
9cc7145
 
4d88688
 
 
 
 
 
 
 
 
 
 
 
9cc7145
 
 
 
 
c282030
622e2dc
9cc7145
 
 
 
 
 
 
8180d07
 
52a50b1
9cc7145
 
 
4d88688
9cc7145
 
 
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
import gradio as gr
import spaces

import torch
from diffusers import StableDiffusionPipeline, StableDiffusionImg2ImgPipeline

pipeline = StableDiffusionPipeline.from_pretrained("nroggendorff/zelda-diffusion").to("cuda")
img2img = StableDiffusionImg2ImgPipeline(**pipeline.components)

@spaces.GPU
def generate(prompt, negative_prompt, width, height, sample_steps, hrf):
    image = pipeline(prompt=prompt, negative_prompt=negative_prompt, width=width, height=height, num_inference_steps=sample_steps).images[0]
    if hrf:
        return img2img(
            prompt=prompt,
            image=image,
            strength=0.75,
            width=width * 2,
            height=height * 2
        ).images[0]
    else:
        return image

with gr.Blocks() as interface:
        with gr.Column():
            with gr.Row():
                with gr.Column():
                    prompt = gr.Textbox(label="Prompt", info="What do you want?", value="pretty girl face, 32k HDR, studio lighting", lines=4, interactive=True)
                    negative_prompt = gr.Textbox(label="Negative Prompt", info="What do you want to exclude from the image?", value="watermark, jewelry, ugly, low quality", lines=4, interactive=True)
                with gr.Column():
                    generate_button = gr.Button("Generate")
                    output = gr.Image()
            with gr.Row():
                with gr.Accordion(label="Advanced Settings", open=False):
                    with gr.Row():
                        with gr.Column():
                            width = gr.Slider(label="Width", info="The width in pixels of the generated image.", value=512, minimum=128, maximum=4096, step=64, interactive=True)
                            height = gr.Slider(label="Height", info="The height in pixels of the generated image.", value=512, minimum=128, maximum=4096, step=64, interactive=True)
                            hrf = gr.Checkbox(label="High-Res Fix", info="Run through img2img.", value=True, interactive=True)
                        with gr.Column():
                            sampling_steps = gr.Slider(label="Sampling Steps", info="The number of denoising steps.", value=20, minimum=4, maximum=50, step=1, interactive=True)
        
        generate_button.click(fn=generate, inputs=[prompt, negative_prompt, width, height, sampling_steps, hrf], outputs=[output])

if __name__ == "__main__":
    interface.launch()