daniel-dona commited on
Commit
eb41639
·
verified ·
1 Parent(s): 51bd381

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -28
app.py CHANGED
@@ -26,24 +26,25 @@ MAX_SEED = np.iinfo(np.int32).max
26
  examples = json.loads(open("examples.json").read())
27
 
28
  aspect_ratios = {
29
- "Big 1:1": (1080, 1080),
30
- "Big 16:9": (1920, 1080),
31
- "Big 9:16": (1080, 1920),
32
- "Big 4:3": (1440, 1080),
33
- "Big 3:4": (1080, 1440),
34
-
35
- "Small 1:1": (720, 720),
36
- "Small 16:9": (1280, 720),
37
- "Small 9:16": (720, 1280),
38
- "Small 4:3": (960, 720),
39
- "Small 3:4": (720, 960),
 
 
 
 
 
 
40
  }
41
 
42
- def get_image_size(aspect_ratio):
43
-
44
-
45
-
46
- return aspect_ratios[aspect_ratio]
47
 
48
  def polish_prompt_en(original_prompt):
49
 
@@ -66,13 +67,13 @@ def polish_prompt_en(original_prompt):
66
  return polished_prompt
67
 
68
 
69
- @spaces.GPU(duration=45)
70
  def infer(
71
  prompt,
72
  negative_prompt=" ",
73
  seed=42,
74
  randomize_seed=False,
75
- aspect_ratio="16:9",
76
  guidance_scale=4,
77
  num_inference_steps=50,
78
  progress=gr.Progress(track_tqdm=True),
@@ -81,7 +82,8 @@ def infer(
81
 
82
  if randomize_seed:
83
  seed = random.randint(0, MAX_SEED)
84
- width, height = get_image_size(aspect_ratio)
 
85
 
86
  print("Generating for prompt:", prompt)
87
  image = pipe(
@@ -89,9 +91,9 @@ def infer(
89
  negative_prompt=negative_prompt,
90
  width=width,
91
  height=height,
92
- num_inference_steps=50,
93
- true_cfg_scale=4.0,
94
- generator=torch.Generator(device="cuda").manual_seed(42)
95
  ).images[0]
96
 
97
  #image.save("example.png")
@@ -125,8 +127,9 @@ with gr.Blocks(css=css) as demo:
125
  run_button = gr.Button("Run", scale=0, variant="primary")
126
 
127
  result = gr.Image(label="Result", show_label=False)
 
128
 
129
- with gr.Accordion("Advanced Settings", open=False):
130
  negative_prompt = gr.Text(
131
  label="Negative prompt",
132
  max_lines=1,
@@ -145,14 +148,13 @@ with gr.Blocks(css=css) as demo:
145
  randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
146
 
147
  with gr.Row():
148
- aspect_ratio = gr.Radio(
149
- label="Image size",
150
  choices=list(aspect_ratios.keys()),
151
- value="Small 4:3",
152
  )
153
 
154
 
155
-
156
  with gr.Row():
157
  guidance_scale = gr.Slider(
158
  label="Guidance scale",
@@ -183,7 +185,7 @@ with gr.Blocks(css=css) as demo:
183
  guidance_scale,
184
  num_inference_steps,
185
  ],
186
- outputs=[result, seed],
187
  )
188
 
189
  if __name__ == "__main__":
 
26
  examples = json.loads(open("examples.json").read())
27
 
28
  aspect_ratios = {
29
+ "1080, aspect 1:1": (1080, 1080),
30
+ "1080, aspect 16:9": (1920, 1080),
31
+ "1080, aspect 9:16": (1080, 1920),
32
+ "1080, aspect 4:3": (1440, 1080),
33
+ "1080, aspect 3:4": (1080, 1440),
34
+
35
+ "720, aspect 1:1": (720, 720),
36
+ "720, aspect 16:9": (1280, 720),
37
+ "720, aspect 9:16": (720, 1280),
38
+ "720, aspect 4:3": (960, 720),
39
+ "720, aspect 3:4": (720, 960),
40
+
41
+ "480, aspect 1:1": (480, 480),
42
+ "480, aspect 16:9": (854, 480),
43
+ "480, aspect 9:16": (480, 854),
44
+ "480, aspect 4:3": (640, 480),
45
+ "480, aspect 3:4": (480, 640),
46
  }
47
 
 
 
 
 
 
48
 
49
  def polish_prompt_en(original_prompt):
50
 
 
67
  return polished_prompt
68
 
69
 
70
+ @spaces.GPU(duration=90)
71
  def infer(
72
  prompt,
73
  negative_prompt=" ",
74
  seed=42,
75
  randomize_seed=False,
76
+ aspect_ratio="480, aspect 3:4",
77
  guidance_scale=4,
78
  num_inference_steps=50,
79
  progress=gr.Progress(track_tqdm=True),
 
82
 
83
  if randomize_seed:
84
  seed = random.randint(0, MAX_SEED)
85
+
86
+ width, height = aspect_ratios[aspect_ratio]
87
 
88
  print("Generating for prompt:", prompt)
89
  image = pipe(
 
91
  negative_prompt=negative_prompt,
92
  width=width,
93
  height=height,
94
+ num_inference_steps=num_inference_steps,
95
+ true_cfg_scale=guidance_scale,
96
+ generator=torch.Generator(device="cuda").manual_seed(seed)
97
  ).images[0]
98
 
99
  #image.save("example.png")
 
127
  run_button = gr.Button("Run", scale=0, variant="primary")
128
 
129
  result = gr.Image(label="Result", show_label=False)
130
+ seed_output = gr.Textbox(label="Used seed", lines=1)
131
 
132
+ with gr.Accordion("Advanced Settings", open=True):
133
  negative_prompt = gr.Text(
134
  label="Negative prompt",
135
  max_lines=1,
 
148
  randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
149
 
150
  with gr.Row():
151
+ aspect_ratio = gr.Dropdown(
152
+ label="Image size (aprox.)",
153
  choices=list(aspect_ratios.keys()),
154
+ value="480, aspect 16:9",
155
  )
156
 
157
 
 
158
  with gr.Row():
159
  guidance_scale = gr.Slider(
160
  label="Guidance scale",
 
185
  guidance_scale,
186
  num_inference_steps,
187
  ],
188
+ outputs=[result, seed_output],
189
  )
190
 
191
  if __name__ == "__main__":