Use api token for listing hidden models.
#2
by
Symbiomatrix
- opened
app.py
CHANGED
@@ -43,8 +43,10 @@ def download_file(url, file_path, folder, api_key=None):
|
|
43 |
raise gr.Error(f"Error downloading file: {str(e)}")
|
44 |
|
45 |
|
46 |
-
def get_files_by_username(username):
|
47 |
url = f"https://civitai.com/api/v1/models?username={username}&limit=100&nsfw=true"
|
|
|
|
|
48 |
output = {}
|
49 |
|
50 |
while url:
|
@@ -69,6 +71,8 @@ def get_files_by_username(username):
|
|
69 |
|
70 |
def get_files_by_model_id(model_id):
|
71 |
api_url = f"https://civitai.com/api/v1/models/{model_id}"
|
|
|
|
|
72 |
try:
|
73 |
response = requests.get(api_url)
|
74 |
response.raise_for_status()
|
@@ -93,10 +97,10 @@ def get_files_by_model_id(model_id):
|
|
93 |
def process_url(url, profile, user_repo_id, oauth_token, folder, api_key=None):
|
94 |
if url.startswith("https://civitai.com/models/"):
|
95 |
model_id = url.split('/')[4]
|
96 |
-
files = get_files_by_model_id(model_id)
|
97 |
elif url.startswith("https://civitai.com/user/"):
|
98 |
username = url.split('/')[4]
|
99 |
-
files = get_files_by_username(username)
|
100 |
else:
|
101 |
raise gr.Error("Unknown CivitAI URL format, please provide model URL or user profile URL")
|
102 |
|
|
|
43 |
raise gr.Error(f"Error downloading file: {str(e)}")
|
44 |
|
45 |
|
46 |
+
def get_files_by_username(username, api_key = None):
|
47 |
url = f"https://civitai.com/api/v1/models?username={username}&limit=100&nsfw=true"
|
48 |
+
if api_key: # Shows hidden models.
|
49 |
+
url += f"&token={api_key}"
|
50 |
output = {}
|
51 |
|
52 |
while url:
|
|
|
71 |
|
72 |
def get_files_by_model_id(model_id):
|
73 |
api_url = f"https://civitai.com/api/v1/models/{model_id}"
|
74 |
+
if api_key: # Shows hidden models.
|
75 |
+
api_url += f"&token={api_key}"
|
76 |
try:
|
77 |
response = requests.get(api_url)
|
78 |
response.raise_for_status()
|
|
|
97 |
def process_url(url, profile, user_repo_id, oauth_token, folder, api_key=None):
|
98 |
if url.startswith("https://civitai.com/models/"):
|
99 |
model_id = url.split('/')[4]
|
100 |
+
files = get_files_by_model_id(model_id, api_key)
|
101 |
elif url.startswith("https://civitai.com/user/"):
|
102 |
username = url.split('/')[4]
|
103 |
+
files = get_files_by_username(username, api_key)
|
104 |
else:
|
105 |
raise gr.Error("Unknown CivitAI URL format, please provide model URL or user profile URL")
|
106 |
|