CrazyEric commited on
Commit
82290d4
1 Parent(s): 1eab256

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -21
app.py CHANGED
@@ -81,6 +81,17 @@ def process_text(prompt):
81
  print("prompt: \n", prompt_trans)
82
  return prompt_trans
83
 
 
 
 
 
 
 
 
 
 
 
 
84
 
85
  @spaces.GPU
86
  def generate(
@@ -119,8 +130,8 @@ def generate(
119
  return pipe(
120
  prompt=process_text(prompt),
121
  negative_prompt=process_text(negative_prompt),
122
- prompt_2=prompt_2,
123
- negative_prompt_2=negative_prompt_2,
124
  width=width,
125
  height=height,
126
  guidance_scale=guidance_scale_base,
@@ -132,8 +143,8 @@ def generate(
132
  latents = pipe(
133
  prompt=process_text(prompt),
134
  negative_prompt=process_text(negative_prompt),
135
- prompt_2=prompt_2,
136
- negative_prompt_2=negative_prompt_2,
137
  width=width,
138
  height=height,
139
  guidance_scale=guidance_scale_base,
@@ -144,8 +155,8 @@ def generate(
144
  image = refiner(
145
  prompt=process_text(prompt),
146
  negative_prompt=process_text(negative_prompt),
147
- prompt_2=prompt_2,
148
- negative_prompt_2=negative_prompt_2,
149
  guidance_scale=guidance_scale_refiner,
150
  num_inference_steps=num_inference_steps_refiner,
151
  image=latents,
@@ -177,6 +188,8 @@ with gr.Blocks(css="style.css") as demo:
177
  )
178
  run_button = gr.Button("生成", scale=0)
179
  result = gr.Image(label="生成结果", show_label=False)
 
 
180
  with gr.Accordion("高级选项", open=False):
181
  with gr.Row():
182
  use_negative_prompt = gr.Checkbox(label="使用反向提示词", value=False)
@@ -209,22 +222,28 @@ with gr.Blocks(css="style.css") as demo:
209
  value=0,
210
  )
211
  randomize_seed = gr.Checkbox(label="随机种子数", value=True)
212
- with gr.Row():
213
- width = gr.Slider(
214
- label="",
215
- minimum=256,
216
- maximum=MAX_IMAGE_SIZE,
217
- step=32,
218
- value=736,
219
- )
220
- height = gr.Slider(
221
- label="高",
222
- minimum=256,
223
- maximum=MAX_IMAGE_SIZE,
224
- step=32,
225
- value=1024,
226
- )
 
 
 
 
 
227
  apply_refiner = gr.Checkbox(label="增加精炼模型(refiner)", value=False, visible=ENABLE_REFINER)
 
228
  with gr.Row():
229
  guidance_scale_base = gr.Slider(
230
  label="提示词相关性",
@@ -256,7 +275,11 @@ with gr.Blocks(css="style.css") as demo:
256
  value=25,
257
  )
258
 
 
 
 
259
  gr.Examples(
 
260
  examples=examples,
261
  inputs=prompt,
262
  outputs=result,
 
81
  print("prompt: \n", prompt_trans)
82
  return prompt_trans
83
 
84
+ # 定义一个函数来处理图片尺寸的选择
85
+ def set_size(option):
86
+ if option == "横版":
87
+ width, height = 1024, 736
88
+ elif option == "竖版":
89
+ width, height = 736, 1024
90
+ elif option == "方形":
91
+ width, height = 736, 736
92
+ else:
93
+ width, height = 736, 1024 # 可以定义一个默认值
94
+ return width, height
95
 
96
  @spaces.GPU
97
  def generate(
 
130
  return pipe(
131
  prompt=process_text(prompt),
132
  negative_prompt=process_text(negative_prompt),
133
+ prompt_2=process_text(prompt_2),
134
+ negative_prompt_2=process_text(negative_prompt_2),
135
  width=width,
136
  height=height,
137
  guidance_scale=guidance_scale_base,
 
143
  latents = pipe(
144
  prompt=process_text(prompt),
145
  negative_prompt=process_text(negative_prompt),
146
+ prompt_2=process_text(prompt_2),
147
+ negative_prompt_2=process_text(negative_prompt_2),
148
  width=width,
149
  height=height,
150
  guidance_scale=guidance_scale_base,
 
155
  image = refiner(
156
  prompt=process_text(prompt),
157
  negative_prompt=process_text(negative_prompt),
158
+ prompt_2=process_text(prompt_2),
159
+ negative_prompt_2=process_text(negative_prompt_2),
160
  guidance_scale=guidance_scale_refiner,
161
  num_inference_steps=num_inference_steps_refiner,
162
  image=latents,
 
188
  )
189
  run_button = gr.Button("生成", scale=0)
190
  result = gr.Image(label="生成结果", show_label=False)
191
+
192
+
193
  with gr.Accordion("高级选项", open=False):
194
  with gr.Row():
195
  use_negative_prompt = gr.Checkbox(label="使用反向提示词", value=False)
 
222
  value=0,
223
  )
224
  randomize_seed = gr.Checkbox(label="随机种子数", value=True)
225
+
226
+ # 使用 Radio 组件替代两个 Slider 组件
227
+ size_option = gr.Radio(choices=["横版", "竖版", "方形"], label="选择尺寸", value="竖版")
228
+
229
+ # with gr.Row():
230
+ # width = gr.Slider(
231
+ # label="宽度",
232
+ # minimum=256,
233
+ # maximum=MAX_IMAGE_SIZE,
234
+ # step=32,
235
+ # value=736,
236
+ # )
237
+ # height = gr.Slider(
238
+ # label="高度",
239
+ # minimum=256,
240
+ # maximum=MAX_IMAGE_SIZE,
241
+ # step=32,
242
+ # value=1024,
243
+ # )
244
+
245
  apply_refiner = gr.Checkbox(label="增加精炼模型(refiner)", value=False, visible=ENABLE_REFINER)
246
+
247
  with gr.Row():
248
  guidance_scale_base = gr.Slider(
249
  label="提示词相关性",
 
275
  value=25,
276
  )
277
 
278
+ # 使用 size_option 的选择结果来动态设置 width 和 height 的值
279
+ size_option.change(fn=set_size, inputs=size_option, outputs=[width, height])
280
+
281
  gr.Examples(
282
+ label="例子"
283
  examples=examples,
284
  inputs=prompt,
285
  outputs=result,