(
state,
version_dict,
is_legacy=False,
return_latents=False,
filter=None,
stage2strength=None,
)
| 160 | |
| 161 | |
| 162 | def run_img2img( |
| 163 | state, |
| 164 | version_dict, |
| 165 | is_legacy=False, |
| 166 | return_latents=False, |
| 167 | filter=None, |
| 168 | stage2strength=None, |
| 169 | ): |
| 170 | img = load_img() |
| 171 | if img is None: |
| 172 | return None |
| 173 | H, W = img.shape[2], img.shape[3] |
| 174 | |
| 175 | init_dict = { |
| 176 | "orig_width": W, |
| 177 | "orig_height": H, |
| 178 | "target_width": W, |
| 179 | "target_height": H, |
| 180 | } |
| 181 | value_dict = init_embedder_options( |
| 182 | get_unique_embedder_keys_from_conditioner(state["model"].conditioner), |
| 183 | init_dict, |
| 184 | prompt=prompt, |
| 185 | negative_prompt=negative_prompt, |
| 186 | ) |
| 187 | strength = st.number_input( |
| 188 | "**Img2Img Strength**", value=0.75, min_value=0.0, max_value=1.0 |
| 189 | ) |
| 190 | sampler, num_rows, num_cols = init_sampling( |
| 191 | img2img_strength=strength, |
| 192 | stage2strength=stage2strength, |
| 193 | ) |
| 194 | num_samples = num_rows * num_cols |
| 195 | |
| 196 | if st.button("Sample"): |
| 197 | out = do_img2img( |
| 198 | repeat(img, "1 ... -> n ...", n=num_samples), |
| 199 | state["model"], |
| 200 | sampler, |
| 201 | value_dict, |
| 202 | num_samples, |
| 203 | force_uc_zero_embeddings=["txt"] if not is_legacy else [], |
| 204 | return_latents=return_latents, |
| 205 | filter=filter, |
| 206 | ) |
| 207 | return out |
| 208 | |
| 209 | |
| 210 | def apply_refiner( |
no test coverage detected