Spaces:
Runtime error
Runtime error
Update all_models2.py
Browse files- all_models2.py +20 -21
all_models2.py
CHANGED
|
@@ -21,18 +21,15 @@ def find_model_list(author: str="", tags: list[str]=[], not_tag="", sort: str="l
|
|
| 21 |
print(f"Error: Failed to list models.")
|
| 22 |
print(e)
|
| 23 |
return models
|
| 24 |
-
t1=True
|
| 25 |
for model in model_infos:
|
| 26 |
|
| 27 |
if not model.private and not model.gated:
|
| 28 |
-
if t1:
|
| 29 |
-
print(model)
|
| 30 |
-
t1=False
|
| 31 |
loadable = True
|
| 32 |
if not_tag and not_tag in model.tags or not loadable: continue
|
| 33 |
if model.id not in bad_models :
|
| 34 |
models.append(model.id)
|
| 35 |
-
models_plus_tags.append([model.id,process_tags(model.tags)])
|
|
|
|
| 36 |
if len(models) == limit: break
|
| 37 |
return models , models_plus_tags
|
| 38 |
|
|
@@ -49,26 +46,27 @@ def process_tags(tags,bad_tags=bad_tags):
|
|
| 49 |
|
| 50 |
def clas_tags(models_plus_tags,min):
|
| 51 |
tags_plus_models=[]
|
| 52 |
-
|
|
|
|
| 53 |
new_tag=True
|
| 54 |
for ent in models_plus_tags:
|
|
|
|
|
|
|
| 55 |
for tagClas in ent[1]:
|
| 56 |
new_tag=True
|
| 57 |
-
for tag in
|
| 58 |
if tag[0] == tagClas:
|
| 59 |
tag[1]+=1
|
| 60 |
tag[2].append(ent[0])
|
| 61 |
new_tag=False
|
| 62 |
if new_tag:
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
output.append(t)
|
| 71 |
-
return output
|
| 72 |
def orga_tag(tags_plus_models):
|
| 73 |
output=[]
|
| 74 |
while(len(output)<len(tags_plus_models)):
|
|
@@ -89,7 +87,7 @@ def tag_new(models,limit=40):
|
|
| 89 |
output[2].append(models[i])
|
| 90 |
return output
|
| 91 |
|
| 92 |
-
def tag_fav(models,fav_models):
|
| 93 |
output=["FAV",0,[]]
|
| 94 |
for m in fav_models:
|
| 95 |
if m in models:
|
|
@@ -107,14 +105,15 @@ def update_tag(models_plus_tags,list_new_tag):
|
|
| 107 |
|
| 108 |
from operator import itemgetter
|
| 109 |
|
|
|
|
| 110 |
#models = find_model_list("Yntec", [], "", "last_modified", 20)
|
| 111 |
-
models , models_plus_tags = find_model_list("John6666", ["stable-diffusion-xl"], "", "last_modified",
|
| 112 |
#tags_plus_models = orga_tag(clas_tags(models_plus_tags,2))
|
| 113 |
tags_plus_models = orga_tag(clas_tags(sorted(models_plus_tags, key=itemgetter(0)),2))
|
| 114 |
-
list_new=tag_new(models,
|
| 115 |
models_plus_tags=update_tag(models_plus_tags,list_new)
|
| 116 |
tags_plus_models.insert(1,list_new)
|
| 117 |
-
list_fav=tag_fav(models
|
| 118 |
if list_fav[1]>0:
|
| 119 |
tags_plus_models.insert(1,list_fav)
|
| 120 |
models_plus_tags=update_tag(models_plus_tags,list_fav)
|
|
@@ -129,4 +128,4 @@ if list_fav[1]>0:
|
|
| 129 |
#models = find_model_list("Yntec", ["anime"], "", "last_modified", 20) # Yntec's latest 20 models with 'anime' tag
|
| 130 |
#models = find_model_list("Yntec", [], "anime", "last_modified", 20) # Yntec's latest 20 models without 'anime' tag
|
| 131 |
#models = find_model_list("", [], "", "last_modified", 20) # latest 20 text-to-image models of huggingface
|
| 132 |
-
#models = find_model_list("", [], "", "downloads", 20) # monthly most downloaded 20 text-to-image models of huggingface
|
|
|
|
| 21 |
print(f"Error: Failed to list models.")
|
| 22 |
print(e)
|
| 23 |
return models
|
|
|
|
| 24 |
for model in model_infos:
|
| 25 |
|
| 26 |
if not model.private and not model.gated:
|
|
|
|
|
|
|
|
|
|
| 27 |
loadable = True
|
| 28 |
if not_tag and not_tag in model.tags or not loadable: continue
|
| 29 |
if model.id not in bad_models :
|
| 30 |
models.append(model.id)
|
| 31 |
+
#models_plus_tags.append([model.id,process_tags(model.tags)])
|
| 32 |
+
models_plus_tags.append([model.id,process_tags(model.cardData.tags)])
|
| 33 |
if len(models) == limit: break
|
| 34 |
return models , models_plus_tags
|
| 35 |
|
|
|
|
| 46 |
|
| 47 |
def clas_tags(models_plus_tags,min):
|
| 48 |
tags_plus_models=[]
|
| 49 |
+
listTemp=[]
|
| 50 |
+
listAllModels=['all',0,[]]
|
| 51 |
new_tag=True
|
| 52 |
for ent in models_plus_tags:
|
| 53 |
+
listAllModels[1]+=1
|
| 54 |
+
listAllModels[2].append(ent[0])
|
| 55 |
for tagClas in ent[1]:
|
| 56 |
new_tag=True
|
| 57 |
+
for tag in listTemp:
|
| 58 |
if tag[0] == tagClas:
|
| 59 |
tag[1]+=1
|
| 60 |
tag[2].append(ent[0])
|
| 61 |
new_tag=False
|
| 62 |
if new_tag:
|
| 63 |
+
listTemp.append([tagClas,1,[ent[0]]])
|
| 64 |
+
tags_plus_models.append(listAllModels)
|
| 65 |
+
for t in listTemp:
|
| 66 |
+
if t[1]>=min and t[1]!=len(models_plus_tags):
|
| 67 |
+
tags_plus_models.append(t)
|
| 68 |
+
return tags_plus_models
|
| 69 |
+
|
|
|
|
|
|
|
| 70 |
def orga_tag(tags_plus_models):
|
| 71 |
output=[]
|
| 72 |
while(len(output)<len(tags_plus_models)):
|
|
|
|
| 87 |
output[2].append(models[i])
|
| 88 |
return output
|
| 89 |
|
| 90 |
+
def tag_fav(models=models,fav_models=fav_models):
|
| 91 |
output=["FAV",0,[]]
|
| 92 |
for m in fav_models:
|
| 93 |
if m in models:
|
|
|
|
| 105 |
|
| 106 |
from operator import itemgetter
|
| 107 |
|
| 108 |
+
nb_models_to_load=10000
|
| 109 |
#models = find_model_list("Yntec", [], "", "last_modified", 20)
|
| 110 |
+
models , models_plus_tags = find_model_list("John6666", ["stable-diffusion-xl"], "", "last_modified", nb_models_to_load)
|
| 111 |
#tags_plus_models = orga_tag(clas_tags(models_plus_tags,2))
|
| 112 |
tags_plus_models = orga_tag(clas_tags(sorted(models_plus_tags, key=itemgetter(0)),2))
|
| 113 |
+
list_new=tag_new(models,nb_models_to_load)
|
| 114 |
models_plus_tags=update_tag(models_plus_tags,list_new)
|
| 115 |
tags_plus_models.insert(1,list_new)
|
| 116 |
+
list_fav=tag_fav(models)
|
| 117 |
if list_fav[1]>0:
|
| 118 |
tags_plus_models.insert(1,list_fav)
|
| 119 |
models_plus_tags=update_tag(models_plus_tags,list_fav)
|
|
|
|
| 128 |
#models = find_model_list("Yntec", ["anime"], "", "last_modified", 20) # Yntec's latest 20 models with 'anime' tag
|
| 129 |
#models = find_model_list("Yntec", [], "anime", "last_modified", 20) # Yntec's latest 20 models without 'anime' tag
|
| 130 |
#models = find_model_list("", [], "", "last_modified", 20) # latest 20 text-to-image models of huggingface
|
| 131 |
+
#models = find_model_list("", [], "", "downloads", 20) # monthly most downloaded 20 text-to-image models of huggingface
|