Comfy-Org/comfy-cli

Any attempts to download model from civitai.com?

Closed this issue · 6 comments

when trying to download models from civitai using

comfy model download --url https://civitai.com/api/download/models/xxxxx

I get:

DownloadException: Failed to download file.
Unauthorized download (401), you might need to manually log into browser to download one

Do you think we should be able login via command line somehow and download the model?

We have great support for managing custom nodes, and I hope there can be more support for model management. I still find collecting models and manage them very time consuming.

Also managing the sharing of models across different instances can be very beneficial too.

✗ comfy model download --url https://civitai.com/models/43331/majicmix-realistic
? Enter filename to save model as majicmixRealistic_v7.safetensors
Start downloading URL: https://civitai.com/api/download/models/176425 into /Users/yoland/Documents/comfy/ComfyUI/models/checkpoints/majicmixRealistic_v7.safetensors
Downloading 2033 MB ╸━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━   2% 0:09:13
Download interrupted, cleanup files? [y/N]: y

I just realized that in your error, you already are using the API download link, I can't reproduce this error

Very interestly, it depends on which model I was downloading! Sorry for omitting the model id number.
Here is the rerun, first one 450029 is a success, and the second one 503451 is a failure:

(comfy-cli) [clash] PS E:\comfy> comfy model download --url https://civitai.com/api/download/models/450029
? Enter filename to save model as 450029
Start downloading URL: https://civitai.com/api/download/models/450029 into E:\comfy\models\checkpoints\450029
Downloading 217 MB ━━━━━╸━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━  14% 0:00:16
Download interrupted, cleanup files? [y/N]: y
(comfy-cli) [clash] PS E:\comfy> comfy model download --url https://civitai.com/api/download/models/503451
? Enter filename to save model as 503451
Start downloading URL: https://civitai.com/api/download/models/503451 into E:\comfy\models\checkpoints\503451
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ E:\comfy-cli.venv\lib\site-packages\comfy_cli\tracking.py:88 in wrapper                          │
│                                                                                                  │
│    85 │   │   │   )                                                                              │
│    86 │   │   │   track_event(command_name, properties=filtered_kwargs)                          │
│    87 │   │   │                                                                                  │
│ ❱  88 │   │   │   return func(*args, **kwargs)                                                   │
│    89 │   │                                                                                      │
│    90 │   │   return wrapper                                                                     │
│    91                                                                                            │
│                                                                                                  │
│ ╭──────────────────────────────────── locals ─────────────────────────────────────╮              │
│ │            args = ()                                                            │              │
│ │    command_name = 'model:download'                                              │              │
│ │ filtered_kwargs = {                                                             │              │
│ │                   │   'url': 'https://civitai.com/api/download/models/503451',  │              │
│ │                   │   'relative_path': 'models/checkpoints',                    │              │
│ │                   │   'cli_version': '0.0.23',                                  │              │
│ │                   │   'tracing_id': 'a6c9fcc2-723f-4a13-955a-1bc0f3ec2e02'      │              │
│ │                   }                                                             │              │
│ │            func = <function download at 0x00000211554B1AB0>                     │              │
│ │          kwargs = {                                                             │              │
│ │                   │   'ctx': <click.core.Context object at 0x000002115550D450>, │              │
│ │                   │   'url': 'https://civitai.com/api/download/models/503451',  │              │
│ │                   │   'relative_path': 'models/checkpoints'                     │              │
│ │                   }                                                             │              │
│ │     sub_command = 'model'                                                       │              │
│ ╰─────────────────────────────────────────────────────────────────────────────────╯              │
│                                                                                                  │
│ E:\comfy-cli.venv\lib\site-packages\comfy_cli\command\models\models.py:65 in download            │
│                                                                                                  │
│    62 │                                                                                          │
│    63 │   # File does not exist, proceed with download                                           │
│    64 │   print(f"Start downloading URL: {url} into {local_filepath}")                           │
│ ❱  65 │   download_file(url, local_filepath)                                                     │
│    66                                                                                            │
│    67                                                                                            │
│    68 @app.command()                                                                             │
│                                                                                                  │
│ ╭────────────────────────────── locals ──────────────────────────────╮                           │
│ │            ctx = <click.core.Context object at 0x000002115550D450> │                           │
│ │ local_filename = '503451'                                          │                           │
│ │ local_filepath = WindowsPath('E:/comfy/models/checkpoints/503451') │                           │
│ │  relative_path = 'models/checkpoints'                              │                           │
│ │            url = 'https://civitai.com/api/download/models/503451'  │                           │
│ ╰────────────────────────────────────────────────────────────────────╯                           │
│                                                                                                  │
│ E:\comfy-cli.venv\lib\site-packages\comfy_cli\file_utils.py:53 in download_file                  │
│                                                                                                  │
│    50 │   │   │   │   │   local_filepath.unlink()                                                │
│    51 │   │   else:                                                                              │
│    52 │   │   │   status_reason = guess_status_code_reason(response.status_code)                 │
│ ❱  53 │   │   │   raise DownloadException(f"Failed to download file.\n{status_reason}")          │
│    54                                                                                            │
│    55                                                                                            │
│    56 def zip_files(zip_filename):                                                               │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │          httpx = <module 'httpx' from                                                        │ │
│ │                  'E:\\comfy-cli.venv\\lib\\site-packages\\httpx\\__init__.py'>               │ │
│ │ local_filepath = WindowsPath('E:/comfy/models/checkpoints/503451')                           │ │
│ │       response = <Response [401 Unauthorized]>                                               │ │
│ │  status_reason = 'Unauthorized download (401), you might need to manually log into browser   │ │
│ │                  to down'+8                                                                  │ │
│ │            url = 'https://civitai.com/api/download/models/503451'                            │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
DownloadException: Failed to download file.
Unauthorized download (401), you might need to manually log into browser to download one

Hmm, thank you for sending that! It's because that one is a private model that requires login in civitai. I ll first add a warning for private model, but also we can support API token as a local config value you can add, and it will just use that to fetch the model
Screenshot 2024-05-15 at 5 22 04 PM

Hmm, thank you for sending that! It's because that one is a private model that requires login in civitai. I ll first add a warning for private model, but also we can support API token as a local config value you can add, and it will just use that to fetch the model Screenshot 2024-05-15 at 5 22 04 PM

Yes, yes. I thought every model was a private model! Ha-ha!
And earlier I was trying to request a feature to support some kind of token for civitai to verify the users' account!

#62

Adding support for civitai API token