Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
S
stable-diffusion-webui
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
stable-diffusion-webui
Commits
524d532b
Commit
524d532b
authored
Jan 01, 2023
by
AUTOMATIC
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved roll artist to built-in extensions
parent
e5f1a37c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
34 deletions
+53
-34
roll-artist.py
extensions-builtin/roll-artist/scripts/roll-artist.py
+50
-0
ui.py
modules/ui.py
+3
-34
No files found.
extensions-builtin/roll-artist/scripts/roll-artist.py
0 → 100644
View file @
524d532b
import
random
from
modules
import
script_callbacks
,
shared
import
gradio
as
gr
art_symbol
=
'
\U0001f3a8
'
# 🎨
global_prompt
=
None
related_ids
=
{
"txt2img_prompt"
,
"txt2img_clear_prompt"
,
"img2img_prompt"
,
"img2img_clear_prompt"
}
def
roll_artist
(
prompt
):
allowed_cats
=
set
([
x
for
x
in
shared
.
artist_db
.
categories
()
if
len
(
shared
.
opts
.
random_artist_categories
)
==
0
or
x
in
shared
.
opts
.
random_artist_categories
])
artist
=
random
.
choice
([
x
for
x
in
shared
.
artist_db
.
artists
if
x
.
category
in
allowed_cats
])
return
prompt
+
", "
+
artist
.
name
if
prompt
!=
''
else
artist
.
name
def
add_roll_button
(
prompt
):
roll
=
gr
.
Button
(
value
=
art_symbol
,
elem_id
=
"roll"
,
visible
=
len
(
shared
.
artist_db
.
artists
)
>
0
)
roll
.
click
(
fn
=
roll_artist
,
_js
=
"update_txt2img_tokens"
,
inputs
=
[
prompt
,
],
outputs
=
[
prompt
,
]
)
def
after_component
(
component
,
**
kwargs
):
global
global_prompt
elem_id
=
kwargs
.
get
(
'elem_id'
,
None
)
if
elem_id
not
in
related_ids
:
return
if
elem_id
==
"txt2img_prompt"
:
global_prompt
=
component
elif
elem_id
==
"txt2img_clear_prompt"
:
add_roll_button
(
global_prompt
)
elif
elem_id
==
"img2img_prompt"
:
global_prompt
=
component
elif
elem_id
==
"img2img_clear_prompt"
:
add_roll_button
(
global_prompt
)
script_callbacks
.
on_after_component
(
after_component
)
modules/ui.py
View file @
524d532b
...
@@ -80,7 +80,6 @@ css_hide_progressbar = """
...
@@ -80,7 +80,6 @@ css_hide_progressbar = """
# Important that they exactly match script.js for tooltip to work.
# Important that they exactly match script.js for tooltip to work.
random_symbol
=
'
\U0001f3b2\ufe0f
'
# 🎲️
random_symbol
=
'
\U0001f3b2\ufe0f
'
# 🎲️
reuse_symbol
=
'
\u267b\ufe0f
'
# ♻️
reuse_symbol
=
'
\u267b\ufe0f
'
# ♻️
art_symbol
=
'
\U0001f3a8
'
# 🎨
paste_symbol
=
'
\u2199\ufe0f
'
# ↙
paste_symbol
=
'
\u2199\ufe0f
'
# ↙
folder_symbol
=
'
\U0001f4c2
'
# 📂
folder_symbol
=
'
\U0001f4c2
'
# 📂
refresh_symbol
=
'
\U0001f504
'
# 🔄
refresh_symbol
=
'
\U0001f504
'
# 🔄
...
@@ -234,13 +233,6 @@ def check_progress_call_initial(id_part):
...
@@ -234,13 +233,6 @@ def check_progress_call_initial(id_part):
return
check_progress_call
(
id_part
)
return
check_progress_call
(
id_part
)
def
roll_artist
(
prompt
):
allowed_cats
=
set
([
x
for
x
in
shared
.
artist_db
.
categories
()
if
len
(
opts
.
random_artist_categories
)
==
0
or
x
in
opts
.
random_artist_categories
])
artist
=
random
.
choice
([
x
for
x
in
shared
.
artist_db
.
artists
if
x
.
category
in
allowed_cats
])
return
prompt
+
", "
+
artist
.
name
if
prompt
!=
''
else
artist
.
name
def
visit
(
x
,
func
,
path
=
""
):
def
visit
(
x
,
func
,
path
=
""
):
if
hasattr
(
x
,
'children'
):
if
hasattr
(
x
,
'children'
):
for
c
in
x
.
children
:
for
c
in
x
.
children
:
...
@@ -403,7 +395,6 @@ def create_toprow(is_img2img):
...
@@ -403,7 +395,6 @@ def create_toprow(is_img2img):
)
)
with
gr
.
Column
(
scale
=
1
,
elem_id
=
"roll_col"
):
with
gr
.
Column
(
scale
=
1
,
elem_id
=
"roll_col"
):
roll
=
gr
.
Button
(
value
=
art_symbol
,
elem_id
=
"roll"
,
visible
=
len
(
shared
.
artist_db
.
artists
)
>
0
)
paste
=
gr
.
Button
(
value
=
paste_symbol
,
elem_id
=
"paste"
)
paste
=
gr
.
Button
(
value
=
paste_symbol
,
elem_id
=
"paste"
)
save_style
=
gr
.
Button
(
value
=
save_style_symbol
,
elem_id
=
"style_create"
)
save_style
=
gr
.
Button
(
value
=
save_style_symbol
,
elem_id
=
"style_create"
)
prompt_style_apply
=
gr
.
Button
(
value
=
apply_style_symbol
,
elem_id
=
"style_apply"
)
prompt_style_apply
=
gr
.
Button
(
value
=
apply_style_symbol
,
elem_id
=
"style_apply"
)
...
@@ -452,7 +443,7 @@ def create_toprow(is_img2img):
...
@@ -452,7 +443,7 @@ def create_toprow(is_img2img):
prompt_style2
=
gr
.
Dropdown
(
label
=
"Style 2"
,
elem_id
=
f
"{id_part}_style2_index"
,
choices
=
[
k
for
k
,
v
in
shared
.
prompt_styles
.
styles
.
items
()],
value
=
next
(
iter
(
shared
.
prompt_styles
.
styles
.
keys
())))
prompt_style2
=
gr
.
Dropdown
(
label
=
"Style 2"
,
elem_id
=
f
"{id_part}_style2_index"
,
choices
=
[
k
for
k
,
v
in
shared
.
prompt_styles
.
styles
.
items
()],
value
=
next
(
iter
(
shared
.
prompt_styles
.
styles
.
keys
())))
prompt_style2
.
save_to_config
=
True
prompt_style2
.
save_to_config
=
True
return
prompt
,
roll
,
prompt_style
,
negative_prompt
,
prompt_style2
,
submit
,
button_interrogate
,
button_deepbooru
,
prompt_style_apply
,
save_style
,
paste
,
token_counter
,
token_button
return
prompt
,
prompt_style
,
negative_prompt
,
prompt_style2
,
submit
,
button_interrogate
,
button_deepbooru
,
prompt_style_apply
,
save_style
,
paste
,
token_counter
,
token_button
def
setup_progressbar
(
progressbar
,
preview
,
id_part
,
textinfo
=
None
):
def
setup_progressbar
(
progressbar
,
preview
,
id_part
,
textinfo
=
None
):
...
@@ -668,7 +659,7 @@ def create_ui():
...
@@ -668,7 +659,7 @@ def create_ui():
modules
.
scripts
.
scripts_txt2img
.
initialize_scripts
(
is_img2img
=
False
)
modules
.
scripts
.
scripts_txt2img
.
initialize_scripts
(
is_img2img
=
False
)
with
gr
.
Blocks
(
analytics_enabled
=
False
)
as
txt2img_interface
:
with
gr
.
Blocks
(
analytics_enabled
=
False
)
as
txt2img_interface
:
txt2img_prompt
,
roll
,
txt2img_prompt_style
,
txt2img_negative_prompt
,
txt2img_prompt_style2
,
submit
,
_
,
_
,
txt2img_prompt_style_apply
,
txt2img_save_style
,
txt2img_paste
,
token_counter
,
token_button
=
create_toprow
(
is_img2img
=
False
)
txt2img_prompt
,
txt2img_prompt_style
,
txt2img_negative_prompt
,
txt2img_prompt_style2
,
submit
,
_
,
_
,
txt2img_prompt_style_apply
,
txt2img_save_style
,
txt2img_paste
,
token_counter
,
token_button
=
create_toprow
(
is_img2img
=
False
)
dummy_component
=
gr
.
Label
(
visible
=
False
)
dummy_component
=
gr
.
Label
(
visible
=
False
)
txt_prompt_img
=
gr
.
File
(
label
=
""
,
elem_id
=
"txt2img_prompt_image"
,
file_count
=
"single"
,
type
=
"bytes"
,
visible
=
False
)
txt_prompt_img
=
gr
.
File
(
label
=
""
,
elem_id
=
"txt2img_prompt_image"
,
file_count
=
"single"
,
type
=
"bytes"
,
visible
=
False
)
...
@@ -771,16 +762,6 @@ def create_ui():
...
@@ -771,16 +762,6 @@ def create_ui():
outputs
=
[
hr_options
],
outputs
=
[
hr_options
],
)
)
roll
.
click
(
fn
=
roll_artist
,
_js
=
"update_txt2img_tokens"
,
inputs
=
[
txt2img_prompt
,
],
outputs
=
[
txt2img_prompt
,
]
)
txt2img_paste_fields
=
[
txt2img_paste_fields
=
[
(
txt2img_prompt
,
"Prompt"
),
(
txt2img_prompt
,
"Prompt"
),
...
@@ -823,7 +804,7 @@ def create_ui():
...
@@ -823,7 +804,7 @@ def create_ui():
modules
.
scripts
.
scripts_img2img
.
initialize_scripts
(
is_img2img
=
True
)
modules
.
scripts
.
scripts_img2img
.
initialize_scripts
(
is_img2img
=
True
)
with
gr
.
Blocks
(
analytics_enabled
=
False
)
as
img2img_interface
:
with
gr
.
Blocks
(
analytics_enabled
=
False
)
as
img2img_interface
:
img2img_prompt
,
roll
,
img2img_prompt_style
,
img2img_negative_prompt
,
img2img_prompt_style2
,
submit
,
img2img_interrogate
,
img2img_deepbooru
,
img2img_prompt_style_apply
,
img2img_save_style
,
img2img_paste
,
token_counter
,
token_button
=
create_toprow
(
is_img2img
=
True
)
img2img_prompt
,
img2img_prompt_style
,
img2img_negative_prompt
,
img2img_prompt_style2
,
submit
,
img2img_interrogate
,
img2img_deepbooru
,
img2img_prompt_style_apply
,
img2img_save_style
,
img2img_paste
,
token_counter
,
token_button
=
create_toprow
(
is_img2img
=
True
)
with
gr
.
Row
(
elem_id
=
'img2img_progress_row'
):
with
gr
.
Row
(
elem_id
=
'img2img_progress_row'
):
img2img_prompt_img
=
gr
.
File
(
label
=
""
,
elem_id
=
"img2img_prompt_image"
,
file_count
=
"single"
,
type
=
"bytes"
,
visible
=
False
)
img2img_prompt_img
=
gr
.
File
(
label
=
""
,
elem_id
=
"img2img_prompt_image"
,
file_count
=
"single"
,
type
=
"bytes"
,
visible
=
False
)
...
@@ -999,18 +980,6 @@ def create_ui():
...
@@ -999,18 +980,6 @@ def create_ui():
outputs
=
[
img2img_prompt
],
outputs
=
[
img2img_prompt
],
)
)
roll
.
click
(
fn
=
roll_artist
,
_js
=
"update_img2img_tokens"
,
inputs
=
[
img2img_prompt
,
],
outputs
=
[
img2img_prompt
,
]
)
prompts
=
[(
txt2img_prompt
,
txt2img_negative_prompt
),
(
img2img_prompt
,
img2img_negative_prompt
)]
prompts
=
[(
txt2img_prompt
,
txt2img_negative_prompt
),
(
img2img_prompt
,
img2img_negative_prompt
)]
style_dropdowns
=
[(
txt2img_prompt_style
,
txt2img_prompt_style2
),
(
img2img_prompt_style
,
img2img_prompt_style2
)]
style_dropdowns
=
[(
txt2img_prompt_style
,
txt2img_prompt_style2
),
(
img2img_prompt_style
,
img2img_prompt_style2
)]
style_js_funcs
=
[
"update_txt2img_tokens"
,
"update_img2img_tokens"
]
style_js_funcs
=
[
"update_txt2img_tokens"
,
"update_img2img_tokens"
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment