Scalino84
commited on
Commit
·
6455ecf
1
Parent(s):
1dc9513
Add application file
Browse files
app.py
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from diffusers import StableDiffusionPipeline
|
3 |
+
import torch
|
4 |
+
from huggingface_hub import HfFolder
|
5 |
+
|
6 |
+
def generate_image(prompt, guidance_scale, num_steps, lora_scale):
|
7 |
+
# Lade das Base Model
|
8 |
+
pipe = StableDiffusionPipeline.from_pretrained(
|
9 |
+
"runwayml/stable-diffusion-v1-5",
|
10 |
+
torch_dtype=torch.float16
|
11 |
+
).to("cuda")
|
12 |
+
|
13 |
+
# Lade dein LoRA
|
14 |
+
pipe.load_lora_weights(
|
15 |
+
"Scalino84/my-flux-face-v2",
|
16 |
+
weight_name="flux_train_replicate.safetensors"
|
17 |
+
)
|
18 |
+
|
19 |
+
# Generiere das Bild
|
20 |
+
image = pipe(
|
21 |
+
prompt=prompt,
|
22 |
+
num_inference_steps=num_steps,
|
23 |
+
guidance_scale=guidance_scale,
|
24 |
+
cross_attention_kwargs={"scale": lora_scale}
|
25 |
+
).images[0]
|
26 |
+
|
27 |
+
return image
|
28 |
+
|
29 |
+
# Erstelle das Gradio Interface
|
30 |
+
with gr.Blocks() as demo:
|
31 |
+
gr.Markdown("# Flux Face Generator")
|
32 |
+
|
33 |
+
with gr.Row():
|
34 |
+
with gr.Column():
|
35 |
+
prompt = gr.Textbox(
|
36 |
+
label="Prompt",
|
37 |
+
value="a photo of xyz person, professional headshot",
|
38 |
+
lines=3
|
39 |
+
)
|
40 |
+
guidance = gr.Slider(
|
41 |
+
label="Guidance Scale",
|
42 |
+
minimum=1,
|
43 |
+
maximum=20,
|
44 |
+
value=7.5,
|
45 |
+
step=0.5
|
46 |
+
)
|
47 |
+
steps = gr.Slider(
|
48 |
+
label="Inference Steps",
|
49 |
+
minimum=20,
|
50 |
+
maximum=100,
|
51 |
+
value=30,
|
52 |
+
step=1
|
53 |
+
)
|
54 |
+
lora_scale = gr.Slider(
|
55 |
+
label="LoRA Scale",
|
56 |
+
minimum=0.1,
|
57 |
+
maximum=1.0,
|
58 |
+
value=0.8,
|
59 |
+
step=0.1
|
60 |
+
)
|
61 |
+
generate = gr.Button("Generate Image")
|
62 |
+
|
63 |
+
with gr.Column():
|
64 |
+
output = gr.Image(label="Generated Image")
|
65 |
+
|
66 |
+
generate.click(
|
67 |
+
fn=generate_image,
|
68 |
+
inputs=[prompt, guidance, steps, lora_scale],
|
69 |
+
outputs=output
|
70 |
+
)
|
71 |
+
|
72 |
+
demo.launch()
|
73 |
+
|