Repository navigation
Expand file tree
/
Copy patheval_public_loras.py
More file actions
84 lines (71 loc) · 3.27 KB
/
Copy patheval_public_loras.py
File metadata and controls
84 lines (71 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import requests
import os
import json
import argparse
from lora_eval import lora_eval
import time
def download_and_process(lora_list_url, a111_url, lora_strengths):
current_page=1
# Directory for storing downloaded files
download_dir = 'loras'
os.makedirs(download_dir, exist_ok=True)
while True:
print(f"Getting list for page {current_page}")
paginated_url = f"{lora_list_url}?page={current_page}&per_page=10"
response = requests.get(paginated_url)
# Fetching JSON data from the URL
print("Parsing list")
if response.status_code != 200:
print("Failed to fetch data from the URL. Retry")
print(response.status_code)
time.sleep(5)
continue
current_page += 1
data = response.json()
# Check if there are no sliders to process
if len(data['sliders']) == 0:
print(f"No more data to process. Ending at page {current_page}.")
break
# Process each slider
for slider in data['sliders']:
download_url = slider['download_url']
name = slider['name']
prompts = slider['data']['prompts'][0] # Assuming one prompt per slider
positive = prompts['positive']
target = prompts['target']
neutral = prompts['neutral']
unconditional = prompts['unconditional']
if 'negative' in prompts:
unconditional = prompts['negative']
file_name = f"{positive}.{target}.{neutral}.{unconditional}.safetensors"
file_name = file_name.replace("/",'-')
file_path = os.path.join(download_dir, file_name)
# Check if file already exists
if os.path.exists(file_path):
#print(f"File {file_path} already exists. Skipping download.")
pass
else:
print("FNAME", file_name)
# Download the file
response = requests.get(download_url, timeout=180)
if response.status_code == 200:
with open(file_path, 'wb') as file:
file.write(response.content)
print(f"Downloaded and saved {file_path}")
else:
print(f"Failed to download {file_name}")
continue
# Call the mock function
unique_tags = list(set([positive, target, neutral, unconditional]))
print("___________________", positive)
lora_eval(a111_url, file_name.replace(".safetensors", ""), [positive.replace("/","-")], lora_strengths)
print("Done parsing list")
def main():
parser = argparse.ArgumentParser(description='Generate images for evaluating a lora')
parser.add_argument('-s', '--lora_strength', nargs='*', required=True, help='lora strength, can be multiple: -2 0 2')
parser.add_argument('-url', '--text_to_image_url', type=str, default="http://localhost:3000/sdapi/v1/txt2img", help='Url for text to image')
parser.add_argument('-lora_url', '--lora_list_url', type=str, default="notpublic", help='Url to get lora list')
args = parser.parse_args()
download_and_process(args.lora_list_url, args.text_to_image_url, args.lora_strength)
if __name__ == '__main__':
main()