File size: 2,244 Bytes
09d1825
105e5a5
 
eafb92c
b29cd11
09d1825
 
 
 
44dcca2
09d1825
68b46bf
 
9f98425
09d1825
b81704c
933af47
0563105
bf8a57c
 
dfcfd2a
2d13de9
9059d06
875cda7
105e5a5
b81704c
 
09d1825
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b81704c
 
09d1825
 
 
 
68b46bf
 
b81704c
7e9e2fa
09d1825
 
 
68b46bf
7e9e2fa
09d1825
 
 
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
import gradio as gr
import numpy
import torch
import requests
import io
from huggingface_hub import HfApi, ModelFilter, list_models, list_repo_files, hf_hub_download
api = HfApi()

models=[
    ""
]
def list_files(model_name):
    files = api.list_repo_files(repo_id=model_name,repo_type="model")
    return gr.update(choices=[m for m in files],interactive=True)    

def load_bin(model_name,file_name):
    r = requests.get(f'https://huggingface.co/{model_name}/resolve/main/{file_name}')
    #print(r.content)
    print("#######")
    print(dir(r))
    #torch.set_printoptions(profile="full")    
    #result=torch.frombuffer(r.content,dtype=torch.get_default_dtype(),offset=1)
    result=torch.frombuffer(r.content,dtype=torch.get_default_dtype(),offset=27)
    print(dir(result))
    return result


def load_models(model_in):
    loaded_model=[]
    model_details=[]
    
    if "/" in models:
        similar_models = api.list_models(search=model_in.split("/")[1],limit=100,cardData=True)
    else:
        similar_models = api.list_models(search=model_in,limit=100,cardData=True)
    for model in similar_models:
        try:
            model_load=gr.load(f'models/{model.id}')
            print(model_load)
            #out_test=model_load("hello?")
            loaded_model.append(model_load)
        except Exception as e:
            loaded_model.append({"MODEL":model.id,"ERROR":e})
        try:
            model_details.append(model)
        except Exception as ee:
            model_details.append({"MODEL":model.id,"ERROR":ee})
    return loaded_model, model_details

    
with gr.Blocks() as app:
    with gr.Row():
        model_name=gr.Textbox(label="Model", value=models[0], placeholder=models[0])
        load_btn=gr.Button("Load")
    with gr.Row():
        file_name=gr.Dropdown(label="Files", choices=[])
        bin_btn=gr.Button("Binary")
    binary=gr.JSON()
    with gr.Row():
        models_out=gr.JSON(label="Gradio Details")
        details=gr.JSON(label="Hub Details")
    app.load(list_files,model_name,[file_name])
    bin_btn.click(load_bin,[model_name,file_name],binary)
    #app.load(load_models,model_name,[models_out,details])
    load_btn.click(load_models,model_name,[models_out,details])
app.launch()