MCPcopy Create free account
hub / github.com/DenOfEquity/ersatzForge / ui

Method ui

modules/processing_scripts/seed.py:26–63  ·  view source on GitHub ↗
(self, is_img2img)

Source from the content-addressed store, hash-verified

24 def ui(self, is_img2img):
25 with InputAccordion(False, label="Seed (checked: random)") as random:
26 with gradio.Row():
27 self.seed = gradio.Number(label="Seed", value=-1, minimum=-1, maximum=4294967295, precision=0, elem_id=self.elem_id("seed"), min_width=100)
28
29 subseed = gradio.Number(label="Variation seed", value=-1, minimum=-1, maximum=4294967295, precision=0, scale=0, elem_id=self.elem_id("subseed"))
30 subseed_strength = gradio.Number(label="Variation strength", value=0, minimum=0, maximum=1, step=0.01, scale=0, elem_id=self.elem_id("subseed_strength"))
31 random_seed = ToolButton("\U0001f3b2\ufe0f", elem_id=self.elem_id("random_seed"), tooltip="set Seed (and Variation) to -1, which means random values will be used") # 🎲️
32 reuse_seed = ToolButton("\u267b\ufe0f", elem_id=self.elem_id("reuse_seed"), tooltip="reuse Seed (and Variation) from last generation") # ♻️
33
34 with gradio.Row():
35 seed_resize_from_w = gradio.Number(label="Resize from width", value=0, minimum=0, maximum=2048, step=8, precision=0, elem_id=self.elem_id("seed_resize_from_w"))
36 seed_resize_from_h = gradio.Number(label="Resize from height", value=0, minimum=0, maximum=2048, step=8, precision=0, elem_id=self.elem_id("seed_resize_from_h"))
37
38
39 random_seed.click(fn=lambda: (-1, -1), inputs=None, outputs=[self.seed, subseed], show_progress="hidden")
40
41 self.infotext_fields = [
42 PasteField(self.seed, "Seed", api="seed"),
43 PasteField(subseed, "Variation seed", api="subseed"),
44 PasteField(subseed_strength, "Variation seed strength", api="subseed_strength"),
45 PasteField(seed_resize_from_w, "Seed resize from-1", api="seed_resize_from_h"),
46 PasteField(seed_resize_from_h, "Seed resize from-2", api="seed_resize_from_w"),
47 ]
48
49 self.on_after_component(lambda x: connect_reuse_seed(self.seed, subseed, reuse_seed, x.component), elem_id=f'generation_info_{self.tabname}')
50
51 return random, self.seed, subseed, subseed_strength, seed_resize_from_w, seed_resize_from_h
52
53 def setup(self, p, random, seed, subseed, subseed_strength, seed_resize_from_w, seed_resize_from_h):
54 p.seed = -1 if random else seed
55
56 if subseed_strength > 0:
57 p.subseed = -1 if random else subseed
58 p.subseed_strength = subseed_strength
59
60 if seed_resize_from_w > 0 and seed_resize_from_h > 0:
61 p.seed_resize_from_w = seed_resize_from_w
62 p.seed_resize_from_h = seed_resize_from_h
63
64
65def connect_reuse_seed(seed: gradio.Number, subseed: gradio.Number, reuse_seed: ToolButton, generation_info: gradio.Textbox):
66 """ Connects a 'reuse (sub)seed' button's click event so that it copies last used

Callers 1

Calls 6

ToolButtonClass · 0.90
PasteFieldClass · 0.90
connect_reuse_seedFunction · 0.85
elem_idMethod · 0.45
updateMethod · 0.45
on_after_componentMethod · 0.45

Tested by

no test coverage detected