SkalskiP commited on
Commit
a92a3f1
·
1 Parent(s): 347ca4d
Files changed (1) hide show
  1. app.py +16 -40
app.py CHANGED
@@ -60,33 +60,6 @@ def set_client_for_session(request: gr.Request):
60
 
61
 
62
  @spaces.GPU(duration=100)
63
- def run_flux(
64
- image: Image.Image,
65
- mask: Image.Image,
66
- inpainting_prompt_text: str,
67
- seed_slicer: int,
68
- randomize_seed_checkbox: bool,
69
- strength_slider: float,
70
- num_inference_steps_slider: int,
71
- width: int,
72
- height: int,
73
- progress=gr.Progress(track_tqdm=True)
74
- ) -> Image.Image:
75
- if randomize_seed_checkbox:
76
- seed_slicer = random.randint(0, MAX_SEED)
77
- generator = torch.Generator().manual_seed(seed_slicer)
78
- return pipe(
79
- prompt=inpainting_prompt_text,
80
- image=image,
81
- mask_image=mask,
82
- width=width,
83
- height=height,
84
- strength=strength_slider,
85
- generator=generator,
86
- num_inference_steps=num_inference_steps_slider
87
- ).images[0]
88
-
89
-
90
  def process(
91
  client,
92
  input_image_editor: dict,
@@ -129,21 +102,24 @@ def process(
129
 
130
  mask = mask.filter(ImageFilter.GaussianBlur(radius=5))
131
  width, height = resize_image_dimensions(original_resolution_wh=image.size)
132
- image = image.resize((width, height), Image.LANCZOS)
133
- mask = mask.resize((width, height), Image.LANCZOS)
134
- result = run_flux(
135
- image=image,
136
- mask=mask,
137
- inpainting_prompt_text=inpainting_prompt_text,
138
- seed_slicer=seed_slicer,
139
- randomize_seed_checkbox=randomize_seed_checkbox,
140
- strength_slider=strength_slider,
141
- num_inference_steps_slider=num_inference_steps_slider,
142
  width=width,
143
  height=height,
144
- progress=progress
145
- )
146
- return result, mask
 
 
 
147
 
148
 
149
  with gr.Blocks() as demo:
 
60
 
61
 
62
  @spaces.GPU(duration=100)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  def process(
64
  client,
65
  input_image_editor: dict,
 
102
 
103
  mask = mask.filter(ImageFilter.GaussianBlur(radius=5))
104
  width, height = resize_image_dimensions(original_resolution_wh=image.size)
105
+ resized_image = image.resize((width, height), Image.LANCZOS)
106
+ resized_mask = mask.resize((width, height), Image.LANCZOS)
107
+
108
+ if randomize_seed_checkbox:
109
+ seed_slicer = random.randint(0, MAX_SEED)
110
+ generator = torch.Generator().manual_seed(seed_slicer)
111
+ result = pipe(
112
+ prompt=inpainting_prompt_text,
113
+ image=resized_image,
114
+ mask_image=resized_mask,
115
  width=width,
116
  height=height,
117
+ strength=strength_slider,
118
+ generator=generator,
119
+ num_inference_steps=num_inference_steps_slider
120
+ ).images[0]
121
+ print('INFERENCE DONE')
122
+ return result, resized_mask
123
 
124
 
125
  with gr.Blocks() as demo: