Spaces:
Running
Running
File size: 4,672 Bytes
90618af 831aba6 90618af |
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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
from blacklist import bad_tags,bad_models,fav_models
models = []
models_plus_tags=[]
tags_plus_models=[]
def list_uniq(l):
return sorted(set(l), key=l.index)
def find_model_list(author: str="", tags: list[str]=[], not_tag="", sort: str="last_modified", limit: int=30, force_gpu=False, check_status=False, bad_models=bad_models):
from huggingface_hub import HfApi
api = HfApi()
default_tags = ["diffusers"]
if not sort: sort = "last_modified"
models = []
models_plus_tags=[]
try:
model_infos = api.list_models(author=author, task="text-to-image",
tags=list_uniq(default_tags + tags), cardData=True, sort=sort, limit=limit)
except Exception as e:
print(f"Error: Failed to list models.")
print(e)
return models
for model in model_infos:
if not model.private and not model.gated:
loadable = True
if not_tag and not_tag in model.tags or not loadable: continue
if model.id not in bad_models :
models.append(model.id)
models_plus_tags.append([model.id,process_tags(model.tags)])
if len(models) == limit: break
return models , models_plus_tags
def process_tags(tags,bad_tags=bad_tags):
t1=True
new_tags=[]
for tag in tags:
if tag not in bad_tags:
if tag == 'en':
t1=False
if t1 :
new_tags.append(tag)
return new_tags
def clas_tags(models_plus_tags,min):
tags_plus_models=[]
output=[]
new_tag=True
for ent in models_plus_tags:
for tagClas in ent[1]:
new_tag=True
for tag in tags_plus_models:
if tag[0] == tagClas:
tag[1]+=1
tag[2].append(ent[0])
new_tag=False
if new_tag:
tags_plus_models.append([tagClas,1,[ent[0]]])
for t in tags_plus_models:
if t[0]=='diffusers' :
t[0]='all'
output.append(t)
else :
if t[1]>=min and t[1]!=len(models_plus_tags):
output.append(t)
return output
def orga_tag(tags_plus_models):
output=[]
while(len(output)<len(tags_plus_models)):
max=0
for tag in tags_plus_models:
if tag[1]>max:
if tag not in output:
max=tag[1]
tagMax=tag
output.append(tagMax)
return output
def tag_new(models,limit=40):
output=["NEW",0,[]]
if limit>len(models):
limit=len(models)
for i in range(limit):
output[1]+=1
output[2].append(models[i])
return output
def tag_fav(models=models,fav_models=fav_models):
output=["FAV",0,[]]
for m in fav_models:
if m in models:
output[1]+=1
output[2].append(m)
return output
def update_tag(models_plus_tags,list_new_tag):
for m_new in list_new_tag[2]:
for m in models_plus_tags:
if m_new == m[0]:
m[1].append(list_new_tag[0])
return models_plus_tags
from operator import itemgetter
#models = find_model_list("Yntec", [], "", "last_modified", 20)
models , models_plus_tags = find_model_list("John6666", ["stable-diffusion-xl"], "", "last_modified", 2000)
#tags_plus_models = orga_tag(clas_tags(models_plus_tags,2))
tags_plus_models = orga_tag(clas_tags(sorted(models_plus_tags, key=itemgetter(0)),2))
list_new=tag_new(models,40)
models_plus_tags=update_tag(models_plus_tags,list_new)
tags_plus_models.insert(1,list_new)
list_fav=tag_fav()
if list_fav[1]>0:
tags_plus_models.insert(1,list_fav)
models_plus_tags=update_tag(models_plus_tags,list_fav)
print(models_plus_tags[0])
#models.extend(find_model_list("John6666", ["stable-diffusion-xl"], "", "last_modified", 200))
#models.extend(find_model_list("John6666", [], "", "last_modified", 20)) # The latest 20 models will be added to the models written above.
# Examples:
#models = ['yodayo-ai/kivotos-xl-2.0', 'yodayo-ai/holodayo-xl-2.1'] # specific models
#models = find_model_list("Yntec", [], "", "last_modified", 20) # Yntec's latest 20 models
#models = find_model_list("Yntec", ["anime"], "", "last_modified", 20) # Yntec's latest 20 models with 'anime' tag
#models = find_model_list("Yntec", [], "anime", "last_modified", 20) # Yntec's latest 20 models without 'anime' tag
#models = find_model_list("", [], "", "last_modified", 20) # latest 20 text-to-image models of huggingface
#models = find_model_list("", [], "", "downloads", 20) # monthly most downloaded 20 text-to-image models of huggingface
|