[FE] Adds to allow to generate private images

This commit is contained in:
HappyZ 2023-05-25 13:20:16 -07:00
parent 00fdf87345
commit b027f4a600
4 changed files with 28 additions and 5 deletions

View File

@ -20,6 +20,11 @@
<label for="apiKey" class="input-group-text" data-en_XX="API Key" data-zh_CN="API 密钥">API
Key</label>
<input type="password" class="form-control" id="apiKey" value="">
<div class="input-group-text">
<input class="form-check-input" type="checkbox" value="" id="isPrivate" value="">
</div>
<label for="isPrivate" class="input-group-text" data-en_XX="Generate Private Images"
data-zh_CN="生成非公开图片">Generate Private Images</label>
</div>
</div>
<div class="col-md-4 mb-3">
@ -702,7 +707,8 @@
'height': heightVal,
'lang': $("#language option:selected").val(),
'guidance_scale': guidanceScaleVal,
'neg_prompt': negPromptVal
'neg_prompt': negPromptVal,
'is_private': $('#isPrivate').is(":checked") ? 1 : 0
}),
success: function (response) {
console.log(response);
@ -814,7 +820,8 @@
'lang': $("#language option:selected").val(),
'guidance_scale': guidanceScaleVal,
'strength': strengthVal,
'neg_prompt': negPromptVal
'neg_prompt': negPromptVal,
'is_private': $('#isPrivate').is(":checked") ? 1 : 0
}),
success: function (response) {
console.log(response);
@ -943,7 +950,8 @@
'height': heightVal,
'lang': $("#language option:selected").val(),
'guidance_scale': guidanceScaleVal,
'neg_prompt': negPromptVal
'neg_prompt': negPromptVal,
'is_private': $('#isPrivate').is(":checked") ? 1 : 0
}),
success: function (response) {
console.log(response);

View File

@ -11,6 +11,7 @@ from utilities.constants import VALUE_HEIGHT_DEFAULT
from utilities.constants import KEY_STRENGTH
from utilities.constants import VALUE_STRENGTH_DEFAULT
from utilities.constants import KEY_SCHEDULER
from utilities.constants import KEY_IS_PRIVATE
from utilities.constants import VALUE_SCHEDULER_DEFAULT
from utilities.constants import VALUE_SCHEDULER_DDIM
from utilities.constants import VALUE_SCHEDULER_DPM_SOLVER_MULTISTEP
@ -58,6 +59,17 @@ class Config:
self.__config[KEY_OUTPUT_FOLDER] = folder
return self
def get_is_private(self) -> bool:
return bool(self.__config.get(KEY_IS_PRIVATE, False))
def set_is_private(self, private: bool) -> bool:
self.__logger.info(
"{} changed from {} to {}".format(
KEY_IS_PRIVATE, self.get_is_private(), private
)
)
self.__config[KEY_IS_PRIVATE] = private
def get_guidance_scale(self) -> float:
return float(
self.__config.get(KEY_GUIDANCE_SCALE, VALUE_GUIDANCE_SCALE_DEFAULT)

View File

@ -57,6 +57,7 @@ VALUE_SCHEDULER_PNDM = "PNDMScheduler"
VALUE_SCHEDULER_DDIM = "DDIMScheduler"
KEY_STRENGTH = "strength"
VALUE_STRENGTH_DEFAULT = 0.5 # default value for KEY_STRENGTH
KEY_IS_PRIVATE = "is_private"
REQUIRED_KEYS = [
APIKEY, # str
@ -75,6 +76,7 @@ OPTIONAL_KEYS = [
REFERENCE_IMG, # str (base64 or filepath)
MASK_IMG, # str (base64 or filepath)
KEY_LANGUAGE, # str
KEY_IS_PRIVATE, # boolean
]
# - output only

View File

@ -7,6 +7,7 @@ import uuid
from utilities.constants import APIKEY
from utilities.constants import UUID
from utilities.constants import KEY_PRIORITY
from utilities.constants import KEY_IS_PRIVATE
from utilities.constants import KEY_JOB_TYPE
from utilities.constants import VALUE_JOB_TXT2IMG
from utilities.constants import VALUE_JOB_IMG2IMG
@ -129,11 +130,11 @@ class Database:
return result[0]
def get_random_jobs(self, limit_count=0) -> list:
query = f"SELECT {', '.join(ANONYMOUS_KEYS)} FROM {HISTORY_TABLE_NAME} WHERE {KEY_JOB_STATUS} = '{VALUE_JOB_DONE}' AND rowid IN (SELECT rowid FROM {HISTORY_TABLE_NAME} ORDER BY RANDOM() LIMIT {limit_count})"
query = f"SELECT {', '.join(ANONYMOUS_KEYS)} FROM {HISTORY_TABLE_NAME} WHERE {KEY_JOB_STATUS} = ? AND {KEY_IS_PRIVATE} = ? AND rowid IN (SELECT rowid FROM {HISTORY_TABLE_NAME} ORDER BY RANDOM() LIMIT ?)"
# execute the query and return the results
c = self.get_cursor()
rows = c.execute(query).fetchall()
rows = c.execute(query, (VALUE_JOB_DONE, False, limit_count)).fetchall()
jobs = []
for row in rows: