idlebg commited on
Commit
6c21d5f
1 Parent(s): 442436d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -35
app.py CHANGED
@@ -95,7 +95,7 @@ def display_and_download_images(output_images, metadata):
95
 
96
  PIPELINE_NAMES = Literal["txt2img", "inpaint", "img2img"]
97
 
98
- DEFAULT_PROMPT = "sprinkled donut sitting on top of a purple cherry apple, colorful hyperrealism"
99
  DEFAULT_WIDTH, DEFAULT_HEIGHT = 512, 512
100
  OUTPUT_IMAGE_KEY = "output_img"
101
  LOADED_IMAGE_KEY = "loaded_image"
@@ -225,23 +225,30 @@ def generate(
225
 
226
 
227
  def prompt_and_generate_button(prefix, pipeline_name: PIPELINE_NAMES, **kwargs):
228
- prompt = st.text_area(
229
- "Prompt",
230
- value=DEFAULT_PROMPT,
231
- key=f"{prefix}-prompt",
232
- )
233
- negative_prompt = st.text_area(
234
- "Negative prompt",
235
- value="(disfigured), bad quality, ((bad art)), ((deformed)), ((extra limbs)), (((duplicate))), ((morbid)), (((ugly)), blurry, ((bad anatomy)), (((bad proportions))), cloned face, body out of frame, out of frame, bad anatomy, gross proportions, (malformed limbs), ((missing arms)), ((missing legs)), (((extra arms))), (((extra legs))), (fused fingers), (too many fingers), (((long neck))), Deformed, blurry",
236
- key=f"{prefix}-negative-prompt",
237
- )
238
  col1, col2 = st.columns(2)
239
  with col1:
240
- steps = st.slider("Number of inference steps", min_value=11, max_value=69, value=14, key=f"{prefix}-inference-steps")
 
 
 
 
241
  with col2:
242
- guidance_scale = st.slider(
243
- "Guidance scale", min_value=0.0, max_value=20.0, value=7.5, step=0.5, key=f"{prefix}-guidance-scale"
 
 
244
  )
 
 
 
 
 
 
 
 
 
 
245
  # Add a select box for the schedulers
246
  scheduler_name = st.selectbox(
247
  "Choose a Scheduler",
@@ -251,41 +258,35 @@ def prompt_and_generate_button(prefix, pipeline_name: PIPELINE_NAMES, **kwargs):
251
  )
252
  scheduler_class = AVAILABLE_SCHEDULERS[scheduler_name] # Get the selected scheduler class
253
 
254
-
255
  pipe = get_pipeline(pipeline_name, scheduler_name=scheduler_name)
256
-
257
- # enable_attention_slicing = st.checkbox('Enable attention slicing (enables higher resolutions but is slower)', key=f"{prefix}-attention-slicing", value=True)
258
- # enable_xformers = st.checkbox('Enable xformers library (better memory usage)', key=f"{prefix}-xformers", value=True)
259
- num_images = st.slider("Number of images to generate", min_value=1, max_value=4, value=1, key=f"{prefix}-num-images")
260
 
261
  images = []
262
 
263
-
264
  if st.button("Generate images", key=f"{prefix}-btn"):
265
  with st.spinner("Generating image..."):
266
  images = generate(
267
  prompt,
268
  pipeline_name,
269
- num_images=num_images, # add this
270
  negative_prompt=negative_prompt,
271
  steps=steps,
272
  guidance_scale=guidance_scale,
273
- enable_attention_slicing=True, # value always set to True
274
- enable_xformers=True, # value always set to True
275
  **kwargs,
276
  )
277
-
278
- for i, image in enumerate(images): # loop over each image
279
- set_image(f"{OUTPUT_IMAGE_KEY}_{i}", image.copy()) # save each image with a unique key
280
-
281
-
282
- image_indices = [int(key.split('_')[-1]) for key in st.session_state.keys() if OUTPUT_IMAGE_KEY in key]
283
- cols = st.columns(len(image_indices) if image_indices else 1) # create a column for each image or a single one if no images
284
- for i in range(max(image_indices) + 1 if image_indices else 1): # loop over each image index
285
- output_image_key = f"{OUTPUT_IMAGE_KEY}_{i}"
286
- output_image = get_image(output_image_key)
287
- if output_image:
288
- cols[i].image(output_image)
289
 
290
 
291
 
 
95
 
96
  PIPELINE_NAMES = Literal["txt2img", "inpaint", "img2img"]
97
 
98
+ DEFAULT_PROMPT = "sprinkled donut sitting on top of a green cherry and pink apple, colorful hyperrealism"
99
  DEFAULT_WIDTH, DEFAULT_HEIGHT = 512, 512
100
  OUTPUT_IMAGE_KEY = "output_img"
101
  LOADED_IMAGE_KEY = "loaded_image"
 
225
 
226
 
227
  def prompt_and_generate_button(prefix, pipeline_name: PIPELINE_NAMES, **kwargs):
228
+ # Change 1: Prompt and Negative prompt to be on 1 line split like width and high (2 columns)
 
 
 
 
 
 
 
 
 
229
  col1, col2 = st.columns(2)
230
  with col1:
231
+ prompt = st.text_area(
232
+ "Prompt",
233
+ value=DEFAULT_PROMPT,
234
+ key=f"{prefix}-prompt",
235
+ )
236
  with col2:
237
+ negative_prompt = st.text_area(
238
+ "Negative prompt",
239
+ value="(disfigured), bad quality, ((bad art)), ((deformed)), ((extra limbs)), (((duplicate))), ((morbid)), (((ugly)), blurry, ((bad anatomy)), (((bad proportions))), (malformed limbs), ((missing arms)), ((missing legs)), (((extra arms))), (((extra legs))), (fused fingers), (too many fingers), (((long neck))), Deformed, blurry"
240
+ key=f"{prefix}-negative-prompt",
241
  )
242
+
243
+ # Change 2: Number of inference steps, Guidance scale, and Number of images to generate to be in a line, 3 columns
244
+ col1, col2, col3 = st.columns(3)
245
+ with col1:
246
+ steps = st.slider("Number of inference steps", min_value=11, max_value=69, value=14, key=f"{prefix}-inference-steps")
247
+ with col2:
248
+ guidance_scale = st.slider("Guidance scale", min_value=0.0, max_value=20.0, value=7.5, step=0.5, key=f"{prefix}-guidance-scale")
249
+ with col3:
250
+ num_images = st.slider("Number of images to generate", min_value=1, max_value=2, value=1, key=f"{prefix}-num-images")
251
+
252
  # Add a select box for the schedulers
253
  scheduler_name = st.selectbox(
254
  "Choose a Scheduler",
 
258
  )
259
  scheduler_class = AVAILABLE_SCHEDULERS[scheduler_name] # Get the selected scheduler class
260
 
 
261
  pipe = get_pipeline(pipeline_name, scheduler_name=scheduler_name)
262
+
263
+ # enable_attention_slicing = st.checkbox('Enable attention slicing (enables higher resolutions but is slower)', key=f"{prefix}-attention-slicing", value=True)
264
+ # enable_xformers = st.checkbox('Enable xformers library (better memory usage)', key=f"{prefix}-xformers", value=True)
 
265
 
266
  images = []
267
 
 
268
  if st.button("Generate images", key=f"{prefix}-btn"):
269
  with st.spinner("Generating image..."):
270
  images = generate(
271
  prompt,
272
  pipeline_name,
273
+ num_images=num_images, # add this
274
  negative_prompt=negative_prompt,
275
  steps=steps,
276
  guidance_scale=guidance_scale,
277
+ enable_attention_slicing=True, # value always set to True
278
+ enable_xformers=True, # value always set to True
279
  **kwargs,
280
  )
281
+ for i, image in enumerate(images): # loop over each image
282
+ set_image(f"{OUTPUT_IMAGE_KEY}_{i}", image.copy()) # save each image with a unique key
283
+ image_indices = [int(key.split('_')[-1]) for key in st.session_state.keys() if OUTPUT_IMAGE_KEY in key]
284
+ cols = st.columns(len(image_indices) if image_indices else 1) # create a column for each image or a single one if no images
285
+ for i in range(max(image_indices) + 1 if image_indices else 1): # loop over each image index
286
+ output_image_key = f"{OUTPUT_IMAGE_KEY}_{i}"
287
+ output_image = get_image(output_image_key)
288
+ if output_image:
289
+ cols[i].image(output_image)
 
 
 
290
 
291
 
292