Skip to content

Commit

Permalink
Displaying file size and changing the save folder for SD models
Browse files Browse the repository at this point in the history
  • Loading branch information
SignalFlagZ committed Aug 24, 2024
1 parent 61ef741 commit ec9e501
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 18 deletions.
30 changes: 18 additions & 12 deletions scripts/civsfz_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ def getSelectedVersionEarlyAccessTimeFrame(self):
'''
return self.jsonData['items'][self.modelIndex]['modelVersions'][self.versionIndex]['earlyAccessTimeFrame']
def getSelectedVersionEarlyAccessDeadline(self):
#if 'earlyAccessDeadline' in self.jsonData['items'][self.modelIndex]['modelVersions'][self.versionIndex]:
# if 'earlyAccessDeadline' in self.jsonData['items'][self.modelIndex]['modelVersions'][self.versionIndex]:
# return self.jsonData['items'][self.modelIndex]['modelVersions'][self.versionIndex]['earlyAccessDeadline']
if self.jsonData['items'][self.modelIndex]['modelVersions'][self.versionIndex]['availability'] == "EarlyAccess":
return "EA"
Expand Down Expand Up @@ -686,7 +686,7 @@ def makeModelInfo2(self, modelIndex=None, versionIndex=None, nsfwLevel=0) -> dic
versionIndex = self.versionIndex if versionIndex is None else versionIndex
item = self.jsonData["items"][modelIndex]
version = item["modelVersions"][versionIndex]
modelInfo = {"infoVersion": "2.2",
modelInfo = {"infoVersion": "2.3",
# Some models do not have 'creator'
#"creator": {"username": ""}
}
Expand Down Expand Up @@ -849,14 +849,14 @@ def modelCardsHtml(self, models, jsID=0, nsfwLevel=0):
break
if param['have'] != "":
break
#ea = item["modelVersions"][0]['earlyAccessDeadline'] if "earlyAccessDeadline" in item["modelVersions"][0] else ""
# ea = item["modelVersions"][0]['earlyAccessDeadline'] if "earlyAccessDeadline" in item["modelVersions"][0] else ""
ea = item["modelVersions"][0]['availability'] == "EarlyAccess"
if ea:
#strEA = item["modelVersions"][0]['earlyAccessDeadline'].replace('Z', '+00:00') # < Python 3.11
#dtEA = datetime.datetime.fromisoformat(strEA)
#dtNow = datetime.datetime.now(datetime.timezone.utc)
#if dtNow < dtEA:
param['ea'] = 'in'
# strEA = item["modelVersions"][0]['earlyAccessDeadline'].replace('Z', '+00:00') # < Python 3.11
# dtEA = datetime.datetime.fromisoformat(strEA)
# dtNow = datetime.datetime.now(datetime.timezone.utc)
# if dtNow < dtEA:
param['ea'] = 'in'
cards.append(param)

forTrigger = f'<!-- {datetime.datetime.now()} -->' # for trigger event
Expand Down Expand Up @@ -929,6 +929,12 @@ def modelInfoHtml(self, modelInfo:dict, nsfwLevel:int=0) -> str:
infotext=infotext,
metaHtml=metaHtml
)
filesize = modelInfo["modelVersions"][0]["files"][0]["sizeKB"]
# Get primary file size
fileIndex = 0
for i, file in enumerate(modelInfo["modelVersions"][0]["files"]):
if "primary" in file:
fileIndex = i

# created = self.getCreatedDatetime().astimezone(
# tz.tzlocal()).replace(microsecond=0).isoformat()
Expand All @@ -943,10 +949,10 @@ def modelInfoHtml(self, modelInfo:dict, nsfwLevel:int=0) -> str:
basicInfo = template.render(
modelInfo=modelInfo,
published=published,
strNsfw=self.strNsfwLevel(modelInfo['nsfwLevel']),
strVNsfw=self.strNsfwLevel(
modelInfo["modelVersions"][0]['nsfwLevel'])
)
strNsfw=self.strNsfwLevel(modelInfo["nsfwLevel"]),
strVNsfw=self.strNsfwLevel(modelInfo["modelVersions"][0]["nsfwLevel"]),
fileIndex=fileIndex,
)

permissions = self.permissionsHtml(self.allows2permissions())
# function:copy to clipboard
Expand Down
2 changes: 1 addition & 1 deletion scripts/civsfz_filemanage.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def generate_model_save_path2(type, modelName: str = "", baseModel: str = "", ns
"VERSIONID": str(vID) if vID is not None else None,
}
if not str.strip(opts.civsfz_save_subfolder):
subTree = "{{BASEMODELbkCmpt}}/.{{NSFW}}/{{MODELNAME}}"
subTree = "_{{BASEMODEL}}/.{{NSFW}}/{{MODELNAME}}"
else:
subTree = str.strip(opts.civsfz_save_subfolder)
subTreeList = subTree.split("/")
Expand Down
10 changes: 6 additions & 4 deletions scripts/civsfz_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ def getComponents(self):
return self.components

def on_ui_tabs():
ver = 'v2.2.1'
ver = 'v2.2.2'
tabNames = []
downloader = Downloader()
for i in range(1, opts.civsfz_number_of_tabs + 1):
Expand All @@ -772,15 +772,17 @@ def on_ui_tabs():
value=(
"# Changes"
"\n"
"- Support Early Access status key that changed to `availability` instead of `earlyAccessDeadline`"
"- SD models are saved in the _SD_1_X folder by default"
"\n"
"- Fix to support arrays of `Trained Tags` and display multiple `Trained Tags`"
" - Move the SD model files to _SD_1_X."
"\n"
" - You can use `BASEMODELbkCmpt` in Settings to maintain backward compatibility (deprecated)"
)
)
downloader.uiDlList(gr)
with gr.Tabs(elem_id='civsfz_tab-element', elem_classes="civsfz-custom-property"):
for i,name in enumerate(tabNames):
with gr.TabItem(label=name, id=f"tab{i}", elem_id=f"civsfz_tab{i}") as tab:
with gr.Tab(label=name, id=f"tab{i}", elem_id=f"civsfz_tab{i}") as tab:
Components(downloader, tab) # (tab)
with gr.Row():
gr.Markdown(value=f'<div style="text-align:center;">{ver}</div>')
Expand Down
2 changes: 1 addition & 1 deletion scripts/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def on_ui_settings():
component=gr.Textbox,
component_args={
"lines": 1,
"placeholder": '{{BASEMODEL}}/.{{NSFW}}/{{MODELNAME}}',
"placeholder": "_{{BASEMODEL}}/.{{NSFW}}/{{MODELNAME}}",
},
section=section,
),
Expand Down
3 changes: 3 additions & 0 deletions templates/modelInfo.jinja
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{# Model Information #}
{{ js }}
<div style="text-align: right;">
<i>Model Info Version: {{ modelInfo["infoVersion"] }}</i>
</div>
<div>
<h1>
{%- if modelInfo['nsfw'] %}
Expand Down
8 changes: 8 additions & 0 deletions templates/modelbasicinfo.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@
<th {{ tdStyle1 }}>Name</th>
<td {{ tdStyle1 }}>{{ modelInfo["versionName"]|e }}</td>
</tr>
<tr>
<th {{ tdStyle1 }}>Size</th>
<td {{ tdStyle1 }}>{{ (modelInfo["modelVersions"][0]["files"][fileIndex]["sizeKB"] * 1024) |filesizeformat|e }}</td>
</tr>
{# <tr>
<th {{ tdStyle1 }}>Hash</th>
<td {{ tdStyle1 }}>{{ copy -}}<span>{{ modelInfo["modelVersions"][0]["files"][fileIndex]["hashes"]["AutoV3"]|lower|e }}</span></td>
</tr> #}
<tr>
<th {{ tdStyle1 }}>NSFW level</th>
<td {{ tdStyle1 }}>{{ strVNsfw }}</td>
Expand Down

0 comments on commit ec9e501

Please sign in to comment.