Spaces:
Running
Running
Upload 3 files
Browse files- app.py +2 -2
- civitai_to_hf.py +19 -7
- utils.py +4 -0
app.py
CHANGED
|
@@ -9,7 +9,7 @@ css = """
|
|
| 9 |
with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", fill_width=True, css=css, delete_cache=(60, 3600)) as demo:
|
| 10 |
with gr.Column():
|
| 11 |
gr.Markdown("# CivitAI to HF🤗 Downloader & Uploader", elem_classes="title")
|
| 12 |
-
with gr.Accordion("Search Civitai", open=
|
| 13 |
with gr.Row():
|
| 14 |
search_civitai_type = gr.CheckboxGroup(label="Type", choices=CIVITAI_TYPE, value=["Checkpoint", "LORA"])
|
| 15 |
search_civitai_basemodel = gr.CheckboxGroup(label="Base model", choices=CIVITAI_BASEMODEL, value=[])
|
|
@@ -23,7 +23,7 @@ with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", fill_width=True, css=css, delete_ca
|
|
| 23 |
with gr.Row():
|
| 24 |
search_civitai_json = gr.JSON(value={}, visible=False)
|
| 25 |
search_civitai_desc = gr.Markdown(value="", visible=False)
|
| 26 |
-
search_civitai_result = gr.Dropdown(label="Search Results", choices=[("", "")], value="", allow_custom_value=True, visible=False)
|
| 27 |
search_civitai_add = gr.Button("Add to download URLs")
|
| 28 |
dl_url = gr.Textbox(label="Download URL(s)", placeholder="https://civitai.com/api/download/models/28907\n...", value="", lines=2, max_lines=255)
|
| 29 |
civitai_key = gr.Textbox(label="Your Civitai Key", value="", max_lines=1)
|
|
|
|
| 9 |
with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", fill_width=True, css=css, delete_cache=(60, 3600)) as demo:
|
| 10 |
with gr.Column():
|
| 11 |
gr.Markdown("# CivitAI to HF🤗 Downloader & Uploader", elem_classes="title")
|
| 12 |
+
with gr.Accordion("Search Civitai", open=True):
|
| 13 |
with gr.Row():
|
| 14 |
search_civitai_type = gr.CheckboxGroup(label="Type", choices=CIVITAI_TYPE, value=["Checkpoint", "LORA"])
|
| 15 |
search_civitai_basemodel = gr.CheckboxGroup(label="Base model", choices=CIVITAI_BASEMODEL, value=[])
|
|
|
|
| 23 |
with gr.Row():
|
| 24 |
search_civitai_json = gr.JSON(value={}, visible=False)
|
| 25 |
search_civitai_desc = gr.Markdown(value="", visible=False)
|
| 26 |
+
search_civitai_result = gr.Dropdown(label="Search Results", choices=[("", "")], value="", allow_custom_value=True, visible=False, multiselect=True)
|
| 27 |
search_civitai_add = gr.Button("Add to download URLs")
|
| 28 |
dl_url = gr.Textbox(label="Download URL(s)", placeholder="https://civitai.com/api/download/models/28907\n...", value="", lines=2, max_lines=255)
|
| 29 |
civitai_key = gr.Textbox(label="Your Civitai Key", value="", max_lines=1)
|
civitai_to_hf.py
CHANGED
|
@@ -6,7 +6,7 @@ import gc
|
|
| 6 |
import requests
|
| 7 |
from requests.adapters import HTTPAdapter
|
| 8 |
from urllib3.util import Retry
|
| 9 |
-
from utils import get_token, set_token, is_repo_exists, get_user_agent, get_download_file
|
| 10 |
import re
|
| 11 |
|
| 12 |
|
|
@@ -19,6 +19,14 @@ def parse_urls(s):
|
|
| 19 |
return []
|
| 20 |
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
def upload_safetensors_to_repo(filename, repo_id, repo_type, is_private, progress=gr.Progress(track_tqdm=True)):
|
| 23 |
output_filename = Path(filename).name
|
| 24 |
hf_token = get_token()
|
|
@@ -135,14 +143,18 @@ def search_civitai(query, types, base_model=[], sort=CIVITAI_SORT[0], period=CIV
|
|
| 135 |
gr.update(visible=True), gr.update(visible=True)
|
| 136 |
|
| 137 |
|
| 138 |
-
def select_civitai_item(
|
| 139 |
-
if
|
| 140 |
-
result = civitai_last_results.get(
|
| 141 |
md = result['md'] if result else ""
|
| 142 |
return gr.update(value=md, visible=True)
|
| 143 |
|
| 144 |
|
| 145 |
-
def add_civitai_item(
|
| 146 |
-
if
|
| 147 |
-
new_url =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
return gr.update(value=new_url)
|
|
|
|
| 6 |
import requests
|
| 7 |
from requests.adapters import HTTPAdapter
|
| 8 |
from urllib3.util import Retry
|
| 9 |
+
from utils import get_token, set_token, is_repo_exists, get_user_agent, get_download_file, list_uniq
|
| 10 |
import re
|
| 11 |
|
| 12 |
|
|
|
|
| 19 |
return []
|
| 20 |
|
| 21 |
|
| 22 |
+
def to_urls(l: list[str]):
|
| 23 |
+
return "\n".join(l)
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def uniq_urls(s):
|
| 27 |
+
return to_urls(list_uniq(parse_urls(s)))
|
| 28 |
+
|
| 29 |
+
|
| 30 |
def upload_safetensors_to_repo(filename, repo_id, repo_type, is_private, progress=gr.Progress(track_tqdm=True)):
|
| 31 |
output_filename = Path(filename).name
|
| 32 |
hf_token = get_token()
|
|
|
|
| 143 |
gr.update(visible=True), gr.update(visible=True)
|
| 144 |
|
| 145 |
|
| 146 |
+
def select_civitai_item(results: list[str]):
|
| 147 |
+
if "http" not in "".join(results): return gr.update(value="None", visible=True)
|
| 148 |
+
result = civitai_last_results.get(results[-1], "None")
|
| 149 |
md = result['md'] if result else ""
|
| 150 |
return gr.update(value=md, visible=True)
|
| 151 |
|
| 152 |
|
| 153 |
+
def add_civitai_item(results: list[str], dl_url: str):
|
| 154 |
+
if "http" not in "".join(results): return gr.update(value=dl_url)
|
| 155 |
+
new_url = dl_url if dl_url else ""
|
| 156 |
+
for result in results:
|
| 157 |
+
if "http" not in result: continue
|
| 158 |
+
new_url += f"\n{result}" if new_url else f"{result}"
|
| 159 |
+
new_url = uniq_urls(new_url)
|
| 160 |
return gr.update(value=new_url)
|
utils.py
CHANGED
|
@@ -63,6 +63,10 @@ def get_model_type(repo_id: str):
|
|
| 63 |
return default
|
| 64 |
|
| 65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
def list_sub(a, b):
|
| 67 |
return [e for e in a if e not in b]
|
| 68 |
|
|
|
|
| 63 |
return default
|
| 64 |
|
| 65 |
|
| 66 |
+
def list_uniq(l):
|
| 67 |
+
return sorted(set(l), key=l.index)
|
| 68 |
+
|
| 69 |
+
|
| 70 |
def list_sub(a, b):
|
| 71 |
return [e for e in a if e not in b]
|
| 72 |
|