42 lines
2.6 KiB
Python
42 lines
2.6 KiB
Python
"""Add fixed-GPU choices without changing any existing model, project, or style."""
|
|
import argparse, datetime, json, sqlite3
|
|
from pathlib import Path
|
|
|
|
root = Path(__file__).resolve().parent.parent
|
|
p = argparse.ArgumentParser()
|
|
p.add_argument('--data-dir', default=str(root / 'huobao-data'))
|
|
a = p.parse_args()
|
|
data = Path(a.data_dir).resolve()
|
|
assert data == root / 'huobao-data' or (data.is_relative_to(root / 'integration-work') and data.name.startswith('hd-test'))
|
|
path = data / 'huobao.sqlite3'
|
|
assert path.is_file()
|
|
backup = data / 'backups' / ('before-gpu-variants-' + datetime.datetime.now().strftime('%Y%m%d-%H%M%S') + '.sqlite3')
|
|
backup.parent.mkdir(exist_ok=True)
|
|
with sqlite3.connect(path) as db, sqlite3.connect(backup) as dest:
|
|
db.backup(dest)
|
|
with sqlite3.connect(path) as db:
|
|
db.row_factory = sqlite3.Row
|
|
sources = {4: 'MiniMax H3', 6: 'Qwen Image 2.1', 7: 'MiniMax H3 加速版', 8: 'LTX 2.3', 9: 'Wan 2.2 图生视频', 10: 'MiniMax H3-VDN-H3 高清 2K/4K'}
|
|
rows = [dict(r) for r in db.execute('SELECT * FROM ai_service_configs')]
|
|
made = []
|
|
for sid, label in sources.items():
|
|
source = next(r for r in rows if r['id'] == sid)
|
|
assert source['service_type'] in ('image', 'video') and source['base_url'].startswith('http://192.168.110.111:1879')
|
|
for gpu in ('gpu1', 'gpu2', 'gpu3'):
|
|
if any(json.loads(r['settings'] or '{}').get('gpu_variant_source') == sid and json.loads(r['settings'] or '{}').get('gpu') == gpu for r in rows):
|
|
continue
|
|
values = {k: v for k, v in source.items() if k != 'id'}
|
|
settings = json.loads(source['settings'] or '{}')
|
|
settings.update(gpu=gpu, gpu_variant_source=sid)
|
|
comfy_label='ComfyUI '+{'gpu1':'8189','gpu2':'8188','gpu3':'8191'}[gpu]
|
|
values.update(name=f'{label} · {gpu.upper()} · {comfy_label}', settings=json.dumps(settings), priority=source['priority'] - 10,
|
|
created_at=datetime.datetime.now(datetime.timezone.utc).isoformat(), updated_at=datetime.datetime.now(datetime.timezone.utc).isoformat())
|
|
columns = ','.join('"' + k + '"' for k in values)
|
|
db.execute(f'INSERT INTO ai_service_configs ({columns}) VALUES ({",".join("?" for _ in values)})', list(values.values()))
|
|
made.append(values['name'])
|
|
# Every pre-existing row must remain byte-for-byte equal.
|
|
after = {r['id']: dict(r) for r in db.execute('SELECT * FROM ai_service_configs')}
|
|
assert all(after[r['id']] == r for r in rows)
|
|
db.commit()
|
|
print(json.dumps({'added': len(made), 'names': made, 'backup': str(backup)}, ensure_ascii=False))
|