Weyaxi commited on
Commit
9329646
β€’
1 Parent(s): 1bffea7

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +140 -0
app.py ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from huggingface_hub import HfApi, HfFileSystem
2
+ import re
3
+ from tqdm import tqdm
4
+ import concurrent.futures
5
+ import gradio as gr
6
+ import datetime
7
+ import pandas as pd
8
+
9
+ api = HfApi()
10
+ fs = HfFileSystem()
11
+
12
+
13
+ text = f"""
14
+ 🎯 The Leaderboard aims to track TheBloke's quantisied models.
15
+
16
+ ## πŸ“š Type Of Models
17
+
18
+ - GPTQ
19
+
20
+ - GGUF
21
+
22
+ - AWQ
23
+
24
+ - GGML
25
+
26
+ ## πŸ› οΈ Backend
27
+
28
+ The leaderboard's backend mainly runs on the [Hugging Face Hub API](https://huggingface.co/docs/huggingface_hub/v0.5.1/en/package_reference/hf_api).
29
+
30
+ ## πŸ” Searching
31
+
32
+ You can search for author or a spesific model using the search bar.
33
+
34
+ ## βŒ› Last Update
35
+
36
+ This space is last updated in **{str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M"))}**.
37
+
38
+ ## πŸ“’ Important Note
39
+
40
+ This space potentially includes incorrectly quantisied models for a model.
41
+
42
+ If you find any incorrectly quantisied model, please report it to me.
43
+ """
44
+
45
+ quant_models = [i.__dict__['id'] for i in api.list_models(author="TheBloke") if "GPTQ" in i.__dict__['id'] or "GGUF" in i.__dict__['id'] or "AWQ" in i.__dict__['id'] or "GGML" in i.__dict__['id']]
46
+
47
+
48
+ pattern = r'\(https://huggingface\.co/([^/]+)/([^/]+)\)'
49
+ liste = {}
50
+
51
+ def process_model(i, pattern, liste):
52
+ text = fs.read_text(i + "/README.md")
53
+ matches = re.search(pattern, text)
54
+
55
+ if matches:
56
+ author = matches.group(1)
57
+ model_name = matches.group(2)
58
+ full_id = (author + "/" + model_name).split(")")[0]
59
+
60
+ try:
61
+ liste[full_id].append(i)
62
+ except KeyError:
63
+ liste[full_id] = [i]
64
+
65
+
66
+ num_threads = 64
67
+
68
+ with concurrent.futures.ThreadPoolExecutor(max_workers=num_threads) as executor:
69
+ futures = []
70
+ for i in quant_models:
71
+ future = executor.submit(process_model, i, pattern, liste)
72
+ futures.append(future)
73
+
74
+ concurrent.futures.wait(futures)
75
+
76
+
77
+ authors, models, gptq, gguf, awq, ggml = [], [], [], [], [], []
78
+
79
+
80
+ for model, values in liste.items():
81
+ models.append(model)
82
+
83
+ gptq_value, gguf_value, awq_value, ggml_value = None, None, None, None
84
+
85
+ for value in values:
86
+ if "-GPTQ" in value:
87
+ gptq_value = value
88
+ elif "-GGUF" in value:
89
+ gguf_value = value
90
+ elif "-AWQ" in value:
91
+ awq_value = value
92
+ elif "-GGML" in value:
93
+ ggml_value = value
94
+
95
+ authors.append(model.split('/')[0])
96
+ gptq.append(gptq_value)
97
+ gguf.append(gguf_value)
98
+ awq.append(awq_value)
99
+ ggml.append(ggml_value)
100
+
101
+
102
+ df = pd.DataFrame({'πŸ‘€ Author Name': authors, 'πŸ€– Model Name': models, 'πŸ‘ GPTQ': gptq, 'πŸ“₯ GGUF': gguf, 'πŸ€·β€β™‚οΈ AWQ': awq, '😭 GGML': ggml})
103
+
104
+
105
+ def search(search_text):
106
+ if not search_text:
107
+ return df
108
+
109
+ if len(search_text.split('/'))>1:
110
+ return df[df['πŸ€– Model Name'] == clickable(search_text)]
111
+ else:
112
+ return df[df['πŸ‘€ Author Name'] == clickable(search_text)]
113
+
114
+
115
+ def clickable(x):
116
+ return None if not x else f'<a target="_blank" href="https://huggingface.co/{x}" style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">{x}</a>'
117
+
118
+
119
+ def to_clickable(df):
120
+ for column in list(df.columns):
121
+ df[column] = df[column].apply(lambda x: clickable(x))
122
+ return df
123
+
124
+
125
+ with gr.Blocks() as demo:
126
+ gr.Markdown("""<center><img src = "https://cdn-uploads.huggingface.co/production/uploads/6426d3f3a7723d62b53c259b/tvPikpAzKTKGN5wrpadOJ.jpeg" width=200 height=200></center>""")
127
+ gr.Markdown("""<h1 align="center" id="space-title">The Bloke Quantisied Models</h1>""")
128
+ gr.Markdown(text)
129
+
130
+ with gr.Column(min_width=320):
131
+ search_bar = gr.Textbox(placeholder="πŸ” Search for a author or a spesific model", show_label=False)
132
+
133
+
134
+ df_clickable = to_clickable(df)
135
+ gr_df = gr.Dataframe(df_clickable, interactive=False, datatype=["markdown"]*len(df.columns))
136
+
137
+ search_bar.submit(fn=search, inputs=search_bar, outputs=gr_df)
138
+
139
+
140
+ demo.launch()