model-explorer / app.py
Omnibus's picture
Update app.py
dded06b verified
raw
history blame
2.82 kB
import gradio as gr
import json
from huggingface_hub import HfApi, ModelFilter, list_models
api = HfApi()
def model_explorer(search,limit=100,task='text-generation'):
# List all models
if not search:
search=None
out_box=[]
filt = ModelFilter(task="text-generation")
this = api.list_models(search=search,limit=limit,filter=filt,cardData=True)
for i,mod in enumerate(this):
if mod.gated=='manual':
out_box.append(mod)
'''
print(dir(mod))
print(mod.id)
print(mod.downloads)
print(mod.likes)
print(mod.pipeline_tag)
out = mod.id
'''
return out_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()
limit=gr.Slider(minimum=1,maximum=10000,value=100)
btn=gr.Button()
models_json=gr.JSON()
btn.click(model_explorer,[search,limit],models_json)
app.launch()