Support negative prompts

This commit is contained in:
cmdr2 2022-09-27 19:09:28 +05:30
parent 828a7aabd7
commit faf455a37c
5 changed files with 19 additions and 3 deletions

View File

@ -15,7 +15,7 @@
<div id="container"> <div id="container">
<div id="top-nav"> <div id="top-nav">
<div id="logo"> <div id="logo">
<h1>Stable Diffusion UI <small>v2.18 <span id="updateBranchLabel"></span></small></h1> <h1>Stable Diffusion UI <small>v2.19 <span id="updateBranchLabel"></span></small></h1>
</div> </div>
<ul id="top-nav-items"> <ul id="top-nav-items">
<li class="dropdown"> <li class="dropdown">
@ -153,6 +153,11 @@
<br/> <br/>
<li><b class="settings-subheader">Prompt Settings</b></li>
<li class="pl-5"><label for="negative_prompt">Negative Prompt:</label> <input id="negative_prompt" name="negative_prompt" size="55"></li>
<br/>
<li><b class="settings-subheader">Render Settings</b></li> <li><b class="settings-subheader">Render Settings</b></li>
<li class="pl-5"><input id="stream_image_progress" name="stream_image_progress" type="checkbox"> <label for="stream_image_progress">Show a live preview of the image <small>(uses more VRAM, slightly slower image creation)</small></label></li> <li class="pl-5"><input id="stream_image_progress" name="stream_image_progress" type="checkbox"> <label for="stream_image_progress">Show a live preview of the image <small>(uses more VRAM, slightly slower image creation)</small></label></li>
<li class="pl-5"><input id="use_face_correction" name="use_face_correction" type="checkbox" checked> <label for="use_face_correction">Fix incorrect faces and eyes <small>(uses GFPGAN)</small></label></li> <li class="pl-5"><input id="use_face_correction" name="use_face_correction" type="checkbox" checked> <label for="use_face_correction">Fix incorrect faces and eyes <small>(uses GFPGAN)</small></label></li>
@ -208,7 +213,7 @@
</div> </div>
</body> </body>
<script src="media/main.js?v=11"></script> <script src="media/main.js?v=12"></script>
<script> <script>
async function init() { async function init() {
await loadModifiers() await loadModifiers()

View File

@ -18,6 +18,7 @@ const IMAGE_REGEX = new RegExp('data:image/[A-Za-z]+;base64')
let sessionId = new Date().getTime() let sessionId = new Date().getTime()
let promptField = document.querySelector('#prompt') let promptField = document.querySelector('#prompt')
let negativePromptField = document.querySelector('#negative_prompt')
let numOutputsTotalField = document.querySelector('#num_outputs_total') let numOutputsTotalField = document.querySelector('#num_outputs_total')
let numOutputsParallelField = document.querySelector('#num_outputs_parallel') let numOutputsParallelField = document.querySelector('#num_outputs_parallel')
let numInferenceStepsField = document.querySelector('#num_inference_steps') let numInferenceStepsField = document.querySelector('#num_inference_steps')
@ -628,6 +629,7 @@ async function makeImage() {
let reqBody = { let reqBody = {
session_id: sessionId, session_id: sessionId,
prompt: prompt, prompt: prompt,
negative_prompt: negativePromptField.value.trim(),
num_outputs: batchSize, num_outputs: batchSize,
num_inference_steps: numInferenceStepsField.value, num_inference_steps: numInferenceStepsField.value,
guidance_scale: guidanceScaleField.value, guidance_scale: guidanceScaleField.value,
@ -672,6 +674,10 @@ async function makeImage() {
let taskConfig = `Seed: ${seed}, Sampler: ${reqBody['sampler']}, Inference Steps: ${numInferenceStepsField.value}, Guidance Scale: ${guidanceScaleField.value}` let taskConfig = `Seed: ${seed}, Sampler: ${reqBody['sampler']}, Inference Steps: ${numInferenceStepsField.value}, Guidance Scale: ${guidanceScaleField.value}`
if (negativePromptField.value.trim() !== '') {
taskConfig += `, Negative Prompt: ${negativePromptField.value.trim()}`
}
if (reqBody['init_image'] !== undefined) { if (reqBody['init_image'] !== undefined) {
taskConfig += `, Prompt Strength: ${promptStrengthField.value}` taskConfig += `, Prompt Strength: ${promptStrengthField.value}`
} }

View File

@ -3,6 +3,7 @@ import json
class Request: class Request:
session_id: str = "session" session_id: str = "session"
prompt: str = "" prompt: str = ""
negative_prompt: str = ""
init_image: str = None # base64 init_image: str = None # base64
mask: str = None # base64 mask: str = None # base64
num_outputs: int = 1 num_outputs: int = 1
@ -30,6 +31,7 @@ class Request:
return { return {
"session_id": self.session_id, "session_id": self.session_id,
"prompt": self.prompt, "prompt": self.prompt,
"negative_prompt": self.negative_prompt,
"num_outputs": self.num_outputs, "num_outputs": self.num_outputs,
"num_inference_steps": self.num_inference_steps, "num_inference_steps": self.num_inference_steps,
"guidance_scale": self.guidance_scale, "guidance_scale": self.guidance_scale,
@ -46,6 +48,7 @@ class Request:
return f''' return f'''
session_id: {self.session_id} session_id: {self.session_id}
prompt: {self.prompt} prompt: {self.prompt}
negative_prompt: {self.negative_prompt}
seed: {self.seed} seed: {self.seed}
num_inference_steps: {self.num_inference_steps} num_inference_steps: {self.num_inference_steps}
sampler: {self.sampler} sampler: {self.sampler}

View File

@ -343,7 +343,7 @@ def do_mk_img(req: Request):
modelCS.to(device) modelCS.to(device)
uc = None uc = None
if opt_scale != 1.0: if opt_scale != 1.0:
uc = modelCS.get_learned_conditioning(batch_size * [""]) uc = modelCS.get_learned_conditioning(batch_size * [req.negative_prompt])
if isinstance(prompts, tuple): if isinstance(prompts, tuple):
prompts = list(prompts) prompts = list(prompts)

View File

@ -39,6 +39,7 @@ app.mount('/media', StaticFiles(directory=os.path.join(SD_UI_DIR, 'media/')), na
class ImageRequest(BaseModel): class ImageRequest(BaseModel):
session_id: str = "session" session_id: str = "session"
prompt: str = "" prompt: str = ""
negative_prompt: str = ""
init_image: str = None # base64 init_image: str = None # base64
mask: str = None # base64 mask: str = None # base64
num_outputs: int = 1 num_outputs: int = 1
@ -100,6 +101,7 @@ def image(req : ImageRequest):
r = Request() r = Request()
r.session_id = req.session_id r.session_id = req.session_id
r.prompt = req.prompt r.prompt = req.prompt
r.negative_prompt = req.negative_prompt
r.init_image = req.init_image r.init_image = req.init_image
r.mask = req.mask r.mask = req.mask
r.num_outputs = req.num_outputs r.num_outputs = req.num_outputs