Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with negative prompts and allow model_name argument #63

Merged
merged 6 commits into from
Aug 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions diffusion/inference/inference_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ class StableDiffusionInference():
Default: ``None``.
"""

def __init__(self, pretrained: bool = False, prediction_type: str = 'epsilon'):
def __init__(self,
model_name: str = 'stabilityai/stable-diffusion-2-base',
pretrained: bool = False,
prediction_type: str = 'epsilon'):
self.device = torch.cuda.current_device()

model = stable_diffusion_2(
model_name=model_name,
pretrained=pretrained,
prediction_type=prediction_type,
encode_latents_in_fp16=True,
Expand Down Expand Up @@ -68,12 +72,14 @@ def predict(self, model_requests: List[Dict[str, Any]]):
# Prompts and negative prompts if available
if isinstance(inputs, str):
prompts.append(inputs)
elif isinstance(input, Dict):
if 'prompt' not in req:
elif isinstance(inputs, Dict):
if 'prompt' not in inputs:
raise RuntimeError('"prompt" must be provided to generate call if using a dict as input')
prompts.append(inputs['prompt'])
if 'negative_prompt' in req:
if 'negative_prompt' in inputs:
negative_prompts.append(inputs['negative_prompt'])
else:
raise RuntimeError(f'Input must be of type string or dict, but it is type: {type(inputs)}')

generate_kwargs = req['parameters']

Expand Down