MohamedRashad commited on
Commit
90c99b7
·
1 Parent(s): 2c55a9a

Update image generation pipeline by adding Autoencoder models and random seed for variability

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -18,13 +18,16 @@ from trellis.pipelines import TrellisImageTo3DPipeline
18
  from trellis.representations import Gaussian, MeshExtractResult
19
  from trellis.utils import render_utils, postprocessing_utils
20
  from gradio_client import Client
21
- from diffusers import FluxPipeline
22
  from live_preview_helpers import flux_pipe_call_that_returns_an_iterable_of_images
 
23
 
24
  llm_client = Client("Qwen/Qwen2.5-72B-Instruct")
25
 
26
  device = "cuda" if torch.cuda.is_available() else "cpu"
27
- pipe = FluxPipeline.from_pretrained("Freepik/flux.1-lite-8B-alpha", torch_dtype=torch.bfloat16).to(device)
 
 
28
  pipe.vae.enable_tiling()
29
  pipe.vae.enable_slicing()
30
  # pipe.enable_sequential_cpu_offload() # offloads modules to CPU on a submodule level (rather than model level)
@@ -85,17 +88,18 @@ def preprocess_pil_image(image: Image.Image) -> Tuple[str, Image.Image]:
85
  @spaces.GPU(duration=75)
86
  def generate_item_image(object_t2i_prompt):
87
  trial_id = ""
 
88
  for image in pipe.flux_pipe_call_that_returns_an_iterable_of_images(
89
  prompt=object_t2i_prompt,
90
  guidance_scale=3.5,
91
- num_inference_steps=1,
92
  width=512,
93
  height=512,
94
- generator=torch.Generator("cpu").manual_seed(0),
95
  output_type="pil",
 
96
  ):
97
  yield trial_id, image
98
- print("Yielded image")
99
 
100
  trial_id, processed_image = preprocess_pil_image(image)
101
  yield trial_id, processed_image
 
18
  from trellis.representations import Gaussian, MeshExtractResult
19
  from trellis.utils import render_utils, postprocessing_utils
20
  from gradio_client import Client
21
+ from diffusers import FluxPipeline, AutoencoderKL, AutoencoderTiny
22
  from live_preview_helpers import flux_pipe_call_that_returns_an_iterable_of_images
23
+ import random
24
 
25
  llm_client = Client("Qwen/Qwen2.5-72B-Instruct")
26
 
27
  device = "cuda" if torch.cuda.is_available() else "cpu"
28
+ taef1 = AutoencoderTiny.from_pretrained("madebyollin/taef1", torch_dtype=torch.bfloat16).to(device)
29
+ good_vae = AutoencoderKL.from_pretrained("Freepik/flux.1-lite-8B-alpha", subfolder="vae", torch_dtype=torch.bfloat16).to(device)
30
+ pipe = FluxPipeline.from_pretrained("Freepik/flux.1-lite-8B-alpha", torch_dtype=torch.bfloat16, vae=taef1).to(device)
31
  pipe.vae.enable_tiling()
32
  pipe.vae.enable_slicing()
33
  # pipe.enable_sequential_cpu_offload() # offloads modules to CPU on a submodule level (rather than model level)
 
88
  @spaces.GPU(duration=75)
89
  def generate_item_image(object_t2i_prompt):
90
  trial_id = ""
91
+ seed = random.randint(0, MAX_SEED)
92
  for image in pipe.flux_pipe_call_that_returns_an_iterable_of_images(
93
  prompt=object_t2i_prompt,
94
  guidance_scale=3.5,
95
+ num_inference_steps=28,
96
  width=512,
97
  height=512,
98
+ generator=torch.Generator().manual_seed(seed),
99
  output_type="pil",
100
+ good_vae=good_vae,
101
  ):
102
  yield trial_id, image
 
103
 
104
  trial_id, processed_image = preprocess_pil_image(image)
105
  yield trial_id, processed_image