Skip to content

Commit

Permalink
[Enhance] add negative prompt for sd inferencer (open-mmlab#2021)
Browse files Browse the repository at this point in the history
add negative prompt for sd
  • Loading branch information
liuwenran committed Sep 7, 2023
1 parent 332c2c2 commit bced86e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions mmagic/apis/inferencers/text2image_inferencer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,23 @@ class Text2ImageInferencer(BaseMMagicInferencer):
"""inferencer that predicts with text2image models."""

func_kwargs = dict(
preprocess=['text', 'control'],
preprocess=['text', 'control', 'negative_prompt'],
forward=[],
visualize=['result_out_dir'],
postprocess=[])

extra_parameters = dict(height=None, width=None, seed=1)

def preprocess(self, text: InputsType, control: str = None) -> Dict:
def preprocess(self,
text: InputsType,
control: str = None,
negative_prompt: InputsType = None) -> Dict:
"""Process the inputs into a model-feedable format.
Args:
text(InputsType): text input for text-to-image model.
control(str): control img dir for controlnet.
negative_prompt(InputsType): negative prompt.
Returns:
result(Dict): Results of preprocess.
Expand All @@ -43,6 +48,9 @@ def preprocess(self, text: InputsType, control: str = None) -> Dict:
result['control'] = control_img
result.pop('seed', None)

if negative_prompt:
result['negative_prompt'] = negative_prompt

return result

def forward(self, inputs: InputsType) -> PredType:
Expand Down

0 comments on commit bced86e

Please sign in to comment.