Commit
·
7c3ba6d
1
Parent(s):
c199e36
Add civitai-to-hf-uploader
Browse files
app.py
CHANGED
@@ -10,7 +10,6 @@ from typing import Optional
|
|
10 |
import json
|
11 |
def download_file(url, file_path, folder):
|
12 |
headers = {}
|
13 |
-
gr.Info("Downloading file from "+ url + " to "+ file_path)
|
14 |
try:
|
15 |
response = requests.get(url, headers=headers)
|
16 |
response.raise_for_status()
|
@@ -32,8 +31,7 @@ def download_file(url, file_path, folder):
|
|
32 |
|
33 |
with open(os.path.join(folder, file_path), 'wb') as f:
|
34 |
f.write(response.content)
|
35 |
-
|
36 |
-
gr.Info("Downloaded "+ file_path)
|
37 |
|
38 |
def get_files_by_username(username):
|
39 |
url = f"https://civitai.com/api/v1/models?username={username}&limit=100"
|
@@ -82,10 +80,15 @@ def process_url(url, profile, do_download=True, folder="."):
|
|
82 |
|
83 |
if do_download:
|
84 |
downloaded_files = {}
|
|
|
|
|
85 |
for dl_path, download_url in files.items():
|
86 |
try:
|
|
|
|
|
87 |
download_file(download_url, dl_path, folder)
|
88 |
downloaded_files[dl_path] = download_url
|
|
|
89 |
except Exception as e:
|
90 |
gr.Warning(f"Failed to download {dl_path}: {str(e)}")
|
91 |
return downloaded_files
|
@@ -129,6 +132,8 @@ def upload_civit_to_hf(profile: Optional[gr.OAuthProfile], oauth_token: gr.OAuth
|
|
129 |
files = process_url(url, profile, folder=folder)
|
130 |
if not files or len(files.keys()) == 0:
|
131 |
return gr.Error("No files were downloaded. Please check the URL and try again.")
|
|
|
|
|
132 |
|
133 |
results = []
|
134 |
|
@@ -142,6 +147,7 @@ def upload_civit_to_hf(profile: Optional[gr.OAuthProfile], oauth_token: gr.OAuth
|
|
142 |
gr.Info(f"Repository {user_repo_id} already exists, will update it:"+ str(e))
|
143 |
|
144 |
gr.Info(f"Uploading models to {user_repo_id}...")
|
|
|
145 |
|
146 |
# Upload the model and card
|
147 |
upload_folder(
|
|
|
10 |
import json
|
11 |
def download_file(url, file_path, folder):
|
12 |
headers = {}
|
|
|
13 |
try:
|
14 |
response = requests.get(url, headers=headers)
|
15 |
response.raise_for_status()
|
|
|
31 |
|
32 |
with open(os.path.join(folder, file_path), 'wb') as f:
|
33 |
f.write(response.content)
|
34 |
+
|
|
|
35 |
|
36 |
def get_files_by_username(username):
|
37 |
url = f"https://civitai.com/api/v1/models?username={username}&limit=100"
|
|
|
80 |
|
81 |
if do_download:
|
82 |
downloaded_files = {}
|
83 |
+
total_files = len(files)
|
84 |
+
current_file = 1
|
85 |
for dl_path, download_url in files.items():
|
86 |
try:
|
87 |
+
filename = dl_path.split('/')[-1]
|
88 |
+
gr.Info(f"Downloading {filename} ({current_file}/{total_files})")
|
89 |
download_file(download_url, dl_path, folder)
|
90 |
downloaded_files[dl_path] = download_url
|
91 |
+
current_file += 1
|
92 |
except Exception as e:
|
93 |
gr.Warning(f"Failed to download {dl_path}: {str(e)}")
|
94 |
return downloaded_files
|
|
|
132 |
files = process_url(url, profile, folder=folder)
|
133 |
if not files or len(files.keys()) == 0:
|
134 |
return gr.Error("No files were downloaded. Please check the URL and try again.")
|
135 |
+
|
136 |
+
gr.Info(f"Downloaded {len(files)} files")
|
137 |
|
138 |
results = []
|
139 |
|
|
|
147 |
gr.Info(f"Repository {user_repo_id} already exists, will update it:"+ str(e))
|
148 |
|
149 |
gr.Info(f"Uploading models to {user_repo_id}...")
|
150 |
+
gr.Info(f"This may take a while, please don't close the page")
|
151 |
|
152 |
# Upload the model and card
|
153 |
upload_folder(
|