nsfwalex commited on
Commit
7c4ee69
1 Parent(s): 3788f6b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -6
app.py CHANGED
@@ -187,9 +187,20 @@ desc_html='''
187
  </div>
188
  '''
189
  def save_image(img):
190
- unique_name = str(uuid.uuid4()) + ".png"
191
- img.save(unique_name)
192
- return unique_name
 
 
 
 
 
 
 
 
 
 
 
193
 
194
  def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
195
  if randomize_seed:
@@ -223,10 +234,10 @@ def generate(prompt, progress=gr.Progress(track_tqdm=True)):
223
  num_images_per_prompt=NUM_IMAGES_PER_PROMPT,
224
  output_type="pil",
225
  ).images
226
-
227
- image_paths = [save_image(img) for img in images]
228
  print(prompt_str, image_paths)
229
- return image_paths
230
 
231
  with gr.Blocks(css=css,head=js,fill_height=True) as demo:
232
  with gr.Row(equal_height=False):
 
187
  </div>
188
  '''
189
  def save_image(img):
190
+ # Generate a unique filename
191
+ unique_name = str(uuid.uuid4()) + ".webp"
192
+
193
+ # Convert the image to WebP format
194
+ webp_img = img.convert("RGB") # Ensure the image is in RGB mode
195
+
196
+ # Save the image in WebP format with high quality
197
+ webp_img.save(unique_name, "WEBP", quality=90)
198
+
199
+ # Open the saved WebP file and return it as a PIL Image object
200
+ with Image.open(unique_name) as webp_file:
201
+ webp_image = webp_file.copy()
202
+
203
+ return webp_image, unique_name
204
 
205
  def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
206
  if randomize_seed:
 
234
  num_images_per_prompt=NUM_IMAGES_PER_PROMPT,
235
  output_type="pil",
236
  ).images
237
+ images = [save_image(img) for img in images]
238
+ image_paths = [i[1] for i in images]
239
  print(prompt_str, image_paths)
240
+ return [i[0] for i in images]
241
 
242
  with gr.Blocks(css=css,head=js,fill_height=True) as demo:
243
  with gr.Row(equal_height=False):