MCPcopy Create free account
hub / github.com/chenfei-wu/TaskMatrix / PoseText2Image

Class PoseText2Image

visual_chatgpt.py:572–609  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

570
571
572class PoseText2Image:
573 def __init__(self, device):
574 print(f"Initializing PoseText2Image to {device}")
575 self.torch_dtype = torch.float16 if 'cuda' in device else torch.float32
576 self.controlnet = ControlNetModel.from_pretrained("fusing/stable-diffusion-v1-5-controlnet-openpose",
577 torch_dtype=self.torch_dtype)
578 self.pipe = StableDiffusionControlNetPipeline.from_pretrained(
579 "runwayml/stable-diffusion-v1-5", controlnet=self.controlnet, safety_checker=StableDiffusionSafetyChecker.from_pretrained('CompVis/stable-diffusion-safety-checker'),
580 torch_dtype=self.torch_dtype)
581 self.pipe.scheduler = UniPCMultistepScheduler.from_config(self.pipe.scheduler.config)
582 self.pipe.to(device)
583 self.num_inference_steps = 20
584 self.seed = -1
585 self.unconditional_guidance_scale = 9.0
586 self.a_prompt = 'best quality, extremely detailed'
587 self.n_prompt = 'longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit,' \
588 ' fewer digits, cropped, worst quality, low quality'
589
590 @prompts(name="Generate Image Condition On Pose Image",
591 description="useful when you want to generate a new real image from both the user description "
592 "and a human pose image. "
593 "like: generate a real image of a human from this human pose image, "
594 "or generate a new real image of a human from this pose. "
595 "The input to this tool should be a comma separated string of two, "
596 "representing the image_path and the user description")
597 def inference(self, inputs):
598 image_path, instruct_text = inputs.split(",")[0], ','.join(inputs.split(',')[1:])
599 image = Image.open(image_path)
600 self.seed = random.randint(0, 65535)
601 seed_everything(self.seed)
602 prompt = f'{instruct_text}, {self.a_prompt}'
603 image = self.pipe(prompt, image, num_inference_steps=20, eta=0.0, negative_prompt=self.n_prompt,
604 guidance_scale=9.0).images[0]
605 updated_image_path = get_new_image_name(image_path, func_name="pose2image")
606 image.save(updated_image_path)
607 print(f"\nProcessed PoseText2Image, Input Pose: {image_path}, Input Text: {instruct_text}, "
608 f"Output Image: {updated_image_path}")
609 return updated_image_path
610
611class SegText2Image:
612 def __init__(self, device):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected