File size: 1,945 Bytes
6455ecf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import gradio as gr
from diffusers import StableDiffusionPipeline
import torch
from huggingface_hub import HfFolder

def generate_image(prompt, guidance_scale, num_steps, lora_scale):
    # Lade das Base Model
    pipe = StableDiffusionPipeline.from_pretrained(
        "runwayml/stable-diffusion-v1-5",
        torch_dtype=torch.float16
    ).to("cuda")
    
    # Lade dein LoRA
    pipe.load_lora_weights(
        "Scalino84/my-flux-face-v2",
        weight_name="flux_train_replicate.safetensors"
    )
    
    # Generiere das Bild
    image = pipe(
        prompt=prompt,
        num_inference_steps=num_steps,
        guidance_scale=guidance_scale,
        cross_attention_kwargs={"scale": lora_scale}
    ).images[0]
    
    return image

# Erstelle das Gradio Interface
with gr.Blocks() as demo:
    gr.Markdown("# Flux Face Generator")
    
    with gr.Row():
        with gr.Column():
            prompt = gr.Textbox(
                label="Prompt",
                value="a photo of xyz person, professional headshot",
                lines=3
            )
            guidance = gr.Slider(
                label="Guidance Scale",
                minimum=1,
                maximum=20,
                value=7.5,
                step=0.5
            )
            steps = gr.Slider(
                label="Inference Steps",
                minimum=20,
                maximum=100,
                value=30,
                step=1
            )
            lora_scale = gr.Slider(
                label="LoRA Scale",
                minimum=0.1,
                maximum=1.0,
                value=0.8,
                step=0.1
            )
            generate = gr.Button("Generate Image")
        
        with gr.Column():
            output = gr.Image(label="Generated Image")
    
    generate.click(
        fn=generate_image,
        inputs=[prompt, guidance, steps, lora_scale],
        outputs=output
    )

demo.launch()