├── .github └── FUNDING.yml ├── LICENSE ├── README.md ├── install.py └── scripts └── huggingface.py /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: camenduru 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: camenduru 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry 13 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 🐣 Please follow me for new updates https://twitter.com/camenduru
2 | 🔥 Please join our discord server https://discord.gg/k5BwmmvJJU
3 | 🥳 Please join my patreon community https://patreon.com/camenduru
4 | 5 | # Push to 🤗 Hugging Face 6 | 7 | ![Push Folder to Hugging Face](https://user-images.githubusercontent.com/54370274/216768707-4efb8a30-6826-409e-8bf1-6e74fc26fdab.jpg) 8 | 9 | To install it, clone the repo into the `extensions` directory and restart the web ui: 10 | 11 | `git clone https://github.com/camenduru/stable-diffusion-webui-huggingface` 12 | 13 | `pip install huggingface-hub==0.11.1` 14 | -------------------------------------------------------------------------------- /install.py: -------------------------------------------------------------------------------- 1 | import launch 2 | 3 | if not launch.is_installed("huggingface_hub"): 4 | launch.run_pip("install huggingface-hub==0.11.0", "requirements for Push to Hugging Face extension") 5 | -------------------------------------------------------------------------------- /scripts/huggingface.py: -------------------------------------------------------------------------------- 1 | import os 2 | import numpy as np 3 | import gradio as gr 4 | from huggingface_hub import model_info, create_repo, create_branch, upload_folder, upload_file 5 | from huggingface_hub.utils import RepositoryNotFoundError, RevisionNotFoundError 6 | from modules import scripts, script_callbacks 7 | from subprocess import getoutput 8 | 9 | def run(command): 10 | out = getoutput(f"{command}") 11 | return out 12 | 13 | def push_folder(folder_from, folder_to, branch, token): 14 | try: 15 | repo_exists = True 16 | r_info = model_info(folder_to, token=token) 17 | except RepositoryNotFoundError: 18 | repo_exists = False 19 | finally: 20 | if repo_exists: 21 | print(r_info) 22 | else: 23 | create_repo(folder_to, private=True, token=token) 24 | try: 25 | branch_exists = True 26 | b_info = model_info(folder_to, revision=branch, token=token) 27 | except RevisionNotFoundError: 28 | branch_exists = False 29 | finally: 30 | if branch_exists: 31 | print(b_info) 32 | else: 33 | create_branch(folder_to, branch=branch, token=token) 34 | upload_folder(folder_path=folder_from, path_in_repo="", revision=branch, repo_id=folder_to, commit_message=f"folder", token=token) 35 | return "push folder done!" 36 | 37 | def push_file(file_from, file_to, file_name, branch, token): 38 | try: 39 | repo_exists = True 40 | r_info = model_info(file_to, token=token) 41 | except RepositoryNotFoundError: 42 | repo_exists = False 43 | finally: 44 | if repo_exists: 45 | print(r_info) 46 | else: 47 | create_repo(file_to, private=True, token=token) 48 | try: 49 | branch_exists = True 50 | b_info = model_info(file_to, revision=branch, token=token) 51 | except RevisionNotFoundError: 52 | branch_exists = False 53 | finally: 54 | if branch_exists: 55 | print(b_info) 56 | else: 57 | create_branch(file_to, branch=branch, token=token) 58 | upload_file(path_or_fileobj=file_from, path_in_repo=file_name, revision=branch, repo_id=file_to, commit_message=f"file", token=token) 59 | return "push file done!" 60 | 61 | def on_ui_tabs(): 62 | with gr.Blocks() as huggingface: 63 | gr.Markdown( 64 | """ 65 | ### Push Folder to 🤗 Hugging Face 66 | folder_from = 🖼 Windows: C:\\Users\\PC\\Desktop\\MyModelFolder 🐧 Linux: /home/user/app/stable-diffusion-webui/my-model-folder
67 | folder_to = camenduru/mymodel
68 | branch = main
69 | token = get from [https://huggingface.co/settings/tokens](https://huggingface.co/settings/tokens) new token role=write 70 | """) 71 | with gr.Group(): 72 | with gr.Box(): 73 | with gr.Row().style(equal_height=True): 74 | text_folder_from = gr.Textbox(show_label=False, max_lines=1, placeholder="folder_from") 75 | text_folder_to = gr.Textbox(show_label=False, max_lines=1, placeholder="folder_to") 76 | text_folder_branch = gr.Textbox(show_label=False, value="main", max_lines=1, placeholder="branch") 77 | text_folder_token = gr.Textbox(show_label=False, max_lines=1, placeholder="🤗 token") 78 | out_folder = gr.Textbox(show_label=False) 79 | with gr.Row().style(equal_height=True): 80 | btn_push_folder = gr.Button("Push Folder To 🤗") 81 | btn_push_folder.click(push_folder, inputs=[text_folder_from, text_folder_to, text_folder_branch, text_folder_token], outputs=out_folder) 82 | gr.Markdown( 83 | """ 84 | ### Push File to 🤗 Hugging Face 85 | file_from = 🖼 Windows: C:\\Users\\PC\\Desktop\\MyModelFolder\\model.ckpt 🐧 Linux: /home/user/app/stable-diffusion-webui/my-model-folder/model.ckpt
86 | file_to = camenduru/mymodel
87 | file_name = model.ckpt
88 | branch = main
89 | token = get from [https://huggingface.co/settings/tokens](https://huggingface.co/settings/tokens) new token role=write 90 | """) 91 | with gr.Group(): 92 | with gr.Box(): 93 | with gr.Row().style(equal_height=True): 94 | text_file_from = gr.Textbox(show_label=False, max_lines=1, placeholder="file_from") 95 | text_file_to = gr.Textbox(show_label=False, max_lines=1, placeholder="file_to") 96 | text_file_name = gr.Textbox(show_label=False, max_lines=1, placeholder="file_name") 97 | text_file_branch = gr.Textbox(show_label=False, value="main", max_lines=1, placeholder="branch") 98 | text_file_token = gr.Textbox(show_label=False, max_lines=1, placeholder="🤗 token") 99 | out_file = gr.Textbox(show_label=False) 100 | with gr.Row().style(equal_height=True): 101 | btn_push_file = gr.Button("Push File To 🤗") 102 | btn_push_file.click(push_file, inputs=[text_file_from, text_file_to, text_file_name, text_file_branch, text_file_token], outputs=out_file) 103 | gr.Markdown( 104 | """ 105 | ### 🦒 Colab Run Command 106 | ```py 107 | model: wget https://huggingface.co/ckpt/anything-v4.5-vae-swapped/resolve/main/anything-v4.5-vae-swapped.safetensors -O /content/stable-diffusion-webui/models/Stable-diffusion/anything-v4.5-vae-swapped.safetensors 108 | lora: wget https://huggingface.co/embed/Sakimi-Chan_LoRA/resolve/main/Sakimi-Chan_LoRA.safetensors -O /content/stable-diffusion-webui/extensions/sd-webui-additional-networks/models/lora/Sakimi-Chan_LoRA.safetensors 109 | embed: wget https://huggingface.co/embed/bad_prompt/resolve/main/bad_prompt_version2.pt -O /content/stable-diffusion-webui/embeddings/bad_prompt_version2.pt 110 | vae: wget https://huggingface.co/ckpt/trinart_characters_19.2m_stable_diffusion_v1/resolve/main/autoencoder_fix_kl-f8-trinart_characters.ckpt -O /content/stable-diffusion-webui/models/VAE/autoencoder_fix_kl-f8-trinart_characters.vae.pt 111 | zip outputs folder: zip -r /content/outputs.zip /content/stable-diffusion-webui/outputs 112 | ``` 113 | """) 114 | with gr.Group(): 115 | with gr.Box(): 116 | command = gr.Textbox(show_label=False, max_lines=1, placeholder="command") 117 | out_text = gr.Textbox(show_label=False) 118 | btn_run = gr.Button("run command") 119 | btn_run.click(run, inputs=command, outputs=out_text) 120 | return (huggingface, "Hugging Face", "huggingface"), 121 | script_callbacks.on_ui_tabs(on_ui_tabs) 122 | --------------------------------------------------------------------------------