Skip to content

Commit

Permalink
refactor: move show_metadata to function in metadata.py
Browse files Browse the repository at this point in the history
  • Loading branch information
robinvandernoord committed Nov 17, 2023
1 parent b96466c commit b48b758
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
15 changes: 3 additions & 12 deletions src/verysimpletransformers/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import questionary
import typer
from configuraptor import BinaryConfig
from configuraptor.helpers import as_binaryio
from rich import print

Expand All @@ -20,6 +19,7 @@
)
from .exceptions import CorruptedModelException, custom_excepthook
from .interactive import input_with_history
from .metadata import show_metadata
from .serve import _handle_predictions
from .support import RedirectStdStreams, devnull, has_stdin
from .types import SimpleTransformerProtocol
Expand Down Expand Up @@ -154,17 +154,8 @@ def show_info(filename: str) -> None:
with as_binaryio(filename) as f:
model, meta, valid = _from_vst(f, with_metadata=True, with_model=False)

def show_recursive(obj: typing.Any, level: int = 0) -> None:
for option, value in obj.__dict__.items():
if option.startswith("_"):
continue
if isinstance(value, BinaryConfig):
print("\t" * level, f"[yellow]{option}[/yellow] ▼")
show_recursive(value, level + 1)
else:
print("\t" * level, f"[yellow]{option}[/yellow] =", value)

show_recursive(meta)
print("[yellow]model class[/yellow] =", type(model))
show_metadata(meta)
print("[yellow]model loaded properly:[/yellow]", isinstance(model, SimpleTransformerProtocol))
if error:
print("[red]error:[/red]", error)
Expand Down
18 changes: 18 additions & 0 deletions src/verysimpletransformers/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
import re
import sys
import warnings
from typing import Any

import torch
import transformers
from plumbum import local
from plumbum.cmd import grep

from configuraptor import BinaryConfig
from rich import print

from .__about__ import __version__
from .metadata_schema import Metadata, MetaHeader, Version
from .versioning import get_version
Expand Down Expand Up @@ -129,3 +133,17 @@ def get_metadata(content_length: int, compression_level: int, device: str) -> Me
meta.meta_header = header

return meta


def show_metadata(meta: Metadata):
def show_recursive(obj: Any, level: int = 0) -> None:
for option, value in obj.__dict__.items():
if option.startswith("_"):
continue
if isinstance(value, BinaryConfig):
print("\t" * level, f"[yellow]{option}[/yellow] ▼")
show_recursive(value, level + 1)
else:
print("\t" * level, f"[yellow]{option}[/yellow] =", value)

show_recursive(meta)

0 comments on commit b48b758

Please sign in to comment.