multimodalart HF staff commited on
Commit
7d06e7c
1 Parent(s): 5c2ed37

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -28
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import gradio as gr
2
  import numpy as np
3
  import random
4
- #import spaces #[uncomment to use ZeroGPU]
5
  from diffusers import DiffusionPipeline
6
  import torch
7
 
@@ -19,8 +19,8 @@ pipe = pipe.to(device)
19
  MAX_SEED = np.iinfo(np.int32).max
20
  MAX_IMAGE_SIZE = 1024
21
 
22
- #@spaces.GPU #[uncomment to use ZeroGPU]
23
- def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, progress=gr.Progress(track_tqdm=True)):
24
 
25
  if randomize_seed:
26
  seed = random.randint(0, MAX_SEED)
@@ -31,6 +31,7 @@ def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance
31
  prompt = prompt,
32
  negative_prompt = negative_prompt,
33
  guidance_scale = guidance_scale,
 
34
  num_inference_steps = num_inference_steps,
35
  width = width,
36
  height = height,
@@ -56,31 +57,46 @@ with gr.Blocks(css=css) as demo:
56
 
57
  with gr.Column(elem_id="col-container"):
58
  gr.Markdown(f"""
59
- # Text-to-Image Gradio Template
60
  """)
61
 
62
  with gr.Row():
63
-
64
- prompt = gr.Text(
65
- label="Prompt",
66
- show_label=False,
67
- max_lines=1,
68
- placeholder="Enter your prompt",
69
- container=False,
70
- )
71
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  run_button = gr.Button("Run", scale=0)
73
 
74
  result = gr.Image(label="Result", show_label=False)
75
 
76
  with gr.Accordion("Advanced Settings", open=False):
77
 
78
- negative_prompt = gr.Text(
79
- label="Negative prompt",
80
- max_lines=1,
81
- placeholder="Enter a negative prompt",
82
- visible=False,
83
- )
84
 
85
  seed = gr.Slider(
86
  label="Seed",
@@ -112,20 +128,14 @@ with gr.Blocks(css=css) as demo:
112
 
113
  with gr.Row():
114
 
115
- guidance_scale = gr.Slider(
116
- label="Guidance scale",
117
- minimum=0.0,
118
- maximum=10.0,
119
- step=0.1,
120
- value=0.0, #Replace with defaults that work for your model
121
- )
122
 
123
  num_inference_steps = gr.Slider(
124
  label="Number of inference steps",
125
  minimum=1,
126
  maximum=50,
127
  step=1,
128
- value=2, #Replace with defaults that work for your model
129
  )
130
 
131
  gr.Examples(
@@ -135,7 +145,7 @@ with gr.Blocks(css=css) as demo:
135
  gr.on(
136
  triggers=[run_button.click, prompt.submit],
137
  fn = infer,
138
- inputs = [prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
139
  outputs = [result, seed]
140
  )
141
 
 
1
  import gradio as gr
2
  import numpy as np
3
  import random
4
+ import spaces #[uncomment to use ZeroGPU]
5
  from diffusers import DiffusionPipeline
6
  import torch
7
 
 
19
  MAX_SEED = np.iinfo(np.int32).max
20
  MAX_IMAGE_SIZE = 1024
21
 
22
+ @spaces.GPU #[uncomment to use ZeroGPU]
23
+ def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, true_guidance, num_inference_steps, progress=gr.Progress(track_tqdm=True)):
24
 
25
  if randomize_seed:
26
  seed = random.randint(0, MAX_SEED)
 
31
  prompt = prompt,
32
  negative_prompt = negative_prompt,
33
  guidance_scale = guidance_scale,
34
+ true_cfg = true_guidance,
35
  num_inference_steps = num_inference_steps,
36
  width = width,
37
  height = height,
 
57
 
58
  with gr.Column(elem_id="col-container"):
59
  gr.Markdown(f"""
60
+ # FLUX.1 [dev] with CFG (and negative prompts)
61
  """)
62
 
63
  with gr.Row():
64
+ with gr.Row():
65
+ prompt = gr.Text(
66
+ label="Prompt",
67
+ show_label=False,
68
+ max_lines=1,
69
+ placeholder="Enter your prompt",
70
+ container=False,
71
+ )
72
+ negative_prompt = gr.Text(
73
+ label="Negative prompt",
74
+ max_lines=1,
75
+ placeholder="Enter a negative prompt",
76
+ visible=False,
77
+ )
78
+ with gr.Row():
79
+ guidance_scale = gr.Slider(
80
+ label="Guidance scale",
81
+ minimum=0.0,
82
+ maximum=10.0,
83
+ step=0.1,
84
+ value=1.0, #Replace with defaults that work for your model
85
+ )
86
+ true_guidance = gr.Slider(
87
+ label="True CFG scale",
88
+ minimum=0.0,
89
+ maximum=10.0,
90
+ step=0.1,
91
+ value=5.0, #Replace with defaults that work for your model
92
+ )
93
  run_button = gr.Button("Run", scale=0)
94
 
95
  result = gr.Image(label="Result", show_label=False)
96
 
97
  with gr.Accordion("Advanced Settings", open=False):
98
 
99
+
 
 
 
 
 
100
 
101
  seed = gr.Slider(
102
  label="Seed",
 
128
 
129
  with gr.Row():
130
 
131
+
 
 
 
 
 
 
132
 
133
  num_inference_steps = gr.Slider(
134
  label="Number of inference steps",
135
  minimum=1,
136
  maximum=50,
137
  step=1,
138
+ value=28, #Replace with defaults that work for your model
139
  )
140
 
141
  gr.Examples(
 
145
  gr.on(
146
  triggers=[run_button.click, prompt.submit],
147
  fn = infer,
148
+ inputs = [prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, true_guidance, num_inference_steps],
149
  outputs = [result, seed]
150
  )
151