MohamedRashad commited on
Commit
ccce713
·
1 Parent(s): bb07a1e

chore: Integrate live preview functionality in image enhancement pipeline

Browse files
Files changed (1) hide show
  1. app.py +20 -10
app.py CHANGED
@@ -3,7 +3,7 @@ from diffusers import FluxPriorReduxPipeline, FluxPipeline
3
  from diffusers.utils import load_image
4
  import gradio as gr
5
  import spaces
6
- # from live_preview_helpers import flux_pipe_call_that_returns_an_iterable_of_images
7
 
8
  pipe_prior_redux = FluxPriorReduxPipeline.from_pretrained("black-forest-labs/FLUX.1-Redux-dev", revision="refs/pr/8", torch_dtype=torch.bfloat16).to("cuda")
9
  pipe = FluxPipeline.from_pretrained(
@@ -11,26 +11,36 @@ pipe = FluxPipeline.from_pretrained(
11
  text_encoder=None,
12
  text_encoder_2=None,
13
  torch_dtype=torch.bfloat16
14
- )
15
- # pipe.flux_pipe_call_that_returns_an_iterable_of_images = flux_pipe_call_that_returns_an_iterable_of_images.__get__(pipe)
16
  # pipe.enable_sequential_cpu_offload()
17
 
18
- @spaces.GPU(duration=120)
19
  def enhance_image(image_path, keep_aspect_ratio=False):
20
  print(image_path)
21
  image = load_image(image_path)
22
  print(image.size)
23
  width, height = image.size if keep_aspect_ratio else (None, None)
24
  pipe_prior_output = pipe_prior_redux(image)
25
- images = pipe(
26
- height=height,
27
- width=width,
28
  guidance_scale=2.5,
29
  num_inference_steps=50,
 
 
30
  generator=torch.Generator("cpu").manual_seed(0),
31
- **pipe_prior_output,
32
- ).images
33
- return images[0]
 
 
 
 
 
 
 
 
 
 
34
 
35
 
36
  with gr.Blocks(title="Flux.1 Dev Redux") as demo:
 
3
  from diffusers.utils import load_image
4
  import gradio as gr
5
  import spaces
6
+ from live_preview_helpers import flux_pipe_call_that_returns_an_iterable_of_images
7
 
8
  pipe_prior_redux = FluxPriorReduxPipeline.from_pretrained("black-forest-labs/FLUX.1-Redux-dev", revision="refs/pr/8", torch_dtype=torch.bfloat16).to("cuda")
9
  pipe = FluxPipeline.from_pretrained(
 
11
  text_encoder=None,
12
  text_encoder_2=None,
13
  torch_dtype=torch.bfloat16
14
+ ).to("cuda")
15
+ pipe.flux_pipe_call_that_returns_an_iterable_of_images = flux_pipe_call_that_returns_an_iterable_of_images.__get__(pipe)
16
  # pipe.enable_sequential_cpu_offload()
17
 
18
+ @spaces.GPU
19
  def enhance_image(image_path, keep_aspect_ratio=False):
20
  print(image_path)
21
  image = load_image(image_path)
22
  print(image.size)
23
  width, height = image.size if keep_aspect_ratio else (None, None)
24
  pipe_prior_output = pipe_prior_redux(image)
25
+ for img in pipe.flux_pipe_call_that_returns_an_iterable_of_images(
 
 
26
  guidance_scale=2.5,
27
  num_inference_steps=50,
28
+ width=width,
29
+ height=height,
30
  generator=torch.Generator("cpu").manual_seed(0),
31
+ output_type="pil",
32
+ **pipe_prior_output
33
+ ):
34
+ yield img
35
+ # images = pipe(
36
+ # height=height,
37
+ # width=width,
38
+ # guidance_scale=2.5,
39
+ # num_inference_steps=50,
40
+ # generator=torch.Generator("cpu").manual_seed(0),
41
+ # **pipe_prior_output,
42
+ # ).images
43
+ # return images[0]
44
 
45
 
46
  with gr.Blocks(title="Flux.1 Dev Redux") as demo: