CoolFace
Apppublic

Omnibus/binary-mod

sourceHugging Faceupdated 3y agoView on Hugging Face
1likes
app.py67 linesDownload Raw Back to root
1import gradio as gr2import numpy3import torch4import requests5import io6from huggingface_hub import HfApi, ModelFilter, list_models, list_repo_files, hf_hub_download7api = HfApi()8 9models=[10    ""11]12def list_files(model_name):13    files = api.list_repo_files(repo_id=model_name,repo_type="model")14    return gr.update(choices=[m for m in files],interactive=True)    15 16def load_bin(model_name,file_name):17    r = requests.get(f'https://huggingface.co/{model_name}/resolve/main/{file_name}')18    #print(r.content)19    print("#######")20    print(dir(r))21    #torch.set_printoptions(profile="full")    22    #result=torch.frombuffer(r.content,dtype=torch.get_default_dtype(),offset=1)23    result=torch.frombuffer(r.content,dtype=torch.get_default_dtype(),offset=27)24    print(dir(result))25    return result26 27 28def load_models(model_in):29    loaded_model=[]30    model_details=[]31    32    if "/" in models:33        similar_models = api.list_models(search=model_in.split("/")[1],limit=100,cardData=True)34    else:35        similar_models = api.list_models(search=model_in,limit=100,cardData=True)36    for model in similar_models:37        try:38            model_load=gr.load(f'models/{model.id}')39            print(model_load)40            #out_test=model_load("hello?")41            loaded_model.append(model_load)42        except Exception as e:43            loaded_model.append({"MODEL":model.id,"ERROR":e})44        try:45            model_details.append(model)46        except Exception as ee:47            model_details.append({"MODEL":model.id,"ERROR":ee})48    return loaded_model, model_details49 50    51with gr.Blocks() as app:52    with gr.Row():53        model_name=gr.Textbox(label="Model", value=models[0], placeholder=models[0])54        load_btn=gr.Button("Load")55    with gr.Row():56        file_name=gr.Dropdown(label="Files", choices=[])57        bin_btn=gr.Button("Binary")58    binary=gr.JSON()59    with gr.Row():60        models_out=gr.JSON(label="Gradio Details")61        details=gr.JSON(label="Hub Details")62    app.load(list_files,model_name,[file_name])63    bin_btn.click(load_bin,[model_name,file_name],binary)64    #app.load(load_models,model_name,[models_out,details])65    load_btn.click(load_models,model_name,[models_out,details])66app.launch()67