update simple-table

Signed-off-by: Vladimir Mandic <mandic00@live.com>
This commit is contained in:
Vladimir Mandic
2025-08-03 08:43:36 -04:00
parent ea9d8b2323
commit 84bccc07ca
4 changed files with 47 additions and 28 deletions
+14 -18
View File
@@ -31,16 +31,8 @@ def civit_update_metadata():
def create_update_metadata_table(rows: list[CivitModel]):
html = """
<table class="simple-table">
<thead">
<tr>
<th>ID</th>
<th>File</th>
<th>Name</th>
<th>Hash</th>
<th>Versions</th>
<th>Latest</th>
<th>Status</th>
</tr>
<thead>
<tr><th>File</th><th>ID</th><th>Name</th><th>Hash</th><th>Versions</th><th>Latest</th><th>Status</th></tr>
</thead>
<tbody>
{tbody}
@@ -52,8 +44,8 @@ def civit_update_metadata():
try:
tbody += f"""
<tr>
<td>{row.id}</td>
<td>{row.file}</td>
<td>{row.id}</td>
<td>{row.name}</td>
<td>{row.sha}</td>
<td>{row.versions}</td>
@@ -103,11 +95,11 @@ def civit_update_metadata():
model.url = f.get('downloadUrl', None)
model.latest_name = f.get('name', '')
if model.vername == model.latest:
model.status = 'Latest'
model.status = 'Latest version'
elif any(map(lambda v: v in model.latest_hashes, all_hashes)): # pylint: disable=cell-var-from-loop # noqa: C417
model.status = 'Downloaded'
model.status = 'Update downloaded'
else:
model.status = 'Available'
model.status = 'Update available'
break
results.append(model)
yield create_update_metadata_table(results)
@@ -226,7 +218,11 @@ def atomic_civit_search_metadata(item, results):
from modules.modelloader import download_civit_preview, download_civit_meta
if item is None:
return
meta = os.path.splitext(item['filename'])[0] + '.json'
try:
meta = os.path.splitext(item['filename'])[0] + '.json'
except Exception:
# log.error(f'CivitAI search metadata: item={item} {e}')
return
has_meta = os.path.isfile(meta) and os.stat(meta).st_size > 0
if ('card-no-preview.png' in item['preview'] or not has_meta) and os.path.isfile(item['filename']):
sha = item.get('hash', None)
@@ -288,8 +284,8 @@ def civit_search_metadata(title: str = None):
def create_search_metadata_table(rows):
html = """
<table class="simple-table">
<thead">
<tr><th>ID</th><th>Name</th><th>Type</th><th>Code</th><th>Hash</th><th>Size</th><th>Note</th></tr>
<thead>
<tr><th>Name</th><th>ID</th><th>Type</th><th>Code</th><th>Hash</th><th>Size</th><th>Note</th></tr>
</thead>
<tbody>
{tbody}
@@ -301,8 +297,8 @@ def civit_search_metadata(title: str = None):
try:
tbody += f"""
<tr>
<td>{row['id']}</td>
<td>{row['name']}</td>
<td>{row['id']}</td>
<td>{row['type']}</td>
<td>{row['code']}</td>
<td>{row['hash']}</td>
+29 -6
View File
@@ -153,20 +153,43 @@ def list_models():
def update_model_hashes():
txt = []
def update_model_hashes_table(rows):
html = """
<table class="simple-table">
<thead>
<tr><th>Name</th><th>Type</th><th>Hash</th></tr>
</thead>
<tbody>
{tbody}
</tbody>
</table>
"""
tbody = ''
for row in rows:
try:
tbody += f"""
<tr>
<td>{row.name}</td>
<td>{row.type}</td>
<td>{row.shorthash}</td>
</tr>
"""
except Exception as e:
shared.log.error(f'Model list: row={row} {e}')
return html.format(tbody=tbody)
lst = [ckpt for ckpt in checkpoints_list.values() if ckpt.hash is None]
for ckpt in lst:
ckpt.hash = model_hash(ckpt.filename)
lst = [ckpt for ckpt in checkpoints_list.values() if ckpt.sha256 is None or ckpt.shorthash is None]
shared.log.info(f'Models list: hash missing={len(lst)} total={len(checkpoints_list)}')
updated = []
for ckpt in lst:
ckpt.sha256 = hashes.sha256(ckpt.filename, f"checkpoint/{ckpt.name}")
ckpt.shorthash = ckpt.sha256[0:10] if ckpt.sha256 is not None else None
if ckpt.sha256 is not None:
txt.append(f'Hash: <b>{ckpt.title}</b> {ckpt.shorthash}')
txt.append(f'Updated hashes for <b>{len(lst)}</b> out of <b>{len(checkpoints_list)}</b> models')
txt = '<br>'.join(txt)
return txt
updated.append(ckpt)
yield update_model_hashes_table(updated)
return
def remove_hash(s):
+3 -3
View File
@@ -27,7 +27,7 @@ def create_ui():
def create_modules_table(rows: list):
html = """
<table class="simple-table">
<thead">
<thead>
<tr><th>Module</th><th>Class</th><th>Device</th><th>Dtype</th><th>Quant</th><th>Params</th><th>Modules</th><th>Config</th></tr>
</thead>
<tbody>
@@ -83,7 +83,7 @@ def create_ui():
from modules import sd_detect
html = """
<table class="simple-table">
<thead">
<thead>
<tr><th>Name</th><th>Type</th><th>Detect</th><th>Pipeline</th><th>Hash</th><th>Size</th><th>MTime</th></tr>
</thead>
<tbody>
@@ -131,10 +131,10 @@ def create_ui():
with gr.Row():
model_list_btn = gr.Button(value="List models", variant='primary')
model_checkhash_btn = gr.Button(value="Calculate missing hashes", variant='secondary')
model_checkhash_btn.click(fn=sd_models.update_model_hashes, inputs=[], outputs=[models_outcome])
with gr.Row():
model_table = gr.HTML(value='', elem_id="model_list_table")
model_checkhash_btn.click(fn=sd_models.update_model_hashes, inputs=[], outputs=[model_table])
model_list_btn.click(fn=lambda: create_models_table(sd_models.checkpoints_list.values()), inputs=[], outputs=[model_table])
with gr.Tab(label="Metadata"):