1414import numpy
1515import random
1616from modules .processing import Processed , process_images , fix_seed
17- from modules .shared import opts , cmd_opts , state
17+ from modules .shared import opts , cmd_opts , state , sd_upscalers
18+ from modules .images import resize_image
1819
20+ __ = lambda key , value = None : opts .data .get (f'customscript/seed_travel.py/txt2img/{ key } /value' , value )
21+
22+ DEFAULT_UPSCALE_METH = __ ('Upscaler' , 'Lanczos' )
23+ DEFAULT_UPSCALE_RATIO = __ ('Upscale ratio' , 1.0 )
24+ CHOICES_UPSCALER = [x .name for x in sd_upscalers ]
1925
2026class Script (scripts .Script ):
2127 def title (self ):
@@ -32,8 +38,11 @@ def ui(self, is_img2img):
3238 with gr .Row ():
3339 video_fps = gr .Number (label = 'Frames per second' , value = 30 )
3440 lead_inout = gr .Number (label = 'Number of frames for lead in/out' , value = 0 )
41+ with gr .Row ():
42+ upscale_meth = gr .Dropdown (label = 'Upscaler' , value = lambda : DEFAULT_UPSCALE_METH , choices = CHOICES_UPSCALER )
43+ upscale_ratio = gr .Slider (label = 'Upscale ratio' , value = lambda : DEFAULT_UPSCALE_RATIO , minimum = 0.0 , maximum = 8.0 , step = 0.1 )
3544
36- return [steps , save_video , video_fps , show_images , lead_inout ]
45+ return [steps , save_video , video_fps , show_images , lead_inout , upscale_meth , upscale_ratio ]
3746
3847 def get_next_sequence_number (path ):
3948 from pathlib import Path
@@ -52,7 +61,7 @@ def get_next_sequence_number(path):
5261 pass
5362 return result + 1
5463
55- def run (self , p , steps , save_video , video_fps , show_images , lead_inout ):
64+ def run (self , p , steps , save_video , video_fps , show_images , lead_inout , upscale_meth , upscale_ratio ):
5665 re_attention_span = re .compile (r"([\-.\d]+~[\-~.\d]+)" , re .X )
5766
5867 def shift_attention (text , distance ):
@@ -117,7 +126,15 @@ def inject_value(distance, match_obj):
117126 proc = process_images (p )
118127 if initial_info is None :
119128 initial_info = proc .info
120- images += proc .images
129+
130+ # upscale - copied from https://github.com/Kahsolt/stable-diffusion-webui-prompt-travel
131+ tgt_w , tgt_h = round (p .width * upscale_ratio ), round (p .height * upscale_ratio )
132+ if upscale_meth != 'None' and upscale_ratio != 1.0 and upscale_ratio != 0.0 :
133+ image = [resize_image (0 , proc .images [0 ], tgt_w , tgt_h , upscaler_name = upscale_meth )]
134+ else :
135+ image = proc .images
136+
137+ images += image
121138
122139 if save_video :
123140 frames = [np .asarray (images [0 ])] * lead_inout + [np .asarray (t ) for t in images ] + [np .asarray (images [- 1 ])] * lead_inout
0 commit comments