Alibrown commited on
Commit
13b0bd1
·
verified ·
1 Parent(s): 2b086d4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +144 -24
app.py CHANGED
@@ -1,30 +1,150 @@
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
- def main():
4
- # Laden des Flux-Modells
5
- demo = gr.load("models/enhanceaiteam/Flux-Uncensored-V2")
6
-
7
- # Anpassung der Benutzeroberfläche
8
- with gr.Blocks() as flux_interface:
9
- gr.Markdown("# Flux Image Generator 🖼️")
10
- gr.Markdown("Generieren Sie hochwertige Bilder mit Flux AI")
11
-
12
  with gr.Row():
13
- # Der geladene Flux-Komponente wird automatisch hinzugefügt
14
- demo.render()
15
-
16
- gr.Markdown("""
17
- ### Tipps zur Nutzung:
18
- - Geben Sie detaillierte Beschreibungen ein
19
- - Experimentieren Sie mit verschiedenen Stilen
20
- - Mehr Details führen zu präziseren Ergebnissen
21
- """)
22
-
23
- # Interface starten
24
- flux_interface.launch(
25
- debug=True, # Detaillierte Fehlermeldungen
26
- show_error=True # Zeige Fehler im Interface
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  )
28
 
29
  if __name__ == "__main__":
30
- main()
 
1
  import gradio as gr
2
+ import numpy as np
3
+ import random
4
+ import os
5
+
6
+ import spaces
7
+ from diffusers import AutoPipelineForText2Image
8
+ import torch
9
+
10
+ from huggingface_hub import login
11
+ login(os.environ.get("HF_TOKEN"))
12
+
13
+ device = "cuda" if torch.cuda.is_available() else "cpu"
14
+
15
+ if torch.cuda.is_available():
16
+ torch_dtype = torch.float16
17
+ else:
18
+ torch_dtype = torch.float32
19
+
20
+ pipe = AutoPipelineForText2Image.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16)
21
+ pipe.load_lora_weights('enhanceaiteam/Flux-uncensored', weight_name='lora.safetensors')
22
+ pipe = pipe.to(device)
23
+
24
+ MAX_SEED = np.iinfo(np.int32).max
25
+ MAX_IMAGE_SIZE = 1024
26
+
27
+
28
+ @spaces.GPU
29
+ def infer(
30
+ prompt,
31
+ seed,
32
+ randomize_seed,
33
+ width,
34
+ height,
35
+ guidance_scale,
36
+ num_inference_steps,
37
+ progress=gr.Progress(track_tqdm=True),
38
+ ):
39
+ if randomize_seed:
40
+ seed = random.randint(0, MAX_SEED)
41
+
42
+ generator = torch.Generator().manual_seed(seed)
43
+
44
+ image = pipe(
45
+ prompt=prompt,
46
+ guidance_scale=guidance_scale,
47
+ num_inference_steps=num_inference_steps,
48
+ width=width,
49
+ height=height,
50
+ generator=generator,
51
+ ).images[0]
52
+
53
+ return image, seed
54
+
55
+
56
+ examples = [
57
+ "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
58
+ "An astronaut riding a green horse",
59
+ "A delicious ceviche cheesecake slice",
60
+ ]
61
+
62
+ css = """
63
+ #col-container {
64
+ margin: 0 auto;
65
+ max-width: 640px;
66
+ }
67
+ """
68
+
69
+ with gr.Blocks(css=css) as demo:
70
+ with gr.Column(elem_id="col-container"):
71
+ gr.Markdown(f"""# [FLUX.1](https://blackforestlabs.ai/)
72
+ Generate any type of image.
73
+ """)
74
 
 
 
 
 
 
 
 
 
 
75
  with gr.Row():
76
+ prompt = gr.Text(
77
+ label="Prompt",
78
+ show_label=False,
79
+ max_lines=1,
80
+ placeholder="Enter your prompt",
81
+ container=False,
82
+ )
83
+
84
+ run_button = gr.Button("Run", scale=0, variant="primary")
85
+
86
+ result = gr.Image(label="Result", show_label=False)
87
+
88
+ with gr.Accordion("Advanced Settings", open=False):
89
+ seed = gr.Slider(
90
+ label="Seed",
91
+ minimum=0,
92
+ maximum=MAX_SEED,
93
+ step=1,
94
+ value=0,
95
+ )
96
+
97
+ randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
98
+
99
+ with gr.Row():
100
+ width = gr.Slider(
101
+ label="Width",
102
+ minimum=256,
103
+ maximum=MAX_IMAGE_SIZE,
104
+ step=32,
105
+ value=1024,
106
+ )
107
+
108
+ height = gr.Slider(
109
+ label="Height",
110
+ minimum=256,
111
+ maximum=MAX_IMAGE_SIZE,
112
+ step=32,
113
+ value=1024,
114
+ )
115
+
116
+ with gr.Row():
117
+ guidance_scale = gr.Slider(
118
+ label="Guidance scale",
119
+ minimum=0.0,
120
+ maximum=10.0,
121
+ step=0.1,
122
+ value=3.5,
123
+ )
124
+
125
+ num_inference_steps = gr.Slider(
126
+ label="Number of inference steps",
127
+ minimum=1,
128
+ maximum=50,
129
+ step=1,
130
+ value=28,
131
+ )
132
+
133
+ gr.Examples(examples=examples, inputs=[prompt])
134
+ gr.on(
135
+ triggers=[run_button.click, prompt.submit],
136
+ fn=infer,
137
+ inputs=[
138
+ prompt,
139
+ seed,
140
+ randomize_seed,
141
+ width,
142
+ height,
143
+ guidance_scale,
144
+ num_inference_steps,
145
+ ],
146
+ outputs=[result, seed],
147
  )
148
 
149
  if __name__ == "__main__":
150
+ demo.launch()