Skip to content

Commit

Permalink
「#」の前置により確実明示的にコメント化するのに対応。
Browse files Browse the repository at this point in the history
  • Loading branch information
NaokiSato102 committed Jul 17, 2023
1 parent 58eebb4 commit b979108
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
scripts/__pycache__/
scripts/elempresets.txt
scripts/lbwpresets.txt
25 changes: 20 additions & 5 deletions scripts/lora_block_weight.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
OUTALL:1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1\n\
ALL0.5:0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5"

class Script(modules.scripts.Script):
class Script(modules.scripts.Script):
def title(self):
return "LoRA Block Weight"

Expand Down Expand Up @@ -126,7 +126,7 @@ def ui(self, is_img2img):
loraratios=lbwpresets.splitlines()
lratios={}
for i,l in enumerate(loraratios):
if ":" not in l or not (l.count(",") == 16 or l.count(",") == 25) : continue
if checkloadcond(l) : continue
lratios[l.split(":")[0]]=l.split(":")[1]
ratiostags = [k for k in lratios.keys()]
ratiostags = ",".join(ratiostags)
Expand Down Expand Up @@ -201,7 +201,7 @@ def tagdicter(presets):
presets=presets.splitlines()
wdict={}
for l in presets:
if ":" not in l or not (l.count(",") == 16 or l.count(",") == 25) : continue
if checkloadcond(l) : continue
w=[]
if ":" in l :
key = l.split(":",1)[0]
Expand Down Expand Up @@ -257,7 +257,7 @@ def process(self, p, loraratios,useblocks,xyzsetting,xtype,xmen,ytype,ymen,ztype
lratios={}
elementals={}
for l in loraratios:
if ":" not in l or not (l.count(",") == 16 or l.count(",") == 25) : continue
if checkloadcond(l) : continue
l0=l.split(":",1)[0]
lratios[l0.strip()]=l.split(":",1)[1]
for e in elemental:
Expand Down Expand Up @@ -310,7 +310,7 @@ def run(self,p,presets,useblocks,xyzsetting,xtype,xmen,ytype,ymen,ztype,zmen,exm
loraratios=presets.splitlines()
lratios={}
for l in loraratios:
if ":" not in l or not (l.count(",") == 16 or l.count(",") == 25) : continue
if checkloadcond(l) : continue
l0=l.split(":",1)[0]
lratios[l0.strip()]=l.split(":",1)[1]

Expand Down Expand Up @@ -764,3 +764,18 @@ def hyphener(t):
ATTNDEEPOFF:IN05-OUT05:attn:0\n\n\
PROJDEEPOFF:IN05-OUT05:proj:0\n\n\
XYZ:::1"


def checkloadcond(l:str)->bool:
# ここの条件分岐は読み込んだ行がBlock Waightの書式にあっているかを確認している。
# [:]が含まれ、16個(LoRa)か25個(LyCORIS)のカンマが含まれる形式であるうえ、
# それがコメントアウト行(# foobar)でないことが求められている。
# 逆に言うとコメントアウトしたいなら絶対"# "から始めることを要求している。

# This conditional branch is checking whether the loaded line conforms to the Block Weight format.
# It is required that "[:]" is included, and the format contains either 16 commas (for LoRa) or 25 commas (for LyCORIS),
# and it's not a comment line (e.g., "# foobar").
# Conversely, if you want to comment out, it requires that it absolutely starts with "# ".
res=(":" not in l) or (not (l.count(",") == 16 or l.count(",") == 25)) or ("#" in l)
print("[debug]", res,repr(l))
return res

0 comments on commit b979108

Please sign in to comment.