From ceb6915f313d13b208ca7e8e9d806c0aa5ca8884 Mon Sep 17 00:00:00 2001 From: fiatrete Date: Thu, 8 Jun 2023 10:53:55 +0800 Subject: [PATCH] Optimized the prompts for the stable-diffusion style, and now the style selection results are more in line with expectations. --- .../demo_modules/stable_diffusion.module.py | 20 ++++++++++++++----- .../demo_modules/stable_diffusion_params.json | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/example_modules/demo_modules/stable_diffusion.module.py b/example_modules/demo_modules/stable_diffusion.module.py index eea424c..195816a 100644 --- a/example_modules/demo_modules/stable_diffusion.module.py +++ b/example_modules/demo_modules/stable_diffusion.module.py @@ -118,13 +118,23 @@ Sometimes you maybe asked to generate a pic of myself. That means you MUST add ' {OTHER_SD_PARAMS_NAME: "If all above does not match, it should be this"}) async def determine_style(prompt: str): - gpt_system_prompt = "You are an AI designed to determine a 'style' of a sentence. I will give you a sentence," \ - " you should reply the which of the 'style' matches the sentence, all candidate of your " \ + # Replace 'style' with 'fact' when talking to GPT, since it may be confused by the word 'style' + gpt_system_prompt = "You are an AI designed to determine a 'fact' of a sentence. " \ + "I will give you a sentence, you should reply the which 'fact' matches the sentence. " \ + "You MUST reply ONLY the fact name with nothing else. All candidate of your " \ "answer are defined as following:\n'''\n" - for style, definition in stable_diffusion_all_style_definitions.items(): - gpt_system_prompt += f"{style}: {definition}.\n" + for fact, definition in stable_diffusion_all_style_definitions.items(): + gpt_system_prompt += f"<{fact}>: <{definition}>.\n" gpt_system_prompt += "'''\n" - gpt_system_prompt += "NOTE: You MUST reply ONLY the 'style name'." + gpt_system_prompt += f"""The following is the matching rule: +f''' +1. Checking fact from the first to the last. +2. Once all features described in a fact are satisfied by the sentence, this fact is considered 'match'. +3. Reply the first match. +4. If no fact match, reply '{OTHER_SD_PARAMS_NAME}' +''' +NOTE: Just reply using these information, don't ask me anything. +""" sys_prompt = {'role': 'system', 'content': gpt_system_prompt} messages = [sys_prompt, {'role': 'user', 'content': prompt}] diff --git a/example_modules/demo_modules/stable_diffusion_params.json b/example_modules/demo_modules/stable_diffusion_params.json index 27756f0..68b1564 100644 --- a/example_modules/demo_modules/stable_diffusion_params.json +++ b/example_modules/demo_modules/stable_diffusion_params.json @@ -22,7 +22,7 @@ "override_settings_restore_afterwards": false }, "girl drinking coffee": { - "DEFINITION": "Required features: A young female, she is drinking coffee", + "DEFINITION": "Required features: A young female. she is drinking coffee. the beverage MUST be coffee", "prompt": "photorealistic, (photorealistic:1.4), best quality, ultra detailed, ultra high res, masterpiece, realistic, 1girl, solo, full body, long_hair, looking at viewer, extremely detailed face, perfect lighting, from above, earrings, pov, pureerosface_v1, A girl with a great figure is wearing an off-the-shoulder dress, sitting in a caf\u00e9. Her long hair is flowing down her shoulders. It's daytime, and outside the window, cars are passing by. There are many people enjoying their coffee around her", "seed": -1, "sampler_name": "DPM++ SDE Karras",