Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added the download model from url feature #2423

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

codezeros
Copy link

  • support all downloadable urls

Models can be downloaded simply by copying and pasting their URLs.

@codezeros
Copy link
Author

preview

Copy link
Collaborator

@mashb1t mashb1t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General feedback: thank you for the implementation, this can be very useful if people don't know the file structure.

Code feedback:

  • do not spam code comments for trivial things, as mentioned.
  • do not autoformat whole files on existing projects, only your part of the implementation.
  • add translations for every outpout, every message, etc. to en.json
  • add argument for disabling the whole tab as not everyone wants/needs/allows users to download newc models, such as on hosted environments, as this may cause a huge increase in traffic (=> more costs) and may be abused, especially in a multi-user environment.

Looking forward to your adjustments.

modules/download_models.py Outdated Show resolved Hide resolved
modules/load_paths.py Outdated Show resolved Hide resolved
modules/load_paths.py Outdated Show resolved Hide resolved
modules/load_paths.py Outdated Show resolved Hide resolved
modules/download_models.py Outdated Show resolved Hide resolved
modules/download_models.py Outdated Show resolved Hide resolved
webui.py Outdated Show resolved Hide resolved
webui.py Outdated Show resolved Hide resolved
webui.py Outdated Show resolved Hide resolved
webui.py Outdated Show resolved Hide resolved
@mashb1t mashb1t added the Size M medium change, isolated, testing with care label Mar 3, 2024
@codezeros
Copy link
Author

codezeros commented Mar 3, 2024

General feedback: thank you for the implementation, this can be very useful if people don't know the file structure.

Code feedback:

* do not spam code comments for trivial things, as mentioned.

* do not autoformat whole files on existing projects, only your part of the implementation.

* add translations for every outpout, every message, etc. to en.json

* add argument for disabling the whole tab as not everyone wants/needs/allows users to download newc models, such as on hosted environments, as this may cause a huge increase in traffic (=> more costs) and may be abused, especially in a multi-user environment.

Looking forward to your adjustments.

@mashb1t thank you for your feedback
i have now removed unnecessary comments and make the codebase simple and effective and we can set the path now directly in json config file instead of dynamically generate json on start of app each time run.

if there any other that need to improve feel free to tell me :)

@codezeros codezeros requested a review from mashb1t March 3, 2024 18:18
Copy link
Collaborator

@mashb1t mashb1t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep in mind to add the translations to en.json as well as add an argument to completely not render the output for all elements when set.
Argument can be --disable-download-tab or similar. You can orient yourself on --disable-metadata + all occurrences of args_manager.args.disable_metadata in the code

modules/download_models.py Outdated Show resolved Hide resolved
modules/download_models.py Show resolved Hide resolved
modules/model_loader.py Outdated Show resolved Hide resolved
modules/model_loader.py Outdated Show resolved Hide resolved
webui.py Outdated Show resolved Hide resolved
webui.py Outdated Show resolved Hide resolved
webui.py Outdated Show resolved Hide resolved
webui.py Outdated Show resolved Hide resolved
@uptotec
Copy link

uptotec commented Mar 4, 2024

hi! if you can only download from civitAI you can get the filename and folder from the api. civitai provide array of files the first one is always the model file. the api also give you the model type you can select the folder based on the model type.

@codezeros
Copy link
Author

hi! if you can only download from civitAI you can get the filename and folder from the api. civitai provide array of files the first one is always the model file. the api also give you the model type you can select the folder based on the model type.

@uptotec yes, for that we need to add store feature using civitai api but this is for downloading models directly into the application using url only also i have tested with huggingface and civitai urls and some other it works! without any issues but note that some model may have sign-in access restriction for those we can not download directly just with url alone

@codezeros codezeros force-pushed the download_model_from_url_feature branch from 64751d8 to 4820f31 Compare March 4, 2024 14:42
@codezeros codezeros requested a review from mashb1t March 4, 2024 14:55
@codezeros
Copy link
Author

codezeros commented Mar 4, 2024

@mashb1t i have modified according to your suggestion and also we can disable download tab using argument --disable-download-tab and also using checkbox in debug (still in progress any suggestions would help!) and added translation :)

@mashb1t
Copy link
Collaborator

mashb1t commented Mar 4, 2024

@codezeros thanks for the update, much appreciated. Will do the review during this week.
I'm wondering, which benefit would it have to be able to toggle the tab in the developer debug settings?

@codezeros
Copy link
Author

@codezeros thanks for the update, much appreciated. Will do the review during this week. I'm wondering, which benefit would it have to be able to toggle the tab in the developer debug settings?

image

@mashb1t i thought user can also disable the tab in fooocus itself to simply make the config easier for non-tech users which may help

@@ -433,6 +453,7 @@ def update_history_link():
disable_seed_increment = gr.Checkbox(label='Disable seed increment',
info='Disable automatic seed increment when image number is > 1.',
value=False)
disable_download_checkbox = gr.Checkbox(label='Disable Download Tab',info='Disable the download tab when clicked',value=modules.config.default_download_tab_checkbox,elem_classes='min_check')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set interactive to false when arg is set

@@ -541,6 +562,9 @@ def model_refresh_clicked():
advanced_checkbox.change(lambda x: gr.update(visible=x), advanced_checkbox, advanced_column,
queue=False, show_progress=False) \
.then(fn=lambda: None, _js='refresh_grid_delayed', queue=False, show_progress=False)
disable_download_checkbox.change(lambda x: gr.update(visible=x), disable_download_checkbox, download_tab) \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not process/output when arg is true

@@ -332,6 +333,25 @@ def update_history_link():
show_progress=False).then(
lambda: None, _js='()=>{refresh_style_localization();}')

if not args_manager.args.disable_download_tab:
with gr.Tab(label='Download',visible=modules.config.default_download_tab_checkbox)as download_tab:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
with gr.Tab(label='Download',visible=modules.config.default_download_tab_checkbox)as download_tab:
with gr.Tab(label='Download', visible=modules.config.default_download_tab_checkbox) as download_tab:

path_controlnet = get_dir_or_set_default('path_controlnet', '../models/controlnet/')
path_clip_vision = get_dir_or_set_default('path_clip_vision', '../models/clip_vision/')
path_fooocus_expansion = get_dir_or_set_default('path_fooocus_expansion', '../models/prompt_expansion/fooocus_expansion')
config_paths = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please do it the other way round.
Instead of using an array and then assigning variables with keys it's more robust to assign variables first and then build an array from vars. This eliminates the need for array key string reading.

@@ -318,6 +347,11 @@ def get_config_item_or_set_default(key, default_value, validator, disable_empty_
default_value=False,
validator=lambda x: isinstance(x, bool)
)
default_download_tab_checkbox = get_config_item_or_set_default(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use a more descriptive naming here, e.g. default_show_download_tab

@xhoxye
Copy link
Contributor

xhoxye commented Mar 6, 2024

Some personal advice:

  1. You can list the fooocus's built-in model download links in downloadtab and add other backup download links. Select Download through the drop-down option to solve the problem of model download failure when fooocus is started.
  2. For Civitai, you can refresh the update of the model version

from torch.hub import download_url_to_file
download_url_to_file(url, cached_file, progress=progress)
except Exception as e:
print(f"Failed to download \"{url}\" to {cached_file}, reason : {e}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codezeros downloading an invalid URL still reports as successful to the frontend despite raising an exception.
This has to be fixed (reverted).

Failed to download "invalid url" to /Volumes/data/private/development/ai/fooocus/models/checkpoints/invalid url, reason : unknown url type: 'invalid url'

Screenshot 2024-03-09 at 16 19 39

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mashb1t thanks for notifying the problem i will look into it and also making some improvements based on previous feedback (in progress)

@mashb1t mashb1t added the feedback pending Waiting for further information label Mar 9, 2024
@mashb1t mashb1t added feedback pending Waiting for further information and removed feedback pending Waiting for further information labels Jun 30, 2024
@sd-jack
Copy link

sd-jack commented Jul 7, 2024

That's enhancement is great! Thank you @codezeros

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feedback pending Waiting for further information Size M medium change, isolated, testing with care
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants