Alibrown commited on
Commit
8f29578
·
verified ·
1 Parent(s): 324d824

Create app_1.py

Browse files
Files changed (1) hide show
  1. app_1.py +68 -0
app_1.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from diffusers import FluxPipeline
3
+ import gradio as gr
4
+
5
+ def generate_flux_image(
6
+ prompt,
7
+ width=512,
8
+ height=512,
9
+ num_inference_steps=50,
10
+ guidance_scale=7.5,
11
+ seed=None
12
+ ):
13
+ # Zufallsgenerator-Initialisierung
14
+ if seed is None:
15
+ generator = torch.Generator(device="cuda" if torch.cuda.is_available() else "cpu")
16
+ else:
17
+ generator = torch.Generator(device="cuda" if torch.cuda.is_available() else "cpu").manual_seed(seed)
18
+
19
+ # Pipeline laden
20
+ pipeline = FluxPipeline.from_pretrained(
21
+ "improvements/flux", # Passen Sie den Pfad an
22
+ torch_dtype=torch.float16
23
+ )
24
+
25
+ # Überprüfen und ggf. auf GPU verschieben
26
+ if torch.cuda.is_available():
27
+ pipeline = pipeline.to("cuda")
28
+
29
+ # Bildgenerierung
30
+ image = pipeline(
31
+ prompt=prompt,
32
+ width=width,
33
+ height=height,
34
+ num_inference_steps=num_inference_steps,
35
+ guidance_scale=guidance_scale,
36
+ generator=generator
37
+ ).images[0]
38
+
39
+ return image
40
+
41
+ # Gradio-Interface
42
+ def create_gradio_interface():
43
+ with gr.Blocks() as demo:
44
+ with gr.Row():
45
+ prompt = gr.Textbox(label="Bildprompt")
46
+ width = gr.Slider(minimum=64, maximum=2048, value=512, label="Breite")
47
+ height = gr.Slider(minimum=64, maximum=2048, value=512, label="Höhe")
48
+
49
+ with gr.Row():
50
+ steps = gr.Slider(minimum=10, maximum=100, value=50, label="Inference Steps")
51
+ guidance = gr.Slider(minimum=1, maximum=15, value=7.5, label="Guidance Scale")
52
+ seed = gr.Number(label="Seed (optional)", precision=0)
53
+
54
+ generate_btn = gr.Button("Bild generieren")
55
+ output_image = gr.Image(label="Generiertes Bild")
56
+
57
+ generate_btn.click(
58
+ fn=generate_flux_image,
59
+ inputs=[prompt, width, height, steps, guidance, seed],
60
+ outputs=output_image
61
+ )
62
+
63
+ return demo
64
+
65
+ # Interface starten
66
+ if __name__ == "__main__":
67
+ interface = create_gradio_interface()
68
+ interface.launch(share=True)