File size: 2,566 Bytes
a00a71d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr

import torch
from diffusers import DiffusionPipeline
from diffusers import EulerDiscreteScheduler


pipeline = DiffusionPipeline.from_pretrained("recoilme/ColorfulXL-Lightning",variant="fp16"#, torch_dtype=torch.float16
                                             , use_safetensors=True)#.to("cuda")
pipeline.scheduler = EulerDiscreteScheduler.from_config(pipeline.scheduler.config, timestep_spacing="trailing")


def generate(prompt, negative_prompt, width, height, sample_steps):
    return pipeline(prompt=prompt, guidance_scale=0, negative_prompt="", width=width, height=height, num_inference_steps=sample_steps).images[0]

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="girl sitting on a small hill looking at night sky, back view, distant exploding moon, nights darkness, intricate circuits and sensors, photographic realism style, detailed textures, peacefulness, mysterious.", 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=576, minimum=512, maximum=1280, step=64, interactive=True)
                            height = gr.Slider(label="Height", info="The height in pixels of the generated image.", value=832, minimum=512, maximum=1280, step=64, interactive=True)
                        with gr.Column():
                            sampling_steps = gr.Slider(label="Sampling Steps", info="The number of denoising steps.", value=5, minimum=3, maximum=10, step=1, interactive=True)
    
            with gr.Row():
                about_text = """
                Based on: Stable Diffusion XL Image Generation interface built by Noa Roggendorff.
                
                You can enter a prompt and negative prompt, adjust the image size and sampling steps, and click the "Generate" button to generate an image.
                """
                gr.Markdown(about_text)
        
        generate_button.click(fn=generate, inputs=[prompt, negative_prompt, width, height, sampling_steps], outputs=[output])

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