Skip to content

Commit

Permalink
feat(api): add section to extras file for additional networks
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Mar 18, 2023
1 parent c397924 commit e3bf04a
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 9 deletions.
17 changes: 17 additions & 0 deletions api/onnx_web/convert/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,23 @@ def convert_models(ctx: ConversionContext, args, models: Models):
except Exception:
logger.exception("error fetching source %s", name)

if args.networks and "networks" in models:
for network in models.get("networks"):
name = network["name"]

if name in args.skip:
logger.info("skipping network: %s", name)
else:
network_format = source_format(network)
network_type = network["type"]
source = network["source"]

try:
dest = fetch_model(ctx, name, source, dest=path.join(ctx.model_path, network_type), format=network_format)
logger.info("finished downloading network: %s -> %s", source, dest)
except Exception:
logger.exception("error fetching network %s", name)

if args.diffusion and "diffusion" in models:
for model in models.get("diffusion"):
model = tuple_to_diffusion(model)
Expand Down
2 changes: 1 addition & 1 deletion api/onnx_web/convert/diffusion/diffusers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from os import mkdir, path
from pathlib import Path
from shutil import rmtree
from typing import Dict
from typing import Dict, Tuple

import torch
from diffusers import (
Expand Down
53 changes: 45 additions & 8 deletions api/schemas/extras.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,20 @@ $defs:
- type: number
- type: string

textual_inversion:
lora_network:
type: object
required: [name, source]
properties:
name:
type: string
source:
type: string
label:
type: string
weight:
type: number

textual_inversion_network:
type: object
required: [name, source]
properties:
Expand All @@ -25,6 +38,8 @@ $defs:
type: string
token:
type: string
weight:
type: number

base_model:
type: object
Expand Down Expand Up @@ -58,7 +73,11 @@ $defs:
inversions:
type: array
items:
$ref: "#/$defs/textual_inversion"
$ref: "#/$defs/textual_inversion_network"
loras:
type: array
items:
$ref: "#/$defs/lora_network"
vae:
type: string

Expand All @@ -82,6 +101,21 @@ $defs:
source:
type: string

source_network:
type: object
required: [name, source, type]
properties:
format:
type: string
enum: [ckpt, safetensors]
name:
type: string
source:
type: string
type:
type: string
enum: [inversion, lora]

translation:
type: object
additionalProperties: False
Expand All @@ -106,12 +140,9 @@ properties:
oneOf:
- $ref: "#/$defs/legacy_tuple"
- $ref: "#/$defs/correction_model"
upscaling:
networks:
type: array
items:
oneOf:
- $ref: "#/$defs/legacy_tuple"
- $ref: "#/$defs/upscaling_model"
items: "#/$defs/source_network"
sources:
type: array
items:
Expand All @@ -123,4 +154,10 @@ properties:
additionalProperties: False
patternProperties:
"^\\w\\w$":
$ref: "#/$defs/translation"
$ref: "#/$defs/translation"
upscaling:
type: array
items:
oneOf:
- $ref: "#/$defs/legacy_tuple"
- $ref: "#/$defs/upscaling_model"

0 comments on commit e3bf04a

Please sign in to comment.