Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
Stable Diffusion Webui
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
novelai-storage
Stable Diffusion Webui
Commits
6435691b
Commit
6435691b
authored
Oct 09, 2022
by
Justin Maier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add "Scale to" option to Extras
parent
45fbd1c5
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
19 deletions
+50
-19
javascript/ui.js
javascript/ui.js
+2
-1
modules/extras.py
modules/extras.py
+23
-5
modules/ui.py
modules/ui.py
+25
-13
No files found.
javascript/ui.js
View file @
6435691b
...
...
@@ -101,7 +101,8 @@ function create_tab_index_args(tabId, args){
}
function
get_extras_tab_index
(){
return
create_tab_index_args
(
'
mode_extras
'
,
arguments
)
const
[,,...
args
]
=
[...
arguments
]
return
[
get_tab_index
(
'
mode_extras
'
),
get_tab_index
(
'
extras_resize_mode
'
),
...
args
]
}
function
create_submit_args
(
args
){
...
...
modules/extras.py
View file @
6435691b
import
math
import
os
import
numpy
as
np
...
...
@@ -19,7 +20,7 @@ import gradio as gr
cached_images
=
{}
def
run_extras
(
extras_mode
,
image
,
image_folder
,
gfpgan_visibility
,
codeformer_visibility
,
codeformer_weight
,
upscaling_resize
,
extras_upscaler_1
,
extras_upscaler_2
,
extras_upscaler_2_visibility
):
def
run_extras
(
extras_mode
,
resize_mode
,
image
,
image_folder
,
gfpgan_visibility
,
codeformer_visibility
,
codeformer_weight
,
upscaling_resize
,
upscaling_resize_w
,
upscaling_resize_h
,
upscaling_crop
,
extras_upscaler_1
,
extras_upscaler_2
,
extras_upscaler_2_visibility
):
devices
.
torch_gc
()
imageArr
=
[]
...
...
@@ -67,8 +68,23 @@ def run_extras(extras_mode, image, image_folder, gfpgan_visibility, codeformer_v
info
+=
f
"CodeFormer w: {round(codeformer_weight, 2)}, CodeFormer visibility:{round(codeformer_visibility, 2)}
\n
"
image
=
res
if
resize_mode
==
1
:
upscaling_resize
=
max
(
upscaling_resize_w
/
image
.
width
,
upscaling_resize_h
/
image
.
height
)
crop_info
=
" (crop)"
if
upscaling_crop
else
""
info
+=
f
"Resize to: {upscaling_resize_w:g}x{upscaling_resize_h:g}{crop_info}
\n
"
def
crop_upscaled_center
(
image
,
resize_w
,
resize_h
):
left
=
int
(
math
.
ceil
((
image
.
width
-
resize_w
)
/
2
))
right
=
image
.
width
-
int
(
math
.
floor
((
image
.
width
-
resize_w
)
/
2
))
top
=
int
(
math
.
ceil
((
image
.
height
-
resize_h
)
/
2
))
bottom
=
image
.
height
-
int
(
math
.
floor
((
image
.
height
-
resize_h
)
/
2
))
image
=
image
.
crop
((
left
,
top
,
right
,
bottom
))
return
image
if
upscaling_resize
!=
1.0
:
def
upscale
(
image
,
scaler_index
,
resize
):
def
upscale
(
image
,
scaler_index
,
resize
,
mode
,
resize_w
,
resize_h
,
crop
):
small
=
image
.
crop
((
image
.
width
//
2
,
image
.
height
//
2
,
image
.
width
//
2
+
10
,
image
.
height
//
2
+
10
))
pixels
=
tuple
(
np
.
array
(
small
)
.
flatten
()
.
tolist
())
key
=
(
resize
,
scaler_index
,
image
.
width
,
image
.
height
,
gfpgan_visibility
,
codeformer_visibility
,
codeformer_weight
)
+
pixels
...
...
@@ -77,15 +93,17 @@ def run_extras(extras_mode, image, image_folder, gfpgan_visibility, codeformer_v
if
c
is
None
:
upscaler
=
shared
.
sd_upscalers
[
scaler_index
]
c
=
upscaler
.
scaler
.
upscale
(
image
,
resize
,
upscaler
.
data_path
)
if
mode
==
1
and
crop
:
c
=
crop_upscaled_center
(
c
,
resize_w
,
resize_h
)
cached_images
[
key
]
=
c
return
c
info
+=
f
"Upscale: {round(upscaling_resize, 3)}, model:{shared.sd_upscalers[extras_upscaler_1].name}
\n
"
res
=
upscale
(
image
,
extras_upscaler_1
,
upscaling_resize
)
res
=
upscale
(
image
,
extras_upscaler_1
,
upscaling_resize
,
resize_mode
,
upscaling_resize_w
,
upscaling_resize_h
,
upscaling_crop
)
if
extras_upscaler_2
!=
0
and
extras_upscaler_2_visibility
>
0
:
res2
=
upscale
(
image
,
extras_upscaler_2
,
upscaling_resize
)
res2
=
upscale
(
image
,
extras_upscaler_2
,
upscaling_resize
,
resize_mode
,
upscaling_resize_w
,
upscaling_resize_h
,
upscaling_crop
)
info
+=
f
"Upscale: {round(upscaling_resize, 3)}, visibility: {round(extras_upscaler_2_visibility, 3)}, model:{shared.sd_upscalers[extras_upscaler_2].name}
\n
"
res
=
Image
.
blend
(
res
,
res2
,
extras_upscaler_2_visibility
)
...
...
modules/ui.py
View file @
6435691b
...
...
@@ -903,7 +903,15 @@ def create_ui(wrap_gradio_gpu_call):
with
gr
.
TabItem
(
'Batch Process'
):
image_batch
=
gr
.
File
(
label
=
"Batch Process"
,
file_count
=
"multiple"
,
interactive
=
True
,
type
=
"file"
)
with
gr
.
Tabs
(
elem_id
=
"extras_resize_mode"
):
with
gr
.
TabItem
(
'Scale by'
):
upscaling_resize
=
gr
.
Slider
(
minimum
=
1.0
,
maximum
=
4.0
,
step
=
0.05
,
label
=
"Resize"
,
value
=
2
)
with
gr
.
TabItem
(
'Scale to'
):
with
gr
.
Group
():
with
gr
.
Row
():
upscaling_resize_w
=
gr
.
Number
(
label
=
"Width"
,
value
=
512
)
upscaling_resize_h
=
gr
.
Number
(
label
=
"Height"
,
value
=
512
)
upscaling_crop
=
gr
.
Checkbox
(
label
=
'Crop to fit'
,
value
=
True
)
with
gr
.
Group
():
extras_upscaler_1
=
gr
.
Radio
(
label
=
'Upscaler 1'
,
choices
=
[
x
.
name
for
x
in
shared
.
sd_upscalers
],
value
=
shared
.
sd_upscalers
[
0
]
.
name
,
type
=
"index"
)
...
...
@@ -934,6 +942,7 @@ def create_ui(wrap_gradio_gpu_call):
fn
=
wrap_gradio_gpu_call
(
modules
.
extras
.
run_extras
),
_js
=
"get_extras_tab_index"
,
inputs
=
[
dummy_component
,
dummy_component
,
extras_image
,
image_batch
,
...
...
@@ -941,6 +950,9 @@ def create_ui(wrap_gradio_gpu_call):
codeformer_visibility
,
codeformer_weight
,
upscaling_resize
,
upscaling_resize_w
,
upscaling_resize_h
,
upscaling_crop
,
extras_upscaler_1
,
extras_upscaler_2
,
extras_upscaler_2_visibility
,
...
...
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