File size: 1,961 Bytes
04928dd
 
 
29fe78d
 
fec1479
 
 
 
 
04928dd
 
29fe78d
 
76cc54c
ef4b1b0
 
29fe78d
 
ef4b1b0
29fe78d
 
 
 
 
 
 
 
 
3bc758b
29fe78d
 
bc20e87
76cc54c
 
 
 
bc20e87
29fe78d
bc20e87
04928dd
29fe78d
 
 
 
 
 
 
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
import gradio as gr
import spaces
import torch
from diffusers import FluxPipeline
from PIL import Image
from huggingface_hub import login
import os

login(token=os.getenv('HF_TOKEN'))


@spaces.GPU
def generate_image_with_flux(prompt: str, height: int = 1024, width: int = 1024, guidance_scale: float = 3.5, num_inference_steps: int = 50) -> Image.Image:
    pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16)
    pipe.to("cuda")
    ghibli_keywords = "Studio Ghibli style, illustration, whimsical, painterly"
    optimized_prompt = f"{prompt}, {ghibli_keywords}"
    generator = torch.Generator("cuda").manual_seed(0)
    image = pipe(
        optimized_prompt,
        height=height,
        width=width,
        guidance_scale=guidance_scale,
        num_inference_steps=num_inference_steps,
        generator=generator
    ).images[0]
    return image

with gr.Blocks() as demo:
    gr.Markdown("# Create Your GhibliCard")
    with gr.Row():
        with gr.Column():
            prompt_input = gr.Textbox(label="prompt", placeholder="Enter a description of the GhibliCard you want to generate...")
            height_input = gr.Slider(minimum=256, maximum=1024, step=128, value=1024, label="Height")
            width_input = gr.Slider(minimum=256, maximum=1024, step=128, value=1024, label="Width")
            guidance_scale_input = gr.Slider(minimum=1.0, maximum=10.0, step=0.5, value=3.5, label="guidance scale")
            steps_input = gr.Slider(minimum=10, maximum=100, step=10, value=50, label="inference steps")
            generate_button = gr.Button("Generate GhibliCard")
        with gr.Column():
            output_image = gr.Image(label="Generated GhibliCard")

    generate_button.click(
        generate_image_with_flux,
        inputs=[prompt_input, height_input, width_input, guidance_scale_input, steps_input],
        outputs=output_image
    )
if __name__ == "__main__":
    demo.launch()