Skip to content

Commit

Permalink
Feature scan info (#53)
Browse files Browse the repository at this point in the history
* pref: migrate fetch model info to end back

* fix(download): can't select model type

* feat: add scan model info

* feat: add trigger button in setting

* feat: add printing logs

* chore: add explanation of scan model info
  • Loading branch information
hayden-fr authored Nov 21, 2024
1 parent 6ae7e18 commit 659637c
Show file tree
Hide file tree
Showing 20 changed files with 918 additions and 425 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,10 @@ npm run build
- Read, edit and save notes. (Saved as a `.md` file beside the model).
- Change or remove a model's preview image.
- View training tags and use the random tag generator to generate prompt ideas. (Inspired by the one in A1111.)

### Scan Model Information

<img src="demo/scan-model-info.png" alt="Model Manager Demo Screenshot" style="max-width: 100%; max-height: 300px"/>

- Scan models and try to download information & preview.
- Support migration from `cdb-boop/ComfyUI-Model-Manager/main`
70 changes: 65 additions & 5 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,26 @@
from .py import config
from .py import utils

extension_uri = utils.normalize_path(os.path.dirname(__file__))

requirements_path = utils.join_path(extension_uri, "requirements.txt")

with open(requirements_path, "r", encoding="utf-8") as f:
requirements = f.readlines()

requirements = [x.strip() for x in requirements]
requirements = [x for x in requirements if not x.startswith("#")]

uninstalled_package = [p for p in requirements if not utils.is_installed(p)]

if len(uninstalled_package) > 0:
utils.print_info(f"Install dependencies...")
for p in uninstalled_package:
utils.pip_install(p)


# Init config settings
config.extension_uri = utils.normalize_path(os.path.dirname(__file__))
config.extension_uri = extension_uri
utils.resolve_model_base_paths()

version = utils.get_current_version()
Expand Down Expand Up @@ -97,9 +114,8 @@ async def create_model(request):
- downloadUrl: download url.
- hash: a JSON string containing the hash value of the downloaded model.
"""
post = await request.post()
task_data = await request.json()
try:
task_data = dict(post)
task_id = await services.create_model_download_task(task_data, request)
return web.json_response({"success": True, "data": {"taskId": task_id}})
except Exception as e:
Expand Down Expand Up @@ -158,13 +174,12 @@ async def update_model(request):
index = int(request.match_info.get("index", None))
filename = request.match_info.get("filename", None)

post: dict = await request.post()
model_data: dict = await request.json()

try:
model_path = utils.get_valid_full_path(model_type, index, filename)
if model_path is None:
raise RuntimeError(f"File {filename} not found")
model_data = dict(post)
services.update_model(model_path, model_data)
return web.json_response({"success": True})
except Exception as e:
Expand Down Expand Up @@ -194,6 +209,37 @@ async def delete_model(request):
return web.json_response({"success": False, "error": error_msg})


@routes.get("/model-manager/model-info")
async def fetch_model_info(request):
"""
Fetch model information from network with model page.
"""
try:
model_page = request.query.get("model-page", None)
result = services.fetch_model_info(model_page)
return web.json_response({"success": True, "data": result})
except Exception as e:
error_msg = f"Fetch model info failed: {str(e)}"
utils.print_error(error_msg)
return web.json_response({"success": False, "error": error_msg})


@routes.post("/model-manager/model-info/scan")
async def download_model_info(request):
"""
Create a task to download model information.
"""
post = await utils.get_request_body(request)
try:
scan_mode = post.get("scanMode", "diff")
await services.download_model_info(scan_mode)
return web.json_response({"success": True})
except Exception as e:
error_msg = f"Download model info failed: {str(e)}"
utils.print_error(error_msg)
return web.json_response({"success": False, "error": error_msg})


@routes.get("/model-manager/preview/{type}/{index}/{filename:.*}")
async def read_model_preview(request):
"""
Expand Down Expand Up @@ -236,6 +282,20 @@ async def read_download_preview(request):
return web.FileResponse(preview_path)


@routes.post("/model-manager/migrate")
async def migrate_legacy_information(request):
"""
Migrate legacy information.
"""
try:
await services.migrate_legacy_information()
return web.json_response({"success": True})
except Exception as e:
error_msg = f"Download model info failed: {str(e)}"
utils.print_error(error_msg)
return web.json_response({"success": False, "error": error_msg})


WEB_DIRECTORY = "web"
NODE_CLASS_MAPPINGS = {}
__all__ = ["WEB_DIRECTORY", "NODE_CLASS_MAPPINGS"]
Binary file added demo/scan-model-info.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"@types/lodash": "^4.17.9",
"@types/markdown-it": "^14.1.2",
"@types/node": "^22.5.5",
"@types/turndown": "^5.0.5",
"@vitejs/plugin-vue": "^5.1.4",
"autoprefixer": "^10.4.20",
"eslint": "^9.10.0",
Expand All @@ -40,15 +39,13 @@
"markdown-it": "^14.1.0",
"markdown-it-metadata-block": "^1.0.6",
"primevue": "^4.0.7",
"turndown": "^7.2.0",
"vue": "^3.4.31",
"vue-i18n": "^9.13.1",
"yaml": "^2.6.0"
},
"lint-staged": {
"./**/*.{js,ts,tsx,vue}": [
"prettier --write",
"git add"
"prettier --write"
]
}
}
23 changes: 0 additions & 23 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 659637c

Please sign in to comment.