| 515 | |
| 516 | |
| 517 | class ScribbleText2Image: |
| 518 | def __init__(self, device): |
| 519 | print(f"Initializing ScribbleText2Image to {device}") |
| 520 | self.torch_dtype = torch.float16 if 'cuda' in device else torch.float32 |
| 521 | self.controlnet = ControlNetModel.from_pretrained("fusing/stable-diffusion-v1-5-controlnet-scribble", |
| 522 | torch_dtype=self.torch_dtype) |
| 523 | self.pipe = StableDiffusionControlNetPipeline.from_pretrained( |
| 524 | "runwayml/stable-diffusion-v1-5", controlnet=self.controlnet, safety_checker=StableDiffusionSafetyChecker.from_pretrained('CompVis/stable-diffusion-safety-checker'), |
| 525 | torch_dtype=self.torch_dtype |
| 526 | ) |
| 527 | self.pipe.scheduler = UniPCMultistepScheduler.from_config(self.pipe.scheduler.config) |
| 528 | self.pipe.to(device) |
| 529 | self.seed = -1 |
| 530 | self.a_prompt = 'best quality, extremely detailed' |
| 531 | self.n_prompt = 'longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, ' \ |
| 532 | 'fewer digits, cropped, worst quality, low quality' |
| 533 | |
| 534 | @prompts(name="Generate Image Condition On Sketch Image", |
| 535 | description="useful when you want to generate a new real image from both the user description and " |
| 536 | "a scribble image or a sketch image. " |
| 537 | "The input to this tool should be a comma separated string of two, " |
| 538 | "representing the image_path and the user description") |
| 539 | def inference(self, inputs): |
| 540 | image_path, instruct_text = inputs.split(",")[0], ','.join(inputs.split(',')[1:]) |
| 541 | image = Image.open(image_path) |
| 542 | self.seed = random.randint(0, 65535) |
| 543 | seed_everything(self.seed) |
| 544 | prompt = f'{instruct_text}, {self.a_prompt}' |
| 545 | image = self.pipe(prompt, image, num_inference_steps=20, eta=0.0, negative_prompt=self.n_prompt, |
| 546 | guidance_scale=9.0).images[0] |
| 547 | updated_image_path = get_new_image_name(image_path, func_name="scribble2image") |
| 548 | image.save(updated_image_path) |
| 549 | print(f"\nProcessed ScribbleText2Image, Input Scribble: {image_path}, Input Text: {instruct_text}, " |
| 550 | f"Output Image: {updated_image_path}") |
| 551 | return updated_image_path |
| 552 | |
| 553 | |
| 554 | class Image2Pose: |
nothing calls this directly
no outgoing calls
no test coverage detected