MCPcopy
hub / github.com/MeiGen-AI/InfiniteTalk / extend_with_img

Method extend_with_img

wan/utils/prompt_extend.py:464–523  ·  view source on GitHub ↗
(self,
                        prompt,
                        system_prompt,
                        image: Union[List[Image.Image], List[str], Image.Image,
                                     str] = None,
                        seed=-1,
                        *args,
                        **kwargs)

Source from the content-addressed store, hash-verified

462 ensure_ascii=False))
463
464 def extend_with_img(self,
465 prompt,
466 system_prompt,
467 image: Union[List[Image.Image], List[str], Image.Image,
468 str] = None,
469 seed=-1,
470 *args,
471 **kwargs):
472 self.model = self.model.to(self.device)
473
474 if not isinstance(image, (list, tuple)):
475 image = [image]
476
477 system_content = [{"type": "text", "text": system_prompt}]
478 role_content = [{
479 "type": "text",
480 "text": prompt
481 }, *[{
482 "image": image_path
483 } for image_path in image]]
484
485 messages = [{
486 'role': 'system',
487 'content': system_content,
488 }, {
489 "role": "user",
490 "content": role_content,
491 }]
492
493 # Preparation for inference
494 text = self.processor.apply_chat_template(
495 messages, tokenize=False, add_generation_prompt=True)
496 image_inputs, video_inputs = self.process_vision_info(messages)
497 inputs = self.processor(
498 text=[text],
499 images=image_inputs,
500 videos=video_inputs,
501 padding=True,
502 return_tensors="pt",
503 )
504 inputs = inputs.to(self.device)
505
506 # Inference: Generation of the output
507 generated_ids = self.model.generate(**inputs, max_new_tokens=512)
508 generated_ids_trimmed = [
509 out_ids[len(in_ids):]
510 for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
511 ]
512 expanded_prompt = self.processor.batch_decode(
513 generated_ids_trimmed,
514 skip_special_tokens=True,
515 clean_up_tokenization_spaces=False)[0]
516 self.model = self.model.to("cpu")
517 return PromptOutput(
518 status=True,
519 prompt=expanded_prompt,
520 seed=seed,
521 system_prompt=system_prompt,

Callers

nothing calls this directly

Calls 2

PromptOutputClass · 0.85
generateMethod · 0.45

Tested by

no test coverage detected