Spaces:
Running
Running
Upload utils.py
#1
by surpise - opened
- utils/utils.py +19 -0
utils/utils.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import ruamel.yaml
|
| 2 |
+
|
| 3 |
+
def read_yaml_file(yaml_path: str, to_dict=True):
|
| 4 |
+
"""read from yaml file"""
|
| 5 |
+
yaml = ruamel.yaml.YAML()
|
| 6 |
+
with open(yaml_path, "r") as file:
|
| 7 |
+
# yaml_content = yaml.safe_load(file)
|
| 8 |
+
yaml_content = yaml.load(file)
|
| 9 |
+
yaml_content = dict(yaml_content) if to_dict else yaml_content
|
| 10 |
+
return yaml_content
|
| 11 |
+
|
| 12 |
+
class Singleton(type):
|
| 13 |
+
_instances = {}
|
| 14 |
+
|
| 15 |
+
def __call__(cls, *args, **kwargs):
|
| 16 |
+
if cls not in cls._instances:
|
| 17 |
+
cls._instances[cls] = super(Singleton, cls).__call__(*args,
|
| 18 |
+
**kwargs)
|
| 19 |
+
return cls._instances[cls]
|