diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2ea7861 --- /dev/null +++ b/.gitignore @@ -0,0 +1,31 @@ +# Python编译文件 +__pycache__/ +*.py[cod] +*$py.class + +# 打包目录 +dist/ +build/ +*.egg-info/ + +# 虚拟环境 +venv/ +env/ +ENV/ + +# IDE配置 +.idea/ +.vscode/ + +# 日志文件 +*.log + +# 打包文件 +*.spec +pod_config.zip +pod_config.json +pod.zip + +# 系统文件 +.DS_Store +Thumbs.db \ No newline at end of file diff --git a/build.py b/build.py new file mode 100644 index 0000000..627dc31 --- /dev/null +++ b/build.py @@ -0,0 +1,32 @@ +import PyInstaller.__main__ +import os +import shutil + +# 清理之前的构建文件 +if os.path.exists("build"): + shutil.rmtree("build") +if os.path.exists("dist"): + shutil.rmtree("dist") + +# 确保输出目录存在 +if not os.path.exists("dist"): + os.makedirs("dist") + +# 打包命令行版本 +PyInstaller.__main__.run([ + 'pod_client_cmd.py', + '--name=pod_client_cmd', + '--onefile', + '--console', + '--clean', # 清理临时文件 +]) + +# 打包GUI版本 +PyInstaller.__main__.run([ + 'pod_client.py', + '--name=pod_client_gui', + '--onefile', + '--noconsole', # GUI版本不显示控制台 + '--windowed', + '--clean', # 清理临时文件 +]) \ No newline at end of file diff --git a/const/app_config.py b/const/app_config.py index 0fb5dba..4a780e7 100644 --- a/const/app_config.py +++ b/const/app_config.py @@ -10,64 +10,89 @@ USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3' POD_MANAGER_URL = "https://models.chenyu.cn" - class AppType: - def __init__(self, name,identity_key,model_dir,plugin_dir,cloud_app_dir): + def __init__(self, + name, + identity_key, + model_dir, + plugin_dir, + cloud_app_dir): + """ + :param name: 应用名称 + :param identity_key: 应用标识 + :param model_dir: 模型目录 + :param plugin_dir: 插件目录 + :param cloud_app_dir: 云端应用目录 + """ self.name = name self.identity_key = identity_key self.model_dir = model_dir self.plugin_dir = plugin_dir self.cloud_app_dir = cloud_app_dir +class AppTypeEnum(Enum): + ComfyUI = AppType(name = "ComfyUI", + identity_key = "custom_nodes", + model_dir = "models", + plugin_dir = "custom_nodes", + cloud_app_dir = "/root/ComfyUI") + Forge = AppType(name = "Forge", + identity_key = "modules_forge", + model_dir = "models", + plugin_dir = "extensions", + cloud_app_dir = "/root/stable-diffusion-webui-forge") -class AppTypeEnum(Enum): - ComfyUI = AppType("ComfyUI","custom_nodes","models","custom_nodes","/root/ComfyUI") - Forge = AppType("Forge","modules_forge","models","extensions","/root/stable-diffusion-webui-forge") - StableDiffusion = AppType("StableDiffusion","extensions","models","extensions","/root/stable-diffusion-webui") + StableDiffusion = AppType(name = "StableDiffusion", + identity_key = "extensions", + model_dir = "models", + plugin_dir = "extensions", + cloud_app_dir = "/root/stable-diffusion-webui") def get_app_type(app_dir): for app_type in AppTypeEnum: if app_type.value.identity_key in os.listdir(app_dir): return app_type.value return None + def get_app_type_by_identity_key(name): for app_type in AppTypeEnum: if app_type.value.name == name: return app_type.value return None -class Model(BaseModel): - model_name: str - model_id: Optional[int] - sha256: str - cache_path: Optional[str] - file_path: list[str] - download_url: Optional[str] +class Model(BaseModel): # 模型 + model_name: str # 模型名称 + model_id: Optional[int] # 模型ID + sha256: str # 模型SHA256 + cache_path: Optional[str] # 缓存路径 + file_path: list[str] # 文件路径 + download_url: Optional[str] # 下载URL class Config: - protected_namespaces = () + protected_namespaces = () # 保护命名空间 + +class Plugin(BaseModel): # 插件 + name: str # 插件名称 + remote_url: str # 远程URL + commit_log: str # 提交日志 -class Plugin(BaseModel): - name: str - remote_url: str - commit_log: str -class PythonPackage(BaseModel): - name: Optional[str] - version: Optional[str] - remote_url: Optional[str] - type : Optional[str] - full_text: Optional[str] +class PythonPackage(BaseModel): # Python包 + name: Optional[str] # 名称 + version: Optional[str] # 版本 + remote_url: Optional[str] # 远程URL + type : Optional[str] # 类型 + full_text: Optional[str] # 完整文本 -class PodConfig(BaseModel): - app_dir: str - app_type: str - model_dir: str - plugin_dir: str - python: str - python_version: str - models: list[Model] - plugins: list[Plugin] - packages: list[PythonPackage] +class PodConfig(BaseModel): # Pod配置 + app_dir: str # 应用目录 + app_type: str # 应用类型 + model_dir: str # 模型目录 + plugin_dir: str # 插件目录 + python: str # Python路径 + python_version: str # Python版本 + models: list[Model] # 模型 + plugins: list[Plugin] # 插件 + packages: list[PythonPackage] # Python包 class Config: - protected_namespaces = () + protected_namespaces = () # 保护命名空间 diff --git a/pod-cloud.py b/pod-cloud.py index 5c0b20b..a4c548b 100644 --- a/pod-cloud.py +++ b/pod-cloud.py @@ -14,7 +14,7 @@ def load_pod_from_json(file_path: str) -> PodConfig: with open(file_path, 'r') as file: json_data = json.load(file) # 读取 JSON 文件 return PodConfig(**json_data) # 使用 Pydantic 将字典转换为对象 -base_dir = "/poddata" +base_dir = "/poddata/ComfyUI" if __name__ == "__main__": """读取当前pod压缩文件并解压到/poddata""" diff --git a/pod_client_cmd.py b/pod_client_cmd.py index 9a99999..77aaa98 100644 --- a/pod_client_cmd.py +++ b/pod_client_cmd.py @@ -74,7 +74,10 @@ def load_plugins(): repo_path = os.path.join(pod_config.plugin_dir, repo_dir) print( f"【提示】处理插件[{index + 1}/{len(repo_dirs)}]:{repo_path}") name, remote_url, commit_log = get_git_repo_info(repo_path) - plugin = Plugin(name=name, remote_url=remote_url, commit_log=commit_log) + try: + plugin = Plugin(name=name, remote_url=remote_url, commit_log=commit_log) + except: + pass pod_config.plugins.append(plugin) print(f"【提示】插件信息[{index + 1}/{len(repo_dirs)}]:{plugin}") diff --git a/pod_model_manager/app/models.py b/pod_model_manager/app/models.py index 09b8e71..e92741e 100644 --- a/pod_model_manager/app/models.py +++ b/pod_model_manager/app/models.py @@ -17,14 +17,14 @@ """ class Model(db.Model): - name = db.Column(db.String(256), nullable=False) # 模型名称 huggingface: repoid civiai: sha256 other: modelname - model_type = db.Column(db.String(32), nullable=False) # -1: 其他 0: C站模型 1: Huggingface模型 - sha256 = db.Column(db.String(128), primary_key=True) - cache_path = db.Column(db.String(256), nullable=True) # 缓存路径 - download_url = db.Column(db.String(1024), nullable=True) - status = db.Column(db.String(32), nullable=True,default=0) # 模型状态 0: 未下载 1: 已下载 2: 下载中 - size = db.Column(db.Integer, nullable=True) # 模型大小 - true_file_name = db.Column(db.String(256), nullable=True) # 真实文件名 + name = db.Column(db.String(256), nullable=False) # 模型名称 huggingface: repoid civiai: sha256 other: modelname + model_type = db.Column(db.String(32), nullable=False) # -1: 其他 0: C站模型 1: Huggingface模型 + sha256 = db.Column(db.String(128), primary_key=True) # 模型SHA256 + cache_path = db.Column(db.String(256), nullable=True) # 缓存路径 + download_url = db.Column(db.String(1024), nullable=True) # 下载URL + status = db.Column(db.String(32), nullable=True,default=0) # 模型状态 0: 未下载 1: 已下载 2: 下载中 + size = db.Column(db.Integer, nullable=True) # 模型大小 + true_file_name = db.Column(db.String(256), nullable=True) # 真实文件名 def __repr__(self): return f'' diff --git a/pod_model_manager/app/routes.py b/pod_model_manager/app/routes.py index ed3da8a..fe24790 100644 --- a/pod_model_manager/app/routes.py +++ b/pod_model_manager/app/routes.py @@ -11,7 +11,7 @@ def create_model(): data = request.get_json() new_model = Model() - identity = data['name'] # huggingface就是repoId c站就是sha256 + identity = data['name'] # huggingface就是repoId c站就是sha256 new_model.model_type = data['model_type'] if Model.query.get(identity) is not None: return jsonify({'message': '模型已存在'}), 400 diff --git a/utils/util.py b/utils/util.py index ee16cae..8ee26af 100644 --- a/utils/util.py +++ b/utils/util.py @@ -68,7 +68,7 @@ def add_models(sha256): response.raise_for_status() # 如果响应状态码不是 200,抛出异常 except requests.exceptions.RequestException as e: logging.error(f"请求失败: {e}") - raise e + # raise e def get_git_repo_info(repo_path): """获取 Git 仓库的地址、名称和当前 commit log"""