mirror of
https://github.com/HumanAIGC/lite-avatar.git
synced 2026-02-05 18:09:20 +08:00
add files
This commit is contained in:
17
funasr_local/utils/build_dataclass.py
Normal file
17
funasr_local/utils/build_dataclass.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import argparse
|
||||
import dataclasses
|
||||
|
||||
from typeguard import check_type
|
||||
|
||||
|
||||
def build_dataclass(dataclass, args: argparse.Namespace):
|
||||
"""Helper function to build dataclass from 'args'."""
|
||||
kwargs = {}
|
||||
for field in dataclasses.fields(dataclass):
|
||||
if not hasattr(args, field.name):
|
||||
raise ValueError(
|
||||
f"args doesn't have {field.name}. You need to set it to ArgumentsParser"
|
||||
)
|
||||
check_type(field.name, getattr(args, field.name), field.type)
|
||||
kwargs[field.name] = getattr(args, field.name)
|
||||
return dataclass(**kwargs)
|
||||
Reference in New Issue
Block a user