From cd70937b7f3a44669f6c011376bbb44fb8201045 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Mon, 17 Jun 2024 10:51:08 +1000 Subject: [PATCH] feat(api): improved model install confirmation page styling & messaging --- invokeai/app/api/routers/model_manager.py | 118 ++++++++++++++++------ 1 file changed, 85 insertions(+), 33 deletions(-) diff --git a/invokeai/app/api/routers/model_manager.py b/invokeai/app/api/routers/model_manager.py index f2fb0932e5..99f00423c6 100644 --- a/invokeai/app/api/routers/model_manager.py +++ b/invokeai/app/api/routers/model_manager.py @@ -514,50 +514,93 @@ async def install_model( response_class=HTMLResponse, ) async def install_hugging_face_model( - source: str = Query(description="Hugging Face repo_id to install"), + source: str = Query(description="HuggingFace repo_id to install"), ) -> HTMLResponse: """Install a Hugging Face model using a string identifier.""" - def generate_html(message: str) -> str: + def generate_html(title: str, heading: str, repo_id: str, is_error: bool, message: str | None = "") -> str: + if message: + message = f"

{message}

" + title_class = "error" if is_error else "success" return f""" - - - - - -
-

{message}

-
- - + + + + {title} + + + + +
+
+

{heading}

+ {message} +

Repo ID: {repo_id}

+
+
+ + + """ try: metadata = HuggingFaceMetadataFetch().from_id(source) assert isinstance(metadata, ModelMetadataWithFiles) - message = "Your Hugging Face model is installing now. You can close this tab and check the Model Manager for installation progress." except UnknownMetadataException: - message = "No HuggingFace repository found with that repo id." - return HTMLResponse(content=generate_html(message), status_code=400) + title = "Unable to Install Model" + heading = "No HuggingFace repository found with that repo ID." + message = "Ensure the repo ID is correct and try again." + return HTMLResponse(content=generate_html(title, heading, source, True, message), status_code=400) logger = ApiDependencies.invoker.services.logger try: installer = ApiDependencies.invoker.services.model_manager.install - if metadata.is_diffusers: installer.heuristic_import( source=source, @@ -569,12 +612,21 @@ async def install_hugging_face_model( inplace=False, ) else: - message = "This HuggingFace repo has multiple models. Please use the Model Manager to install this." + title = "Unable to Install Model" + heading = "This HuggingFace repo has multiple models." + message = "Please use the Model Manager to install this model." + return HTMLResponse(content=generate_html(title, heading, source, True, message), status_code=200) + + title = "Model Install Started" + heading = "Your HuggingFace model is installing now." + message = "You can close this tab and check the Model Manager for installation progress." + return HTMLResponse(content=generate_html(title, heading, source, False, message), status_code=201) except Exception as e: logger.error(str(e)) - message = "There was an error with installing this model. Please use the Model Manager to install this." - - return HTMLResponse(content=generate_html(message), status_code=201) + title = "Unable to Install Model" + heading = "There was an problem installing this model." + message = 'Please use the Model Manager directly to install this model. If the issue persists, ask for help on discord.' + return HTMLResponse(content=generate_html(title, heading, source, True, message), status_code=500) @model_manager_router.get(