forked from LeoYoung-code/Aigc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
42 lines (32 loc) · 996 Bytes
/
main.py
File metadata and controls
42 lines (32 loc) · 996 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from abc import ABC, abstractmethod
from typing import Type, Dict
import config
import param
from class_interface import ClassInterface
# 定义接口
class ClassFactoryInterface(ABC):
@abstractmethod
def get_class(self, model_name: str) -> 'ClassInterface':
pass
# 让 ClassFactory 实现接口
class ClassFactory(ClassFactoryInterface):
def __init__(self):
self._class_map: Dict[str, Type['ClassInterface']] = config.class_map_config
def get_class(self, model_name: str) -> 'ClassInterface':
cls = self._class_map.get(model_name)
if cls is None:
raise ValueError(f"Unknown class: {model_name}")
return cls()
def main():
params = param.get_model_name()
if params is None:
return
factory = ClassFactory()
try:
instance = factory.get_class(params)
instance.initialize()
instance.request()
except ValueError as e:
print(e)
if __name__ == "__main__":
main()