File size: 4,090 Bytes
9ab3040
 
f5924d4
9ab3040
 
 
7488de9
9ab3040
6c2508c
f47b463
7488de9
3725129
 
f47b463
9ab3040
f5924d4
 
9ab3040
f5924d4
 
 
 
 
9ab3040
 
 
 
 
da70f6f
986f1e6
9ab3040
 
 
 
 
 
 
 
 
 
986f1e6
f5924d4
5ae8d3f
e8e0a6c
9ab3040
f5924d4
9ab3040
 
 
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
import gradio as gr
import spaces
import random

import torch
from diffusers import StableDiffusionXLPipeline
from diffusers import AutoencoderTiny, AutoencoderKL

dtype = torch.bfloat16
device = "cuda" if torch.cuda.is_available() else "cpu"
#taef1 = AutoencoderTiny.from_pretrained("madebyollin/taef1", torch_dtype=dtype).to(device)
#good_vae = AutoencoderKL.from_pretrained("black-forest-labs/FLUX.1-dev", subfolder="vae", torch_dtype=dtype).to(device)
good_vae = AutoencoderKL.from_pretrained("bobber/bigasp2", subfolder="vae", torch_dtype=dtype).to(device)
pipeline = StableDiffusionXLPipeline.from_pretrained("bobber/bigasp2", torch_dtype=dtype, vae=good_vae).to(device)

MAX_SEED = np.iinfo(np.int32).max

@spaces.GPU
def generate(prompt, negative_prompt, width, height, sample_steps, guidance_scale, seed):
    if seed ==0:
        seed = random.randint(0, MAX_SEED)
    generator = torch.Generator().manual_seed(seed)
    return pipeline(prompt=prompt, generator=generator, negative_prompt=negative_prompt, width=width, height=height, guidance_scale=guidance_scale, 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="score_6_up, A high-resolution photograph of a young, nude woman with fair skin and long, wavy red hair cascading down her back. She is standing in a lush, tropical jungle setting, surrounded by dense greenery and various types of plants. Her physique is slender with small, perky breasts and a flat stomach. She has a relaxed, confident expression on her face, looking directly at the camera. The woman has a pair of translucent, fairy-like wings attached to her back, with a light, almost golden hue. The wings have a delicate, almost ethereal quality, contrasting with her natural skin tone. She is standing on a moss-covered rock in a small, shallow pond, with her left hand resting on the rock for support and her right arm hanging loosely by her side. The background is a dense, vibrant jungle, with large leaves and ferns in various shades of green, creating a lush, tropical atmosphere. The lighting is soft and natural, with sunlight filtering through the foliage, casting a gentle glow on her skin and the surrounding environment. The overall mood of the image is serene and magical, blending elements of fantasy and nature.", lines=4, interactive=True)
                    negative_prompt = gr.Textbox(label="Negative Prompt", info="What do you want to exclude from the image?", value="score_1, score_2, score_3", 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=1024, minimum=128, maximum=4096, step=64, interactive=True)
                            height = gr.Slider(label="Height", info="The height in pixels of the generated image.", value=1024, minimum=128, maximum=4096, step=64, interactive=True)
                        with gr.Column():
                            sampling_steps = gr.Slider(label="Sampling Steps", info="The number of denoising steps.", value=40, minimum=4, maximum=50, step=1, interactive=True)
                            seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=0,)
                        with gr.Column():
                            guidance_scale = gr.Slider(label="Guidance Scale", info="Guidance scale.", value=2.5, minimum=1, maximum=10, step=0.1, interactive=True)
        
        generate_button.click(fn=generate, inputs=[prompt, negative_prompt, width, height, sampling_steps, guidance_scale, seed], outputs=[output])

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