NyxKrage commited on
Commit
2a0da0f
·
verified ·
1 Parent(s): 47ee99f

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +20 -18
index.html CHANGED
@@ -82,16 +82,16 @@
82
  'Authorization': `Bearer ${hf_token}`
83
  }
84
  }
85
- let configRes = await fetch(
86
  `https://huggingface.co/${hf_model}/raw/main/config.json`, auth
87
  )
88
- if (configRes.status === 401) {
89
  throw new Error("Model is either private or gated, you must provide an access token")
90
  }
91
- if (configRes.status === 403) {
92
  throw new Error("Model is either private or gated and provided access token does not have access to the repo")
93
  }
94
- let config = await configRes.json()
95
  let model_size = 0
96
  let dtype = parseInt(config["torch_dtype"].replaceAll(/\D/g, '')) / 8
97
  try {
@@ -106,20 +106,22 @@
106
  throw new Error("no size in pytorch metadata")
107
  }
108
  } catch {
109
- throw new Error("Neither model.safetensors.index.json nor pytorch_model.bin.index.json contain size of model")
110
- // huggingface is now blocking corsproxy
111
- // let model_page = await fetch(
112
- // "https://corsproxy.io/?" + encodeURIComponent(`https://huggingface.co/${hf_model}`)
113
- // ).then(r => r.text())
114
- // let el = document.createElement( 'html' );
115
- // el.innerHTML = model_page
116
- // let params_el = el.querySelector('div[data-target="ModelSafetensorsParams"]')
117
- // if (params_el !== null) {
118
- // model_size = JSON.parse(params_el.attributes.getNamedItem("data-props").value)["safetensors"]["total"]
119
- // } else {
120
- // params_el = el.querySelector('div[data-target="ModelHeader"]')
121
- // model_size = JSON.parse(params_el.attributes.getNamedItem("data-props").value)["model"]["safetensors"]["total"]
122
- // }
 
 
123
  }
124
  }
125
  config.parameters = model_size
 
82
  'Authorization': `Bearer ${hf_token}`
83
  }
84
  }
85
+ let config_res = await fetch(
86
  `https://huggingface.co/${hf_model}/raw/main/config.json`, auth
87
  )
88
+ if (config_res.status === 401) {
89
  throw new Error("Model is either private or gated, you must provide an access token")
90
  }
91
+ if (config_res.status === 403) {
92
  throw new Error("Model is either private or gated and provided access token does not have access to the repo")
93
  }
94
+ let config = await config_res.json()
95
  let model_size = 0
96
  let dtype = parseInt(config["torch_dtype"].replaceAll(/\D/g, '')) / 8
97
  try {
 
106
  throw new Error("no size in pytorch metadata")
107
  }
108
  } catch {
109
+ try {
110
+ let model_page = await fetch(
111
+ `https://huggingface.co/${hf_model}`
112
+ ).then(r => r.text())
113
+ let el = document.createElement( 'html' );
114
+ el.innerHTML = model_page
115
+ let params_el = el.querySelector('div[data-target="ModelSafetensorsParams"]')
116
+ if (params_el !== null) {
117
+ model_size = JSON.parse(params_el.attributes.getNamedItem("data-props").value)["safetensors"]["total"]
118
+ } else {
119
+ params_el = el.querySelector('div[data-target="ModelHeader"]')
120
+ model_size = JSON.parse(params_el.attributes.getNamedItem("data-props").value)["model"]["safetensors"]["total"]
121
+ }
122
+ } catch {
123
+ throw new Error("Couldn't determine model size from safetensor/pytorch index metadata nor from the model card. If the model is an unsharded pytorch model, it is not supported by this calculator.")
124
+ }
125
  }
126
  }
127
  config.parameters = model_size