Symbiomatrix commited on
Commit
47bbbbd
·
verified ·
1 Parent(s): c0f70b8

TEST - Fixed list of version ids.

Browse files
Files changed (1) hide show
  1. app.py +28 -23
app.py CHANGED
@@ -43,30 +43,35 @@ 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, 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:
53
- response = requests.get(url, timeout=30)
54
- data = response.json()
55
- # Add current page items to the list
56
- for model in data['items']:
57
- for version in model['modelVersions']:
58
- for file in version['files']:
59
- output[str(model['id']) + '/' + str(version['id']) + '/' + file['name']] = {
60
- 'downloadUrl': file['downloadUrl'],
61
- 'modelId': model['name'] + ' - ' + version['name'],
62
- 'modelUrl': f"https://civitai.com/models/{model['id']}?modelVersionId={version['id']}",
63
- 'author': model['creator']['username'],
64
- 'authorUrl': f"https://civitai.com/user/{model['creator']['username']}",
65
- 'mirrorUrl': f"https://civitaiarchive.com/models/{model['id']}?modelVersionId={version['id']}",
66
- }
67
-
68
- metadata = data.get('metadata', {})
69
- url = metadata.get('nextPage', None)
 
 
 
 
 
70
  return output
71
 
72
  def get_files_by_model_id(model_id):
 
43
  raise gr.Error(f"Error downloading file: {str(e)}")
44
 
45
 
46
+ def get_files_by_username(username="loradude"):
47
+ # Fixed list of model IDs to check
48
+ LIST1 = [106794, 123456, 789012] # Add/remove model IDs as needed
49
+
50
  output = {}
51
+
52
+ for model_id in LIST1:
53
+ # Get model version data directly
54
+ version_url = f"https://civitai.com/api/v1/model-versions/{model_id}"
55
+ try:
56
+ response = requests.get(version_url, timeout=30)
57
+ response.raise_for_status()
58
+ version_data = response.json()
59
+
60
+ # Process files (same structure as before)
61
+ for file in version_data['files']:
62
+ output[f"{version_data["modelId"]}/{version_data["id"]}/{file["name"]}"] = {
63
+ 'downloadUrl': file['downloadUrl'],
64
+ 'modelId': version_data["model"]["name"] + ' - ' + version_data["name"],
65
+ 'modelUrl': f"https://civitai.com/models/{version_data["modelId"]}?modelVersionId={version_data['id']}",
66
+ 'author': username, # Hardcoded username
67
+ 'authorUrl': f"https://civitai.com/user/{username}",
68
+ 'mirrorUrl': f"https://civitaiarchive.com/models/{version_data["modelId"]}?modelVersionId={version_data['id']}",
69
+ }
70
+
71
+ except Exception as e:
72
+ print(f"Failed to process model {model_id}: {str(e)}")
73
+ continue
74
+
75
  return output
76
 
77
  def get_files_by_model_id(model_id):