parent
15a500697a
commit
59055f3b63
|
|
@ -27,15 +27,17 @@ def loadsettings():
|
||||||
file.close()
|
file.close()
|
||||||
return settings
|
return settings
|
||||||
|
|
||||||
def savesettings(active, username, apikey):
|
def savesettings(active, username, apikey, negprompt):
|
||||||
"""Save the current username and api key to the active booru
|
"""Save the current username and api key to the active booru
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
active (str): The string identifier of the currently selected booru
|
active (str): The string identifier of the currently selected booru
|
||||||
username (str): The username for that booru
|
username (str): The username for that booru
|
||||||
apikey (str): The user's api key
|
apikey (str): The user's api key
|
||||||
|
negprompt (str): The negative prompt to be appended to each image selection
|
||||||
"""
|
"""
|
||||||
settings["active"] = active
|
settings["active"] = active
|
||||||
|
settings["negativeprompt"] = negprompt
|
||||||
|
|
||||||
#Stepping through all the boorus in the settings till we find the right one
|
#Stepping through all the boorus in the settings till we find the right one
|
||||||
for booru in settings['boorus']:
|
for booru in settings['boorus']:
|
||||||
|
|
@ -190,11 +192,12 @@ def updatesettings(active = settings['active']):
|
||||||
apikey = booru['apikey']
|
apikey = booru['apikey']
|
||||||
return username, apikey, active, active
|
return username, apikey, active, active
|
||||||
|
|
||||||
def grabtags(url, replacespaces, replaceunderscores, includeartist, includecharacter, includecopyright, includemeta):
|
def grabtags(url, negprompt, replacespaces, replaceunderscores, includeartist, includecharacter, includecopyright, includemeta):
|
||||||
"""Get the tags for the selected post and update all the relevant textboxes on the Select tab.
|
"""Get the tags for the selected post and update all the relevant textboxes on the Select tab.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
url (str): Either the full path to the post, or just the posts' id, formatted like "id:xxxxxx"
|
url (str): Either the full path to the post, or just the posts' id, formatted like "id:xxxxxx"
|
||||||
|
negprompt (str): A negative prompt to paste into the relevant field. Setting to None will delete the existing negative prompt at the target
|
||||||
replacespaces (bool): True to replace all the spaces in the tag list with ", "
|
replacespaces (bool): True to replace all the spaces in the tag list with ", "
|
||||||
replaceunderscores (bool): True to replace the underscores in each tag with a space
|
replaceunderscores (bool): True to replace the underscores in each tag with a space
|
||||||
includeartist (bool): True to include the artist tags in the final tag string
|
includeartist (bool): True to include the artist tags in the final tag string
|
||||||
|
|
@ -273,6 +276,11 @@ def grabtags(url, replacespaces, replaceunderscores, includeartist, includechara
|
||||||
if replaceunderscores:
|
if replaceunderscores:
|
||||||
tags = tags.replace("_", " ")
|
tags = tags.replace("_", " ")
|
||||||
|
|
||||||
|
#Adding a line for the negative prompt if we receieved one
|
||||||
|
#It's formatted this way very specifically. This is how the metadata looks on pngs coming out of SD
|
||||||
|
if negprompt:
|
||||||
|
tags += f"\nNegative prompt: {negprompt}"
|
||||||
|
|
||||||
#Creating the temp directory if it doesn't already exist
|
#Creating the temp directory if it doesn't already exist
|
||||||
if not os.path.exists(edirectory + "tempimages"):
|
if not os.path.exists(edirectory + "tempimages"):
|
||||||
os.makedirs(edirectory + "tempimages")
|
os.makedirs(edirectory + "tempimages")
|
||||||
|
|
@ -294,6 +302,7 @@ def on_ui_tabs():
|
||||||
activeboorutext1 = gr.Textbox(label="Current Booru", value=settings['active'], interactive=False)
|
activeboorutext1 = gr.Textbox(label="Current Booru", value=settings['active'], interactive=False)
|
||||||
activeboorutext2 = gr.Textbox(label="Current Booru", value=settings['active'], interactive=False)
|
activeboorutext2 = gr.Textbox(label="Current Booru", value=settings['active'], interactive=False)
|
||||||
curpage = gr.Textbox(value="1", label="Page Number", interactive=False, show_label=True)
|
curpage = gr.Textbox(value="1", label="Page Number", interactive=False, show_label=True)
|
||||||
|
negprompt = gr.Textbox(label="Negative Prompt", value=settings['negativeprompt'], placeholder="Negative prompt to send with along with each prompt")
|
||||||
|
|
||||||
with gr.Blocks() as interface:
|
with gr.Blocks() as interface:
|
||||||
with gr.Tab("Select"):
|
with gr.Tab("Select"):
|
||||||
|
|
@ -325,6 +334,7 @@ def on_ui_tabs():
|
||||||
selectbutton.click(fn=grabtags,
|
selectbutton.click(fn=grabtags,
|
||||||
inputs=
|
inputs=
|
||||||
[imagelink,
|
[imagelink,
|
||||||
|
negprompt,
|
||||||
replacespaces,
|
replacespaces,
|
||||||
replaceunderscores,
|
replaceunderscores,
|
||||||
includeartist,
|
includeartist,
|
||||||
|
|
@ -373,15 +383,16 @@ def on_ui_tabs():
|
||||||
#gallery, and send it back here to the imagelink output. I cannot fathom why Gradio galleries can't
|
#gallery, and send it back here to the imagelink output. I cannot fathom why Gradio galleries can't
|
||||||
#be used as inputs, but so be it.
|
#be used as inputs, but so be it.
|
||||||
sendsearched.click(fn = None, _js="switch_to_select", outputs = imagelink)
|
sendsearched.click(fn = None, _js="switch_to_select", outputs = imagelink)
|
||||||
with gr.Tab("API Keys"):
|
with gr.Tab("Settings/API Keys"):
|
||||||
settingshelptext = gr.HTML(interactive=False, show_label = False, value="API info may not be necessary for some boorus, but certain information or posts may fail to load without it. For example, Danbooru doesn't show certain posts in search results unless you auth as a Gold tier member.")
|
settingshelptext = gr.HTML(interactive=False, show_label = False, value="API info may not be necessary for some boorus, but certain information or posts may fail to load without it. For example, Danbooru doesn't show certain posts in search results unless you auth as a Gold tier member.")
|
||||||
settingshelptext2 = gr.HTML(interactive=False, show_label=False, value="Also, please set the booru selection here before using select or search.")
|
settingshelptext2 = gr.HTML(interactive=False, show_label=False, value="Also, please set the booru selection here before using select or search.")
|
||||||
booru = gr.Dropdown(label="Booru",value=settings['active'],choices=boorulist, interactive=True)
|
booru = gr.Dropdown(label="Booru",value=settings['active'],choices=boorulist, interactive=True)
|
||||||
u, a = getauth()
|
u, a = getauth()
|
||||||
username = gr.Textbox(label="Username", value=u)
|
username = gr.Textbox(label="Username", value=u)
|
||||||
apikey = gr.Textbox(label="API Key", value=a)
|
apikey = gr.Textbox(label="API Key", value=a)
|
||||||
|
negprompt.render()
|
||||||
savesettingsbutton = gr.Button(value="Save Settings", variant="primary")
|
savesettingsbutton = gr.Button(value="Save Settings", variant="primary")
|
||||||
savesettingsbutton.click(fn=savesettings, inputs=[booru, username, apikey])
|
savesettingsbutton.click(fn=savesettings, inputs=[booru, username, apikey, negprompt])
|
||||||
booru.change(fn=updatesettings, inputs=booru, outputs=[username, apikey, activeboorutext1, activeboorutext2])
|
booru.change(fn=updatesettings, inputs=booru, outputs=[username, apikey, activeboorutext1, activeboorutext2])
|
||||||
|
|
||||||
return (interface, "booru2prompt", "b2p_interface"),
|
return (interface, "booru2prompt", "b2p_interface"),
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"active": "Danbooru",
|
"active": "Danbooru",
|
||||||
|
"negativeprompt": "lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, artist name",
|
||||||
"boorus": [
|
"boorus": [
|
||||||
{
|
{
|
||||||
"name": "Danbooru",
|
"name": "Danbooru",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue