NyxKrage commited on
Commit
260ecb5
·
verified ·
1 Parent(s): 6c720bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -7
app.py CHANGED
@@ -27,18 +27,39 @@ def get_model_config(hf_model: str) -> dict[str, Any]:
27
  config = requests.get(
28
  f"https://huggingface.co/{hf_model}/raw/main/config.json"
29
  ).json()
30
- model_index = {}
31
  try:
32
- model_index = requests.get(
33
  f"https://huggingface.co/{hf_model}/raw/main/model.safetensors.index.json"
34
- ).json()
35
  except:
36
- model_index = requests.get(
37
- f"https://huggingface.co/{hf_model}/raw/main/pytorch_model.bin.index.json"
38
- ).json()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
  # assume fp16 weights
41
- config["parameters"] = model_index["metadata"]["total_size"] / 2
42
  return config
43
 
44
 
 
27
  config = requests.get(
28
  f"https://huggingface.co/{hf_model}/raw/main/config.json"
29
  ).json()
30
+ model_size = 0
31
  try:
32
+ model_size = requests.get(
33
  f"https://huggingface.co/{hf_model}/raw/main/model.safetensors.index.json"
34
+ ).json()["metadta"]["total_size"]
35
  except:
36
+ try:
37
+ model_size = requests.get(
38
+ f"https://huggingface.co/{hf_model}/raw/main/pytorch_model.bin.index.json"
39
+ ).json()["metadta"]["total_size"]
40
+ except:
41
+ model_page = requests.get(
42
+ f"https://huggingface.co/{hf_model}"
43
+ ).text
44
+ param_props_idx = model_page.find('data-target="ModelSafetensorsParams"')
45
+ param_props_start = model_page.rfind("<div", 0, param_props_idx)
46
+ model_size = (
47
+ json.loads(
48
+ [
49
+ prop
50
+ for prop in model_page[param_props_start:param_props_idx].split(" ")
51
+ if prop.startswith("data-props=")
52
+ ][0]
53
+ .split("=")[1]
54
+ .replace('"', "")
55
+ .replace("&quot;", '"')
56
+ )["safetensors"]["total"]
57
+ * 2
58
+ )
59
+
60
 
61
  # assume fp16 weights
62
+ config["parameters"] = model_size / 2
63
  return config
64
 
65