(text=None, no_input=False)
| 26 | |
| 27 | |
| 28 | def parse_input(text=None, no_input=False): |
| 29 | warnings.warn("Parsing input without negative prompt is deprecated.") |
| 30 | |
| 31 | if not text: |
| 32 | if no_input: |
| 33 | raise user_error(f"No input parsed in \"{text}\".") |
| 34 | |
| 35 | text = input("Enter the response: ") |
| 36 | if objects_text in text: |
| 37 | text = text.split(objects_text)[1] |
| 38 | |
| 39 | text_split = text.split(bg_prompt_text_no_trailing_space) |
| 40 | if len(text_split) == 2: |
| 41 | gen_boxes, bg_prompt = text_split |
| 42 | elif len(text_split) == 1: |
| 43 | if no_input: |
| 44 | raise user_error(f"Invalid input (no background prompt): {text}") |
| 45 | gen_boxes = text |
| 46 | bg_prompt = "" |
| 47 | while not bg_prompt: |
| 48 | # Ignore the empty lines in the response |
| 49 | bg_prompt = input("Enter the background prompt: ").strip() |
| 50 | if bg_prompt_text_no_trailing_space in bg_prompt: |
| 51 | bg_prompt = bg_prompt.split(bg_prompt_text_no_trailing_space)[1] |
| 52 | else: |
| 53 | raise user_error(f"Invalid input (possibly multiple background prompts): {text}") |
| 54 | try: |
| 55 | gen_boxes = ast.literal_eval(gen_boxes) |
| 56 | except SyntaxError as e: |
| 57 | # Sometimes the response is in plain text |
| 58 | if "No objects" in gen_boxes: |
| 59 | gen_boxes = [] |
| 60 | else: |
| 61 | raise e |
| 62 | bg_prompt = bg_prompt.strip() |
| 63 | |
| 64 | return gen_boxes, bg_prompt |
| 65 | |
| 66 | def parse_input_with_negative(text=None, no_input=False): |
| 67 | # no_input: should not request interactive input |
nothing calls this directly
no outgoing calls
no test coverage detected