| 208 | |
| 209 | |
| 210 | def apply_refiner( |
| 211 | input, |
| 212 | state, |
| 213 | sampler, |
| 214 | num_samples, |
| 215 | prompt, |
| 216 | negative_prompt, |
| 217 | filter=None, |
| 218 | finish_denoising=False, |
| 219 | ): |
| 220 | init_dict = { |
| 221 | "orig_width": input.shape[3] * 8, |
| 222 | "orig_height": input.shape[2] * 8, |
| 223 | "target_width": input.shape[3] * 8, |
| 224 | "target_height": input.shape[2] * 8, |
| 225 | } |
| 226 | |
| 227 | value_dict = init_dict |
| 228 | value_dict["prompt"] = prompt |
| 229 | value_dict["negative_prompt"] = negative_prompt |
| 230 | |
| 231 | value_dict["crop_coords_top"] = 0 |
| 232 | value_dict["crop_coords_left"] = 0 |
| 233 | |
| 234 | value_dict["aesthetic_score"] = 6.0 |
| 235 | value_dict["negative_aesthetic_score"] = 2.5 |
| 236 | |
| 237 | st.warning(f"refiner input shape: {input.shape}") |
| 238 | samples = do_img2img( |
| 239 | input, |
| 240 | state["model"], |
| 241 | sampler, |
| 242 | value_dict, |
| 243 | num_samples, |
| 244 | skip_encode=True, |
| 245 | filter=filter, |
| 246 | add_noise=not finish_denoising, |
| 247 | ) |
| 248 | |
| 249 | return samples |
| 250 | |
| 251 | |
| 252 | if __name__ == "__main__": |