Tanvir1337
commited on
Commit
β’
712be77
1
Parent(s):
ebe89a1
init app.py
Browse files
app.py
ADDED
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
import os
|
9 |
+
import threading
|
10 |
+
import time
|
11 |
+
|
12 |
+
HF_TOKEN = os.getenv('HF_TOKEN')
|
13 |
+
|
14 |
+
api = HfApi()
|
15 |
+
fs = HfFileSystem()
|
16 |
+
|
17 |
+
def restart_space():
|
18 |
+
time.sleep(36000)
|
19 |
+
api.restart_space(repo_id="Tanvir1337/lonestriker-quantized-models", token=HF_TOKEN)
|
20 |
+
|
21 |
+
text = f"""
|
22 |
+
π― The Leaderboard aims to track lonestriker's exl2 quantized models.
|
23 |
+
|
24 |
+
## π οΈ Backend
|
25 |
+
|
26 |
+
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).
|
27 |
+
|
28 |
+
## π Searching
|
29 |
+
|
30 |
+
You can search for author or a specific model using the search bar.
|
31 |
+
|
32 |
+
## β Last Update
|
33 |
+
|
34 |
+
This space is last updated in **{str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M"))}**.
|
35 |
+
|
36 |
+
## π Important Note
|
37 |
+
|
38 |
+
This space potentially includes incorrectly quantized models for a model.
|
39 |
+
|
40 |
+
If you find any incorrectly quantized model, please report it to me.
|
41 |
+
"""
|
42 |
+
|
43 |
+
quant_models = [i.__dict__['id'] for i in api.list_models(author="lonestriker") if "exl2" in i.__dict__['id']]
|
44 |
+
|
45 |
+
pattern = r'\(https://huggingface\.co/([^/]+)/([^/]+)\)'
|
46 |
+
liste = {}
|
47 |
+
|
48 |
+
def process_model(i, pattern, liste):
|
49 |
+
text = fs.read_text(i + "/README.md")
|
50 |
+
matches = re.search(pattern, text)
|
51 |
+
|
52 |
+
if matches:
|
53 |
+
author = matches.group(1)
|
54 |
+
model_name = matches.group(2)
|
55 |
+
full_id = (author + "/" + model_name).split(")")[0]
|
56 |
+
|
57 |
+
try:
|
58 |
+
liste[full_id].append(i)
|
59 |
+
except KeyError:
|
60 |
+
liste[full_id] = [i]
|
61 |
+
|
62 |
+
|
63 |
+
num_threads = 64
|
64 |
+
|
65 |
+
with concurrent.futures.ThreadPoolExecutor(max_workers=num_threads) as executor:
|
66 |
+
futures = []
|
67 |
+
for i in quant_models:
|
68 |
+
future = executor.submit(process_model, i, pattern, liste)
|
69 |
+
futures.append(future)
|
70 |
+
|
71 |
+
concurrent.futures.wait(futures)
|
72 |
+
|
73 |
+
|
74 |
+
authors, models, exl2 = [], [], []
|
75 |
+
|
76 |
+
|
77 |
+
for model, values in liste.items():
|
78 |
+
models.append(model)
|
79 |
+
|
80 |
+
exl2_value = None
|
81 |
+
|
82 |
+
for value in values:
|
83 |
+
if "-exl2" in value:
|
84 |
+
exl2_value = value
|
85 |
+
|
86 |
+
authors.append(model.split('/')[0])
|
87 |
+
exl2.append(exl2_value)
|
88 |
+
|
89 |
+
|
90 |
+
df = pd.DataFrame({'π€ Author Name': authors, 'π€ Model Name': models, 'π₯ EXL2': exl2})
|
91 |
+
|
92 |
+
|
93 |
+
def search(search_text):
|
94 |
+
if not search_text:
|
95 |
+
return df
|
96 |
+
|
97 |
+
if len(search_text.split('/'))>1:
|
98 |
+
return df[df['π€ Model Name'] == clickable(search_text)]
|
99 |
+
else:
|
100 |
+
return df[df['π€ Author Name'] == clickable(search_text)]
|
101 |
+
|
102 |
+
|
103 |
+
def clickable(x):
|
104 |
+
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>'
|
105 |
+
|
106 |
+
|
107 |
+
def to_clickable(df):
|
108 |
+
for column in list(df.columns):
|
109 |
+
df[column] = df[column].apply(lambda x: clickable(x))
|
110 |
+
return df
|
111 |
+
|
112 |
+
|
113 |
+
with gr.Blocks() as demo:
|
114 |
+
gr.Markdown("""<center><img src = "https://huggingface.co/avatars/f18351bc5ce9c106ba74523d9a55567c.svg" width=200 height=200></center>""")
|
115 |
+
gr.Markdown("""<h1 align="center" id="space-title">lonestriker Quantized Models</h1>""")
|
116 |
+
gr.Markdown(text)
|
117 |
+
|
118 |
+
with gr.Column(min_width=320):
|
119 |
+
search_bar = gr.Textbox(placeholder="π Search for a author or a specific model", show_label=False)
|
120 |
+
|
121 |
+
|
122 |
+
df_clickable = to_clickable(df)
|
123 |
+
gr_df = gr.Dataframe(df_clickable, interactive=False, datatype=["markdown"]*len(df.columns))
|
124 |
+
|
125 |
+
search_bar.submit(fn=search, inputs=search_bar, outputs=gr_df)
|
126 |
+
|
127 |
+
threading.Thread(target=restart_space).start()
|
128 |
+
demo.launch()
|