| 316 | ) |
| 317 | |
| 318 | def text_preprocessing(text, clean_caption=False): |
| 319 | if clean_caption and not is_bs4_available(): |
| 320 | clean_caption = False |
| 321 | |
| 322 | if clean_caption and not is_ftfy_available(): |
| 323 | clean_caption = False |
| 324 | |
| 325 | if not isinstance(text, (tuple, list)): |
| 326 | text = [text] |
| 327 | |
| 328 | def process(text: str): |
| 329 | if clean_caption: |
| 330 | text = clean_caption(text) |
| 331 | text = clean_caption(text) |
| 332 | else: |
| 333 | text = text.lower().strip() |
| 334 | return text |
| 335 | |
| 336 | return [process(t) for t in text] |
| 337 | |
| 338 | # Copied from diffusers.pipelines.deepfloyd_if.pipeline_if.IFPipeline._clean_caption |
| 339 | def clean_caption(caption): |