hanruijiang
commited on
Commit
•
63839d2
1
Parent(s):
286d298
upload scripts
Browse filesupload downloading script.
upload processing script.
- download_civitai.py +49 -0
- process_civitai.py +41 -0
download_civitai.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
import json
|
3 |
+
import time
|
4 |
+
from tqdm.auto import tqdm
|
5 |
+
|
6 |
+
proxies = {
|
7 |
+
'http': 'http://localhost:7890',
|
8 |
+
'https': 'http://localhost:7890'
|
9 |
+
}
|
10 |
+
|
11 |
+
headers = {'Content-Type': 'application/json'}
|
12 |
+
|
13 |
+
url = 'https://civitai.com/api/v1/images'
|
14 |
+
|
15 |
+
results = list()
|
16 |
+
|
17 |
+
tbar = tqdm()
|
18 |
+
|
19 |
+
wait_time = 2
|
20 |
+
flag = True
|
21 |
+
while flag:
|
22 |
+
|
23 |
+
try:
|
24 |
+
# data = requests.get(url, proxies=proxies)
|
25 |
+
data = requests.get(url)
|
26 |
+
data = json.loads(data.content)
|
27 |
+
url = data['metadata'].get('nextPage')
|
28 |
+
except KeyboardInterrupt:
|
29 |
+
break
|
30 |
+
except:
|
31 |
+
wait_time = min(60, wait_time * 2)
|
32 |
+
time.sleep(wait_time)
|
33 |
+
continue
|
34 |
+
|
35 |
+
if url == None: break
|
36 |
+
|
37 |
+
items = data['items']
|
38 |
+
# now do whatever you want with data
|
39 |
+
|
40 |
+
wait_time = 2
|
41 |
+
time.sleep(wait_time)
|
42 |
+
results.extend(items)
|
43 |
+
tbar.update()
|
44 |
+
|
45 |
+
with open('../dataset/scrap/civitai-2023-11-14.jsonl', 'wt') as f:
|
46 |
+
for i in tqdm(results):
|
47 |
+
f.write(json.dumps(i) + '\n')
|
48 |
+
|
49 |
+
|
process_civitai.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
from tqdm.auto import tqdm
|
3 |
+
|
4 |
+
items = list()
|
5 |
+
|
6 |
+
hashs = set()
|
7 |
+
|
8 |
+
with open('../dataset/scrap/civitai-2023-11-14.jsonl') as f:
|
9 |
+
for i, line in tqdm(enumerate(f)):
|
10 |
+
item = json.loads(line)
|
11 |
+
|
12 |
+
if item['hash'] in hashs:
|
13 |
+
continue
|
14 |
+
hashs.add(item['hash'])
|
15 |
+
|
16 |
+
if item['meta'] is None:
|
17 |
+
item['meta'] = {}
|
18 |
+
|
19 |
+
prompt = item['meta'].get('prompt')
|
20 |
+
item['prompt'] = '' if prompt is None else prompt
|
21 |
+
|
22 |
+
item['meta']['prompt'] = ''
|
23 |
+
del item['meta']['prompt']
|
24 |
+
|
25 |
+
negativePrompt = item['meta'].get('negativePrompt')
|
26 |
+
item['negativePrompt'] = '' if negativePrompt is None else negativePrompt
|
27 |
+
|
28 |
+
item['meta']['negativePrompt'] = ''
|
29 |
+
del item['meta']['negativePrompt']
|
30 |
+
|
31 |
+
items.append(item)
|
32 |
+
|
33 |
+
print(len(items))
|
34 |
+
|
35 |
+
items = sorted(items, key=lambda x: x['createdAt'])
|
36 |
+
|
37 |
+
with open('../dataset/scrap/civitai-2023-11-14-sorted.jsonl', 'wt') as f:
|
38 |
+
for i in tqdm(items):
|
39 |
+
f.write(json.dumps(i) + '\n')
|
40 |
+
|
41 |
+
|