Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import gradio as gr
|
|
3 |
import pandas as pd
|
4 |
import json
|
5 |
import requests
|
|
|
6 |
|
7 |
quants = {
|
8 |
"Q2_K": 3.35,
|
@@ -19,6 +20,17 @@ quants = {
|
|
19 |
"Q8_0": 8.5,
|
20 |
}
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
def calc_model_size(parameters: int, quant: float) -> int:
|
24 |
return parameters * quant // 8
|
@@ -45,37 +57,28 @@ def get_model_config(hf_model: str) -> dict[str, Any]:
|
|
45 |
param_props_idx = model_page.find('data-target="ModelSafetensorsParams"')
|
46 |
if param_props_idx != -1:
|
47 |
param_props_start = model_page.rfind("<div", 0, param_props_idx)
|
|
|
|
|
|
|
48 |
model_size = (
|
49 |
json.loads(
|
50 |
-
|
51 |
-
prop
|
52 |
-
for prop in model_page[param_props_start:param_props_idx].split(" ")
|
53 |
-
if prop.startswith("data-props=")
|
54 |
-
][0]
|
55 |
-
.split("=")[1]
|
56 |
-
.replace('"', "")
|
57 |
-
.replace(""", '"')
|
58 |
)["safetensors"]["total"]
|
59 |
* 2
|
60 |
)
|
61 |
else:
|
62 |
param_props_idx = model_page.find('data-target="ModelHeader"')
|
63 |
param_props_start = model_page.rfind("<div", 0, param_props_idx)
|
|
|
|
|
|
|
64 |
model_size = (
|
65 |
json.loads(
|
66 |
-
|
67 |
-
prop
|
68 |
-
for prop in model_page[param_props_start:param_props_idx].split(" ")
|
69 |
-
if prop.startswith("data-props=")
|
70 |
-
][0]
|
71 |
-
.split("=")[1]
|
72 |
-
.replace('"', "")
|
73 |
-
.replace(""", '"')
|
74 |
)["model"]["safetensors"]["total"]
|
75 |
* 2
|
76 |
)
|
77 |
|
78 |
-
|
79 |
# assume fp16 weights
|
80 |
config["parameters"] = model_size / 2
|
81 |
return config
|
|
|
3 |
import pandas as pd
|
4 |
import json
|
5 |
import requests
|
6 |
+
from html.parser import HTMLParser
|
7 |
|
8 |
quants = {
|
9 |
"Q2_K": 3.35,
|
|
|
20 |
"Q8_0": 8.5,
|
21 |
}
|
22 |
|
23 |
+
class SvelteHydratorExtractor(HTMLParser):
|
24 |
+
def __init__(self):
|
25 |
+
self.data = None
|
26 |
+
super().__init__()
|
27 |
+
|
28 |
+
def handle_starttag(self, tag, attrs):
|
29 |
+
print("Start tag:", tag)
|
30 |
+
for attr in attrs:
|
31 |
+
if attr[0] == "data-props":
|
32 |
+
self.data = attr[1].replace("":", '"')
|
33 |
+
|
34 |
|
35 |
def calc_model_size(parameters: int, quant: float) -> int:
|
36 |
return parameters * quant // 8
|
|
|
57 |
param_props_idx = model_page.find('data-target="ModelSafetensorsParams"')
|
58 |
if param_props_idx != -1:
|
59 |
param_props_start = model_page.rfind("<div", 0, param_props_idx)
|
60 |
+
param_props_end = model_page.find(">", param_props_idx)
|
61 |
+
extractor = SvelteHydratorExtractor()
|
62 |
+
extractor.feed(model_page[param_props_start:param_props_end + 1])
|
63 |
model_size = (
|
64 |
json.loads(
|
65 |
+
extractor.data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
)["safetensors"]["total"]
|
67 |
* 2
|
68 |
)
|
69 |
else:
|
70 |
param_props_idx = model_page.find('data-target="ModelHeader"')
|
71 |
param_props_start = model_page.rfind("<div", 0, param_props_idx)
|
72 |
+
param_props_end = model_page.find(">", param_props_idx)
|
73 |
+
extractor = SvelteHydratorExtractor()
|
74 |
+
extractor.feed(model_page[param_props_start:param_props_end + 1])
|
75 |
model_size = (
|
76 |
json.loads(
|
77 |
+
extractor.data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
)["model"]["safetensors"]["total"]
|
79 |
* 2
|
80 |
)
|
81 |
|
|
|
82 |
# assume fp16 weights
|
83 |
config["parameters"] = model_size / 2
|
84 |
return config
|