File size: 1,838 Bytes
abd4d0f
 
 
 
 
 
f51dfbd
 
 
 
147b85b
abd4d0f
 
 
 
 
147b85b
abd4d0f
147b85b
f51dfbd
 
 
147b85b
f51dfbd
abd4d0f
147b85b
abd4d0f
 
 
 
147b85b
 
abd4d0f
 
 
 
 
147b85b
 
abd4d0f
 
147b85b
abd4d0f
 
 
 
 
147b85b
 
abd4d0f
 
 
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
import gradio as gr
import numpy as np
import random
from diffusers import DiffusionPipeline
import torch

torch_dtype, device = (
    (torch.float16, torch.device("cuda")) if torch.cuda.is_available() 
    else (torch.float32, torch.device("cpu"))
)

model_repo_id = "black-forest-labs/FLUX.1-dev"

pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype).to(device)
pipe.load_lora_weights("pepper13/flux-anime")

def infer(prompt, randomize_seed, width, height, guidance_scale, num_inference_steps):
    image = pipe(
        prompt=prompt,
        guidance_scale=guidance_scale,
        num_inference_steps=num_inference_steps,
        width=width,
        height=height
    ).images[0]
    
    return image

with gr.Blocks() as demo:
    with gr.Column(elem_id="col-container"):
        with gr.Row():
            prompt = gr.Text(label="Prompt", show_label=False, placeholder="Enter your prompt")
            run_button = gr.Button("Generate", scale=0)
        
        result = gr.Image(label="Result", show_label=False)

        with gr.Accordion("Advanced Settings", open=False):
            with gr.Row():
                width = gr.Slider(label="Width", minimum=256, maximum=1024, step=32, value=512)
                height = gr.Slider(label="Height", minimum=256, maximum=1024, step=32, value=512)
            
            with gr.Row():
                guidance_scale = gr.Slider(label="Guidance scale", minimum=0.1, maximum=10.0, step=0.1, value=7.0)
                num_inference_steps = gr.Slider(label="Number of inference steps", minimum=1, maximum=50, step=1, value=20)
    
    gr.on(
        triggers=[run_button.click, prompt.submit],
        fn=infer,
        inputs=[prompt, negative_prompt, width, height, guidance_scale, num_inference_steps],
        outputs=[result]
    )

demo.launch()