Skip to content

Commit

Permalink
fix: on error parsing, fall back to "raw" prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
psychedelicious committed Oct 9, 2023
1 parent 5ac57ad commit 75d3ff4
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/compel/compel.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import torch
from torch import Tensor
from transformers import CLIPTokenizer, CLIPTextModel
from pyparsing.exceptions import ParseException

from . import cross_attention_control
from .conditioning_scheduler import ConditioningScheduler, StaticConditioningScheduler
Expand Down Expand Up @@ -155,7 +156,10 @@ def parse_prompt_string(cls, prompt_string: str) -> Conjunction:
Parse the given prompt string and return a structured Conjunction object that represents the prompt it contains.
"""
pp = PromptParser()
conjunction = pp.parse_conjunction(prompt_string)
try:
conjunction = pp.parse_conjunction(prompt_string)
except ParseException:
return Conjunction(prompts=[FlattenedPrompt([(prompt_string, 1.0)])], weights=[1.0])
return conjunction

def describe_tokenization(self, text: str) -> List[str]:
Expand Down

0 comments on commit 75d3ff4

Please sign in to comment.