linoyts HF Staff commited on
Commit
7577000
·
verified ·
1 Parent(s): 00ce5e1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -3
app.py CHANGED
@@ -64,6 +64,7 @@ default_negative_prompt = "色调艳丽, 过曝, 静态, 细节模糊不清, 字
64
 
65
  def get_duration(
66
  prompt,
 
67
  negative_prompt,
68
  guidance_scale,
69
  guidance_scale_2,
@@ -77,6 +78,7 @@ def get_duration(
77
  @spaces.GPU(duration=get_duration)
78
  def generate_image(
79
  prompt,
 
80
  negative_prompt=default_negative_prompt,
81
  guidance_scale = 3.5,
82
  guidance_scale_2 = 4,
@@ -93,6 +95,7 @@ def generate_image(
93
 
94
  Args:
95
  prompt (str): Text prompt describing the desired image.
 
96
  negative_prompt (str, optional): Negative prompt to avoid unwanted elements.
97
  Defaults to default_negative_prompt (contains unwanted visual artifacts).
98
  guidance_scale (float, optional): Controls adherence to the prompt. Higher values = more adherence.
@@ -123,11 +126,21 @@ def generate_image(
123
 
124
  current_seed = random.randint(0, MAX_SEED) if randomize_seed else int(seed)
125
 
 
 
 
 
 
 
 
 
 
 
126
  out_img = pipe(
127
  prompt=prompt,
128
  negative_prompt=negative_prompt,
129
- height=1024,
130
- width=1024,
131
  num_frames=1,
132
  guidance_scale=float(guidance_scale),
133
  guidance_scale_2=float(guidance_scale_2),
@@ -154,6 +167,7 @@ with gr.Blocks(css=css) as demo:
154
  container=False,)
155
  generate_button = gr.Button("Run", variant="primary", scale=0)
156
  img_output = gr.Image(label="Generated Image", interactive=False)
 
157
  with gr.Accordion("Advanced Settings", open=False):
158
  negative_prompt_input = gr.Textbox(label="Negative Prompt", value=default_negative_prompt, lines=3)
159
  seed_input = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=42, interactive=True)
@@ -176,7 +190,7 @@ with gr.Blocks(css=css) as demo:
176
  ],
177
  inputs=[prompt_input], outputs=[img_output, seed_input], fn=generate_image, cache_examples="lazy")
178
  ui_inputs = [
179
- prompt_input,
180
  negative_prompt_input,
181
  guidance_scale_input, guidance_scale_2_input, steps_slider, seed_input, randomize_seed_checkbox
182
  ]
 
64
 
65
  def get_duration(
66
  prompt,
67
+ img_size,
68
  negative_prompt,
69
  guidance_scale,
70
  guidance_scale_2,
 
78
  @spaces.GPU(duration=get_duration)
79
  def generate_image(
80
  prompt,
81
+ img_size,
82
  negative_prompt=default_negative_prompt,
83
  guidance_scale = 3.5,
84
  guidance_scale_2 = 4,
 
95
 
96
  Args:
97
  prompt (str): Text prompt describing the desired image.
98
+ img_size (str): size and orientation of output image, choices are square(1024), portrait(1024,576), landscape(576,1024).
99
  negative_prompt (str, optional): Negative prompt to avoid unwanted elements.
100
  Defaults to default_negative_prompt (contains unwanted visual artifacts).
101
  guidance_scale (float, optional): Controls adherence to the prompt. Higher values = more adherence.
 
126
 
127
  current_seed = random.randint(0, MAX_SEED) if randomize_seed else int(seed)
128
 
129
+ if img_size == "square":
130
+ height=1024
131
+ width=1024
132
+ elif img_size == "portrait":
133
+ height=1024
134
+ width=576
135
+ else: #landscape
136
+ height=576
137
+ width=1024
138
+
139
  out_img = pipe(
140
  prompt=prompt,
141
  negative_prompt=negative_prompt,
142
+ height=height,
143
+ width=width,
144
  num_frames=1,
145
  guidance_scale=float(guidance_scale),
146
  guidance_scale_2=float(guidance_scale_2),
 
167
  container=False,)
168
  generate_button = gr.Button("Run", variant="primary", scale=0)
169
  img_output = gr.Image(label="Generated Image", interactive=False)
170
+ img_size= gr.Radio(choices=["square", "portrait", "landscape"], value="square", label="Image Size")
171
  with gr.Accordion("Advanced Settings", open=False):
172
  negative_prompt_input = gr.Textbox(label="Negative Prompt", value=default_negative_prompt, lines=3)
173
  seed_input = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=42, interactive=True)
 
190
  ],
191
  inputs=[prompt_input], outputs=[img_output, seed_input], fn=generate_image, cache_examples="lazy")
192
  ui_inputs = [
193
+ prompt_input,img_size,
194
  negative_prompt_input,
195
  guidance_scale_input, guidance_scale_2_input, steps_slider, seed_input, randomize_seed_checkbox
196
  ]