kadirnar commited on
Commit
3d87864
1 Parent(s): a16e7cb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -128
app.py CHANGED
@@ -1,60 +1,20 @@
1
  import gradio as gr
2
  import numpy as np
3
  import random
4
- import spaces
5
- from diffusers import AuraFlowPipeline
6
  import torch
7
- from gradio_imageslider import ImageSlider
8
 
9
  device = "cuda" if torch.cuda.is_available() else "cpu"
10
 
11
- #torch.set_float32_matmul_precision("high")
12
-
13
- #torch._inductor.config.conv_1x1_as_mm = True
14
- #torch._inductor.config.coordinate_descent_tuning = True
15
- #torch._inductor.config.epilogue_fusion = False
16
- #torch._inductor.config.coordinate_descent_check_all_directions = True
17
-
18
- #pipe_v1 = AuraFlowPipeline.from_pretrained(
19
- # "fal/AuraFlow",
20
- # torch_dtype=torch.float16
21
- #).to("cuda")
22
-
23
- pipe_v2 = AuraFlowPipeline.from_pretrained(
24
- "fal/AuraFlow-v0.2",
25
- torch_dtype=torch.float16
26
- ).to("cuda")
27
-
28
  pipe = AuraFlowPipeline.from_pretrained(
29
- "fal/AuraFlow-v0.3",
30
  torch_dtype=torch.float16
31
- ).to("cuda")
32
- #pipe.transformer.to(memory_format=torch.channels_last)
33
- #pipe.transformer = torch.compile(pipe.transformer, mode="reduce-overhead", fullgraph=True)
34
- #pipe.transformer.to(memory_format=torch.channels_last)
35
- #pipe.vae.to(memory_format=torch.channels_last)
36
-
37
- #pipe.transformer = torch.compile(pipe.transformer, mode="max-autotune", fullgraph=True)
38
- #pipe.vae.decode = torch.compile(pipe.vae.decode, mode="max-autotune", fullgraph=True)
39
 
40
  MAX_SEED = np.iinfo(np.int32).max
41
  MAX_IMAGE_SIZE = 1024
42
 
43
- @spaces.GPU()
44
- def infer_example(prompt, negative_prompt="", seed=42, randomize_seed=False, width=1024, height=1024, guidance_scale=5.0, num_inference_steps=28, model_version="0.2", comparison_mode=False, progress=gr.Progress(track_tqdm=True)):
45
- generator = torch.Generator().manual_seed(seed)
46
- image = pipe(
47
- prompt = prompt,
48
- negative_prompt = negative_prompt,
49
- width = width,
50
- height = height,
51
- guidance_scale = guidance_scale,
52
- num_inference_steps = num_inference_steps,
53
- generator = generator
54
- ).images[0]
55
- return image, seed
56
-
57
- @spaces.GPU(duration=95)
58
  def infer(prompt,
59
  negative_prompt="",
60
  seed=42,
@@ -63,68 +23,24 @@ def infer(prompt,
63
  height=1024,
64
  guidance_scale=5.0,
65
  num_inference_steps=28,
66
- model_version="0.3",
67
- comparison_mode=False,
68
- progress=gr.Progress(track_tqdm=True)
69
- ):
70
 
71
  if randomize_seed:
72
  seed = random.randint(0, MAX_SEED)
73
 
74
- generator = torch.Generator().manual_seed(seed)
75
- if(comparison_mode):
76
- image_1 = pipe_v2(
77
- prompt = prompt,
78
- negative_prompt = negative_prompt,
79
- width=width,
80
- height=height,
81
- guidance_scale = guidance_scale,
82
- num_inference_steps = num_inference_steps,
83
- generator = generator
84
- ).images[0]
85
- generator = torch.Generator().manual_seed(seed)
86
- image_2 = pipe(
87
- prompt = prompt,
88
- negative_prompt = negative_prompt,
89
- width=width,
90
- height=height,
91
- guidance_scale = guidance_scale,
92
- num_inference_steps = num_inference_steps,
93
- generator = generator
94
- ).images[0]
95
- return gr.update(visible=False), gr.update(visible=True, value=(image_1, image_2)), seed
96
- if(model_version == "0.1"):
97
- image = pipe_v1(
98
- prompt = prompt,
99
- negative_prompt = negative_prompt,
100
- width=width,
101
- height=height,
102
- guidance_scale = guidance_scale,
103
- num_inference_steps = num_inference_steps,
104
- generator = generator
105
- ).images[0]
106
- elif(model_version == "0.2"):
107
- image = pipe_v2(
108
- prompt = prompt,
109
- negative_prompt = negative_prompt,
110
- width=width,
111
- height=height,
112
- guidance_scale = guidance_scale,
113
- num_inference_steps = num_inference_steps,
114
- generator = generator
115
- ).images[0]
116
- else:
117
- image = pipe(
118
- prompt = prompt,
119
- negative_prompt = negative_prompt,
120
- width=width,
121
- height=height,
122
- guidance_scale = guidance_scale,
123
- num_inference_steps = num_inference_steps,
124
- generator = generator
125
- ).images[0]
126
 
127
- return gr.update(visible=True, value=image), gr.update(visible=False), seed
128
 
129
  examples = [
130
  "A photo of a lavender cat",
@@ -141,16 +57,24 @@ css="""
141
  """
142
 
143
  with gr.Blocks(css=css) as demo:
144
-
145
  with gr.Column(elem_id="col-container"):
146
- gr.Markdown(f"""
147
- # AuraFlow 0.3
148
- Demo of the [AuraFlow 0.3](https://huggingface.co/fal/AuraFlow-v0.3) 6.8B parameters open source diffusion transformer model
149
- [[blog](https://blog.fal.ai/auraflow/)] [[model](https://huggingface.co/fal/AuraFlow)] [[fal](https://fal.ai/models/fal-ai/aura-flow)]
150
- """)
 
 
 
 
 
 
 
 
 
 
151
 
152
  with gr.Row():
153
-
154
  prompt = gr.Text(
155
  label="Prompt",
156
  show_label=False,
@@ -158,18 +82,11 @@ with gr.Blocks(css=css) as demo:
158
  placeholder="Enter your prompt",
159
  container=False,
160
  )
161
-
162
  run_button = gr.Button("Run", scale=0)
163
 
164
  result = gr.Image(label="Result", show_label=False)
165
- result_compare = ImageSlider(visible=False, label="Left 0.2, Right 0.3")
166
- comparison_mode = gr.Checkbox(label="Comparison mode", info="Compare v0.2 with v0.3", value=False)
167
  with gr.Accordion("Advanced Settings", open=False):
168
-
169
- model_version = gr.Dropdown(
170
- ["0.2", "0.3"], label="Model version", value="0.3"
171
- )
172
-
173
  negative_prompt = gr.Text(
174
  label="Negative prompt",
175
  max_lines=1,
@@ -187,7 +104,6 @@ with gr.Blocks(css=css) as demo:
187
  randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
188
 
189
  with gr.Row():
190
-
191
  width = gr.Slider(
192
  label="Width",
193
  minimum=256,
@@ -195,7 +111,6 @@ with gr.Blocks(css=css) as demo:
195
  step=32,
196
  value=1024,
197
  )
198
-
199
  height = gr.Slider(
200
  label="Height",
201
  minimum=256,
@@ -205,7 +120,6 @@ with gr.Blocks(css=css) as demo:
205
  )
206
 
207
  with gr.Row():
208
-
209
  guidance_scale = gr.Slider(
210
  label="Guidance scale",
211
  minimum=0.0,
@@ -213,7 +127,6 @@ with gr.Blocks(css=css) as demo:
213
  step=0.1,
214
  value=5.0,
215
  )
216
-
217
  num_inference_steps = gr.Slider(
218
  label="Number of inference steps",
219
  minimum=1,
@@ -223,18 +136,18 @@ with gr.Blocks(css=css) as demo:
223
  )
224
 
225
  gr.Examples(
226
- examples = examples,
227
- fn = infer_example,
228
- inputs = [prompt],
229
- outputs = [result, seed],
230
  cache_examples="lazy"
231
  )
232
 
233
  gr.on(
234
  triggers=[run_button.click, prompt.submit, negative_prompt.submit],
235
- fn = infer,
236
- inputs = [prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, model_version, comparison_mode],
237
- outputs = [result, result_compare, seed]
238
  )
239
 
240
- demo.queue().launch()
 
1
  import gradio as gr
2
  import numpy as np
3
  import random
 
 
4
  import torch
5
+ from diffusers import AuraFlowPipeline
6
 
7
  device = "cuda" if torch.cuda.is_available() else "cpu"
8
 
9
+ # Initialize the AuraFlow v0.3 pipeline
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  pipe = AuraFlowPipeline.from_pretrained(
11
+ "fal/AuraFlow-v0.3",
12
  torch_dtype=torch.float16
13
+ ).to(device)
 
 
 
 
 
 
 
14
 
15
  MAX_SEED = np.iinfo(np.int32).max
16
  MAX_IMAGE_SIZE = 1024
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  def infer(prompt,
19
  negative_prompt="",
20
  seed=42,
 
23
  height=1024,
24
  guidance_scale=5.0,
25
  num_inference_steps=28,
26
+ progress=gr.Progress(track_tqdm=True)):
 
 
 
27
 
28
  if randomize_seed:
29
  seed = random.randint(0, MAX_SEED)
30
 
31
+ generator = torch.Generator(device=device).manual_seed(seed)
32
+
33
+ image = pipe(
34
+ prompt=prompt,
35
+ negative_prompt=negative_prompt,
36
+ width=width,
37
+ height=height,
38
+ guidance_scale=guidance_scale,
39
+ num_inference_steps=num_inference_steps,
40
+ generator=generator
41
+ ).images[0]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
 
43
+ return image, seed
44
 
45
  examples = [
46
  "A photo of a lavender cat",
 
57
  """
58
 
59
  with gr.Blocks(css=css) as demo:
 
60
  with gr.Column(elem_id="col-container"):
61
+ gr.HTML(
62
+ """
63
+ <h1 style='text-align: center'>
64
+ AuraFlow v0.3
65
+ </h1>
66
+ """
67
+ )
68
+ gr.HTML(
69
+ """
70
+ <h3 style='text-align: center'>
71
+ Follow me for more!
72
+ <a href='https://twitter.com/kadirnar_ai' target='_blank'>Twitter</a> | <a href='https://github.com/kadirnar' target='_blank'>Github</a> | <a href='https://www.linkedin.com/in/kadir-nar/' target='_blank'>Linkedin</a> | <a href='https://www.huggingface.co/kadirnar/' target='_blank'>HuggingFace</a>
73
+ </h3>
74
+ """
75
+ )
76
 
77
  with gr.Row():
 
78
  prompt = gr.Text(
79
  label="Prompt",
80
  show_label=False,
 
82
  placeholder="Enter your prompt",
83
  container=False,
84
  )
 
85
  run_button = gr.Button("Run", scale=0)
86
 
87
  result = gr.Image(label="Result", show_label=False)
88
+
 
89
  with gr.Accordion("Advanced Settings", open=False):
 
 
 
 
 
90
  negative_prompt = gr.Text(
91
  label="Negative prompt",
92
  max_lines=1,
 
104
  randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
105
 
106
  with gr.Row():
 
107
  width = gr.Slider(
108
  label="Width",
109
  minimum=256,
 
111
  step=32,
112
  value=1024,
113
  )
 
114
  height = gr.Slider(
115
  label="Height",
116
  minimum=256,
 
120
  )
121
 
122
  with gr.Row():
 
123
  guidance_scale = gr.Slider(
124
  label="Guidance scale",
125
  minimum=0.0,
 
127
  step=0.1,
128
  value=5.0,
129
  )
 
130
  num_inference_steps = gr.Slider(
131
  label="Number of inference steps",
132
  minimum=1,
 
136
  )
137
 
138
  gr.Examples(
139
+ examples=examples,
140
+ fn=infer,
141
+ inputs=[prompt],
142
+ outputs=[result, seed],
143
  cache_examples="lazy"
144
  )
145
 
146
  gr.on(
147
  triggers=[run_button.click, prompt.submit, negative_prompt.submit],
148
+ fn=infer,
149
+ inputs=[prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
150
+ outputs=[result, seed]
151
  )
152
 
153
+ demo.queue().launch()