frogleo commited on
Commit
c864180
·
verified ·
1 Parent(s): d46f000

Update app.py

Browse files

将输出文件webp改为jpg

Files changed (1) hide show
  1. app.py +16 -2
app.py CHANGED
@@ -7,6 +7,7 @@ import numpy as np
7
  import random
8
  import spaces
9
  import torch
 
10
  from diffusers import Flux2Pipeline, Flux2Transformer2DModel
11
  from diffusers import BitsAndBytesConfig as DiffBitsAndBytesConfig
12
  import requests
@@ -15,6 +16,7 @@ import json
15
  import base64
16
  from huggingface_hub import InferenceClient
17
 
 
18
  subprocess.check_call([sys.executable, "-m", "pip", "install", "spaces==0.43.0"])
19
 
20
  dtype = torch.bfloat16
@@ -80,6 +82,14 @@ pipe.to(device)
80
  # flash-attn估计库估计更新了,导致冲突了,不使用预编译的了
81
  # spaces.aoti_blocks_load(pipe.transformer, "zerogpu-aoti/FLUX.2", variant="fa3")
82
 
 
 
 
 
 
 
 
 
83
  def image_to_data_uri(img):
84
  buffered = io.BytesIO()
85
  img.save(buffered, format="PNG")
@@ -187,7 +197,11 @@ def generate_image(prompt_embeds, image_list, width, height, num_inference_steps
187
  height=height,
188
  callback_on_step_end=callback_fn,
189
  ).images[0]
190
- return image
 
 
 
 
191
 
192
  def infer(prompt, input_images=None, seed=42, randomize_seed=False, width=1024, height=1024, num_inference_steps=50, guidance_scale=2.5, prompt_upsampling=False, progress=gr.Progress()):
193
 
@@ -339,7 +353,7 @@ with gr.Blocks() as demo:
339
 
340
 
341
  with gr.Column():
342
- result = gr.Image(label="Result", show_label=False)
343
 
344
 
345
  gr.Examples(
 
7
  import random
8
  import spaces
9
  import torch
10
+ import uuid
11
  from diffusers import Flux2Pipeline, Flux2Transformer2DModel
12
  from diffusers import BitsAndBytesConfig as DiffBitsAndBytesConfig
13
  import requests
 
16
  import base64
17
  from huggingface_hub import InferenceClient
18
 
19
+
20
  subprocess.check_call([sys.executable, "-m", "pip", "install", "spaces==0.43.0"])
21
 
22
  dtype = torch.bfloat16
 
82
  # flash-attn估计库估计更新了,导致冲突了,不使用预编译的了
83
  # spaces.aoti_blocks_load(pipe.transformer, "zerogpu-aoti/FLUX.2", variant="fa3")
84
 
85
+ def save_image(image, output_dir):
86
+ filename = str(uuid.uuid4()) + ".jpg"
87
+ os.makedirs(output_dir, exist_ok=True)
88
+ filepath = os.path.join(output_dir, filename)
89
+ image.save(filepath, "JPEG", quality=80)
90
+ return filepath
91
+
92
+
93
  def image_to_data_uri(img):
94
  buffered = io.BytesIO()
95
  img.save(buffered, format="PNG")
 
197
  height=height,
198
  callback_on_step_end=callback_fn,
199
  ).images[0]
200
+
201
+ path = save_image(image, "./outputs")
202
+ progress(1, desc="Complete")
203
+
204
+ return path
205
 
206
  def infer(prompt, input_images=None, seed=42, randomize_seed=False, width=1024, height=1024, num_inference_steps=50, guidance_scale=2.5, prompt_upsampling=False, progress=gr.Progress()):
207
 
 
353
 
354
 
355
  with gr.Column():
356
+ result = gr.Image(label="Result",type="filepath", show_label=False)
357
 
358
 
359
  gr.Examples(