Spaces:
Sleeping
Sleeping
File size: 3,331 Bytes
3c20eb9 322a977 5a07619 ac8553a b2d5214 b43a77a 2be8239 e9a5f22 5e9b025 46b7295 f47d997 4bac749 f47d997 b43a77a 61374ed 0776ccc f47d997 a2485e3 46b7295 225d9e9 6adfb24 46b7295 a2485e3 c27d682 5e9b025 b43a77a 322a977 d58ac29 f47d997 46b7295 322a977 00e554d 07bb252 00e554d 5d0c146 ae19ada 453b5a2 07bb252 e6566d7 50f55e5 453b5a2 07bb252 e6566d7 50f55e5 453b5a2 07bb252 e6566d7 50f55e5 453b5a2 07bb252 e6566d7 50f55e5 453b5a2 07bb252 e6566d7 50f55e5 07bb252 50f55e5 07bb252 50f55e5 07bb252 b801897 07bb252 5d0c146 73bd618 f208894 5d0c146 93e1bf4 ef8285d e9a5f22 b2d5214 2be8239 ef8285d f47d997 ef8285d b2d5214 ef8285d |
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 |
import gradio as gr
import json
from huggingface_hub import HfApi, ModelFilter, list_models
api = HfApi()
def model_explorer(search,task,limit=100):
# List all models
if limit==0:
limit=None
if not search:
search=None
out_box=[]
out_box1=[]
name_box=[]
if task:
filt = ModelFilter(task=task)
this = api.list_models(search=search,limit=limit,filter=filt,cardData=True)
else:
this = api.list_models(search=search,limit=limit,cardData=True)
cnt=0
for i,mod in enumerate(this):
print(mod.__dict__)
print(dir(mod))
cnt+=1
#if mod.gated=='manual':
out_box.append(mod)
loaded=mod.__dict__
loaded['DOWNLOAD_LINK']=f'https://huggingface.co/models/{mod.id}'
out_box1.append(loaded)
name_box.append(mod.id)
'''
print(dir(mod))
print(mod.id)
print(mod.downloads)
print(mod.likes)
print(mod.pipeline_tag)
out = mod.id
'''
print(cnt)
return out_box1,name_box
def tasks_json():
with open("tasks.json", "r") as read_file:
print("Read JSON file")
tasks = json.load(read_file)
print("Before Pretty Printing JSON Data")
print(tasks)
def fix_json():
new_json=[]
with open("tasks.json", "r") as fix_file:
for i, line in enumerate(fix_file.readlines()):
#print (line)
if "name:" in line:
out = line.replace("name:",'"name":')
new_json.append(out)
print (out)
elif "modality:" in line:
out = line.replace("modality:",'"modality":')
new_json.append(out)
print (out)
elif "type:" in line:
out = line.replace("type:",'"type":')
new_json.append(out)
print (out)
elif "subtasks:" in line:
out = line.replace("subtasks:",'"subtasks":')
new_json.append(out)
print (out)
elif "color:" in line:
out = line.replace("color:",'"color":')
new_json.append(out)
print (out)
elif "hideInModels:" in line:
out = line.replace("hideInModels:",'"hideInModels":')
new_json.append(out)
print (out)
elif "hideInDatasets:" in line:
out = line.replace("hideInDatasets:",'"hideInDatasets":')
new_json.append(out)
print (out)
else:
new_json.append(line)
print(line)
#print (json.dumps(new_json))
#new_out=new_json.decode("utf-8")
for i,line in enumerate(new_json):
try:
line.decode("utf-8")
except Exception:
pass
if line.strip():
print (line)
with gr.Blocks() as app:
with gr.Row():
search=gr.Textbox(label="query")
task=gr.Textbox(label="task")
limit=gr.Slider(minimum=0,maximum=10000,value=100)
btn=gr.Button()
names_json=gr.JSON()
models_json=gr.JSON()
btn.click(model_explorer,[search,task,limit],[models_json,names_json])
app.launch() |