Skip to content

Commit

Permalink
✨ feat(controller): add option to hide long text in tagger response
Browse files Browse the repository at this point in the history
Added `hidden_long_text` parameter to `tagger` method to control
the display of long text responses. Updated relevant method calls
to include the new parameter.
  • Loading branch information
sudoskys committed Sep 28, 2024
1 parent 668cc58 commit 3ee3c95
Showing 1 changed file with 33 additions and 17 deletions.
50 changes: 33 additions & 17 deletions app/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,50 @@
StepCache = StateMemoryStorage()


def extract_between_multiple_markers(input_list, start_markers, end_markers):
extracting = False
extracted_elements = []
for item in input_list:
# Check if the item contains any start marker
if any(start_marker in item for start_marker in start_markers):
extracting = True
# continue # Skip appending the marker itself
if end_markers:
if any(end_marker in item for end_marker in end_markers):
break
if extracting:
extracted_elements.append(item)
return extracted_elements


async def read_a111(file: BytesIO):
try:
file.seek(0)
with Image.open(file) as img:
print(img.info)
parameter = img.info.get("parameters", None)
if not parameter:
raise Exception("Empty Parameter")
if isinstance(parameter, str):
parameter = parameter.split(",")
prompt = []
info = []
continue_flag = True
for p in parameter:
if p.count(":") > 0 and p.count("\n") > 0:
continue_flag = False
if continue_flag:
prompt.append(p)
else:
info.append(p.replace("\n", ""))
prompt = ",".join(prompt)
info = "\n".join(info)
parameter = f"{prompt}\n{info}"
if not isinstance(parameter, str):
parameter = str(parameter)
parameters = parameter.split(",")
prompt = extract_between_multiple_markers(
parameters, [""], ["Negative prompt:", "Steps:"]
)
negative_prompt = extract_between_multiple_markers(
parameters, ["Negative prompt:"], ["Steps:"]
)
info = extract_between_multiple_markers(parameters, ["Steps:"], None)
prompt = ",".join(prompt)
negative_prompt = ",".join(negative_prompt)
info = ",".join(info)
message = f"{prompt}\n{negative_prompt}\n{info}"
while "\n\n" in message:
message = message.replace("\n\n", "\n")
except Exception as e:
logger.debug(f"Error {e}")
return []
else:
return [f"📦 Prompt: \n>{parameter}\n"]
return [f"📦 Prompt: \n>{message}\n"]


async def read_comfyui(file: BytesIO):
Expand Down

0 comments on commit 3ee3c95

Please sign in to comment.