SkalskiP commited on
Commit
72d2b99
·
1 Parent(s): 7ea5176
Files changed (1) hide show
  1. app.py +19 -10
app.py CHANGED
@@ -17,7 +17,7 @@ for taking it to the next level by enabling inpainting with the FLUX.
17
  """
18
 
19
  MAX_SEED = np.iinfo(np.int32).max
20
- MAX_IMAGE_SIZE = 2048
21
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
22
 
23
  pipe = FluxInpaintPipeline.from_pretrained(
@@ -26,10 +26,15 @@ pipe = FluxInpaintPipeline.from_pretrained(
26
 
27
  def resize_image_dimensions(
28
  original_resolution_wh: Tuple[int, int],
29
- maximum_dimension: int = 2048
30
  ) -> Tuple[int, int]:
31
  width, height = original_resolution_wh
32
 
 
 
 
 
 
33
  if width > height:
34
  scaling_factor = maximum_dimension / width
35
  else:
@@ -41,13 +46,10 @@ def resize_image_dimensions(
41
  new_width = new_width - (new_width % 32)
42
  new_height = new_height - (new_height % 32)
43
 
44
- new_width = min(maximum_dimension, new_width)
45
- new_height = min(maximum_dimension, new_height)
46
-
47
  return new_width, new_height
48
 
49
 
50
- @spaces.GPU()
51
  def process(
52
  input_image_editor: dict,
53
  input_text: str,
@@ -79,7 +81,7 @@ def process(
79
  if randomize_seed_checkbox:
80
  seed_slicer = random.randint(0, MAX_SEED)
81
  generator = torch.Generator().manual_seed(seed_slicer)
82
- return pipe(
83
  prompt=input_text,
84
  image=resized_image,
85
  mask_image=resized_mask,
@@ -88,7 +90,9 @@ def process(
88
  strength=strength_slider,
89
  generator=generator,
90
  num_inference_steps=num_inference_steps_slider
91
- ).images[0], resized_mask
 
 
92
 
93
 
94
  with gr.Blocks() as demo:
@@ -120,7 +124,7 @@ with gr.Blocks() as demo:
120
  minimum=0,
121
  maximum=MAX_SEED,
122
  step=1,
123
- value=0,
124
  )
125
 
126
  randomize_seed_checkbox_component = gr.Checkbox(
@@ -129,14 +133,19 @@ with gr.Blocks() as demo:
129
  with gr.Row():
130
  strength_slider_component = gr.Slider(
131
  label="Strength",
 
 
 
132
  minimum=0,
133
  maximum=1,
134
  step=0.01,
135
- value=0.75,
136
  )
137
 
138
  num_inference_steps_slider_component = gr.Slider(
139
  label="Number of inference steps",
 
 
140
  minimum=1,
141
  maximum=50,
142
  step=1,
 
17
  """
18
 
19
  MAX_SEED = np.iinfo(np.int32).max
20
+ IMAGE_SIZE = 1024
21
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
22
 
23
  pipe = FluxInpaintPipeline.from_pretrained(
 
26
 
27
  def resize_image_dimensions(
28
  original_resolution_wh: Tuple[int, int],
29
+ maximum_dimension: int = IMAGE_SIZE
30
  ) -> Tuple[int, int]:
31
  width, height = original_resolution_wh
32
 
33
+ # if width <= maximum_dimension and height <= maximum_dimension:
34
+ # width = width - (width % 32)
35
+ # height = height - (height % 32)
36
+ # return width, height
37
+
38
  if width > height:
39
  scaling_factor = maximum_dimension / width
40
  else:
 
46
  new_width = new_width - (new_width % 32)
47
  new_height = new_height - (new_height % 32)
48
 
 
 
 
49
  return new_width, new_height
50
 
51
 
52
+ @spaces.GPU(duration=100)
53
  def process(
54
  input_image_editor: dict,
55
  input_text: str,
 
81
  if randomize_seed_checkbox:
82
  seed_slicer = random.randint(0, MAX_SEED)
83
  generator = torch.Generator().manual_seed(seed_slicer)
84
+ result = pipe(
85
  prompt=input_text,
86
  image=resized_image,
87
  mask_image=resized_mask,
 
90
  strength=strength_slider,
91
  generator=generator,
92
  num_inference_steps=num_inference_steps_slider
93
+ ).images[0]
94
+ print('INFERENCE DONE')
95
+ return result, resized_mask
96
 
97
 
98
  with gr.Blocks() as demo:
 
124
  minimum=0,
125
  maximum=MAX_SEED,
126
  step=1,
127
+ value=42,
128
  )
129
 
130
  randomize_seed_checkbox_component = gr.Checkbox(
 
133
  with gr.Row():
134
  strength_slider_component = gr.Slider(
135
  label="Strength",
136
+ info="Indicates extent to transform the reference `image`. "
137
+ "Must be between 0 and 1. `image` is used as a starting "
138
+ "point and more noise is added the higher the `strength`.",
139
  minimum=0,
140
  maximum=1,
141
  step=0.01,
142
+ value=0.85,
143
  )
144
 
145
  num_inference_steps_slider_component = gr.Slider(
146
  label="Number of inference steps",
147
+ info="The number of denoising steps. More denoising steps "
148
+ "usually lead to a higher quality image at the",
149
  minimum=1,
150
  maximum=50,
151
  step=1,