patrickvonplaten
commited on
Commit
•
c9b0b96
1
Parent(s):
a38f44b
[LCM] Better error message
Browse files- civitai_stats.json +50 -0
- get_nfsw_civitai.py +116 -0
civitai_stats.json
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"total_models": 100,
|
3 |
+
"allow_commercial_use": {
|
4 |
+
"None": 23,
|
5 |
+
"Rent": 34,
|
6 |
+
"Image": 9,
|
7 |
+
"Sell": 12,
|
8 |
+
"RentCivit": 22
|
9 |
+
},
|
10 |
+
"nsfw_count": {
|
11 |
+
"sum": 18,
|
12 |
+
"avg": 0.18
|
13 |
+
},
|
14 |
+
"allow_derivatives": {
|
15 |
+
"sum": 90,
|
16 |
+
"avg": 0.9
|
17 |
+
},
|
18 |
+
"allow_no_credit": {
|
19 |
+
"sum": 68,
|
20 |
+
"avg": 0.68
|
21 |
+
},
|
22 |
+
"download_count": {
|
23 |
+
"sum": 12042078,
|
24 |
+
"avg": 120420.78
|
25 |
+
},
|
26 |
+
"favorite_count": {
|
27 |
+
"sum": 1177711,
|
28 |
+
"avg": 11777.11
|
29 |
+
},
|
30 |
+
"comment_count": {
|
31 |
+
"sum": 16084,
|
32 |
+
"avg": 160.84
|
33 |
+
},
|
34 |
+
"rating_count": {
|
35 |
+
"sum": 54496,
|
36 |
+
"avg": 544.96
|
37 |
+
},
|
38 |
+
"tipped_amount_count": {
|
39 |
+
"sum": 208051,
|
40 |
+
"avg": 2080.51
|
41 |
+
},
|
42 |
+
"ratings": 4.938500000000001,
|
43 |
+
"num_creators": 76,
|
44 |
+
"total_models_per_creator": 1.32,
|
45 |
+
"download_count_per_creator": 158448.39,
|
46 |
+
"comment_count_per_creator": 211.63,
|
47 |
+
"rating_count_per_creator": 717.05,
|
48 |
+
"tipped_amount_count_per_creator": 2737.51,
|
49 |
+
"favorite_count_per_creator": 15496.2
|
50 |
+
}
|
get_nfsw_civitai.py
ADDED
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
import requests
|
3 |
+
import json
|
4 |
+
from collections import Counter
|
5 |
+
|
6 |
+
def get_model_counts():
|
7 |
+
# Base URL of the API endpoint
|
8 |
+
url = "https://civitai.com/api/v1/models"
|
9 |
+
|
10 |
+
# Parameters for the API request
|
11 |
+
params = {
|
12 |
+
'limit': 100, # Set a high limit to reduce the number of pages to iterate through
|
13 |
+
'page': 1 # Start from the first page
|
14 |
+
}
|
15 |
+
|
16 |
+
# Initialize counts
|
17 |
+
total_models = 0
|
18 |
+
|
19 |
+
# counter
|
20 |
+
allow_commercial_use = []
|
21 |
+
creator = []
|
22 |
+
|
23 |
+
# sum
|
24 |
+
nsfw_count = []
|
25 |
+
allow_derivatives = []
|
26 |
+
allow_no_credit = []
|
27 |
+
download_count = []
|
28 |
+
favorite_count = []
|
29 |
+
comment_count = []
|
30 |
+
rating_count = []
|
31 |
+
tipped_amount_count = []
|
32 |
+
ratings = []
|
33 |
+
failures = 0
|
34 |
+
total_pages = 1000 # set to very high value, just in case it fails a lot in the beginning
|
35 |
+
|
36 |
+
while True:
|
37 |
+
# Make the GET request
|
38 |
+
try:
|
39 |
+
response = requests.get(url, params=params)
|
40 |
+
response.raise_for_status() # This will raise an error if the request fails
|
41 |
+
data = response.json()
|
42 |
+
|
43 |
+
# Process the current page of results
|
44 |
+
models = data["items"]
|
45 |
+
total_models += len(models)
|
46 |
+
|
47 |
+
for model in models:
|
48 |
+
allow_commercial_use.append(model["allowCommercialUse"])
|
49 |
+
creator.append(model["creator"]["username"])
|
50 |
+
nsfw_count.append(model["nsfw"])
|
51 |
+
allow_derivatives.append(model["allowDerivatives"])
|
52 |
+
allow_no_credit.append(model["allowNoCredit"])
|
53 |
+
download_count.append(model["stats"]["downloadCount"])
|
54 |
+
favorite_count.append(model["stats"]["favoriteCount"])
|
55 |
+
comment_count.append(model["stats"]["commentCount"])
|
56 |
+
rating_count.append(model["stats"]["ratingCount"])
|
57 |
+
tipped_amount_count.append(model["stats"]["tippedAmountCount"])
|
58 |
+
ratings.append(model["stats"]["rating"])
|
59 |
+
|
60 |
+
# Check if there are more pages to process
|
61 |
+
total_pages = int(data.get('metadata', {}).get('totalPages', 0))
|
62 |
+
# if params['page'] >= total_pages:
|
63 |
+
if params['page'] >= 2:
|
64 |
+
break
|
65 |
+
|
66 |
+
# Increment the page number for the next request
|
67 |
+
params['page'] += 1
|
68 |
+
|
69 |
+
print(f"{params['page']} / {total_pages}")
|
70 |
+
except:
|
71 |
+
failures += 1
|
72 |
+
params["page"] += 1
|
73 |
+
|
74 |
+
return {
|
75 |
+
'total_models': total_models,
|
76 |
+
'allow_commercial_use': allow_commercial_use,
|
77 |
+
'creator': creator,
|
78 |
+
'nsfw_count': nsfw_count,
|
79 |
+
'allow_derivatives': allow_derivatives,
|
80 |
+
'allow_no_credit': allow_no_credit,
|
81 |
+
'download_count': download_count,
|
82 |
+
'favorite_count': favorite_count,
|
83 |
+
'comment_count': comment_count,
|
84 |
+
'rating_count': rating_count,
|
85 |
+
'tipped_amount_count': tipped_amount_count,
|
86 |
+
'ratings': ratings,
|
87 |
+
'failures': failures,
|
88 |
+
}
|
89 |
+
|
90 |
+
outputs = get_model_counts()
|
91 |
+
|
92 |
+
def map_fn(k, v):
|
93 |
+
if k in ["total_models", 'failures']:
|
94 |
+
return v
|
95 |
+
elif k in ["creator", "allow_commercial_use"]:
|
96 |
+
return Counter(v)
|
97 |
+
elif k in ["ratings"]:
|
98 |
+
return sum(v) / len(v)
|
99 |
+
else:
|
100 |
+
return {
|
101 |
+
"sum": sum(v),
|
102 |
+
"avg": round(sum(v) / len(v), 3)
|
103 |
+
}
|
104 |
+
|
105 |
+
stats = {k: map_fn(k, v) for k,v in outputs.items()}
|
106 |
+
stats["num_creators"] = len(stats.pop("creator"))
|
107 |
+
|
108 |
+
for k in ["total_models", "download_count", "comment_count", "rating_count", "tipped_amount_count", "favorite_count"]:
|
109 |
+
if isinstance(stats[k], dict):
|
110 |
+
stats[f"{k}_per_creator"] = round(stats[k]["sum"] / stats["num_creators"], 2)
|
111 |
+
else:
|
112 |
+
stats[f"{k}_per_creator"] = round(stats[k] / stats["num_creators"], 2)
|
113 |
+
|
114 |
+
filename = "civitai_stats.json"
|
115 |
+
with open(filename, 'w') as file:
|
116 |
+
json.dump(stats, file, indent=4)
|