NyxKrage commited on
Commit
a017d2a
·
verified ·
1 Parent(s): 3930797

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +22 -16
index.html CHANGED
@@ -82,34 +82,40 @@
82
  'Authorization': `Bearer ${hf_token}`
83
  }
84
  }
85
- let config = await fetch(
86
  `https://huggingface.co/${hf_model}/raw/main/config.json`, auth
87
- ).then(r => r.json())
 
 
 
 
88
  let model_size = 0
89
  try {
90
  model_size = (await fetch(`https://huggingface.co/${hf_model}/resolve/main/model.safetensors.index.json`, auth).then(r => r.json()))["metadata"]["total_size"] / 2
91
  if (isNaN(model_size)) {
92
- throw new Erorr("no size in safetensors metadata")
93
  }
94
  } catch (e) {
95
  try {
96
  model_size = (await fetch(`https://huggingface.co/${hf_model}/resolve/main/pytorch_model.bin.index.json`, auth).then(r => r.json()))["metadata"]["total_size"] / 2
97
  if (isNaN(model_size)) {
98
- throw new Erorr("no size in pytorch metadata")
99
  }
100
  } catch {
101
- let model_page = await fetch(
102
- "https://corsproxy.io/?" + encodeURIComponent(`https://huggingface.co/${hf_model}`)
103
- ).then(r => r.text())
104
- let el = document.createElement( 'html' );
105
- el.innerHTML = model_page
106
- let params_el = el.querySelector('div[data-target="ModelSafetensorsParams"]')
107
- if (params_el !== null) {
108
- model_size = JSON.parse(params_el.attributes.getNamedItem("data-props").value)["safetensors"]["total"]
109
- } else {
110
- params_el = el.querySelector('div[data-target="ModelHeader"]')
111
- model_size = JSON.parse(params_el.attributes.getNamedItem("data-props").value)["model"]["safetensors"]["total"]
112
- }
 
 
113
  }
114
  }
115
  config.parameters = model_size
 
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 === 403) {
89
+ throw new Error("Model is either private or gated and you have not provided an access token or the provided access token does not have access to the repo")
90
+ }
91
+ let config = await configRes.json()
92
  let model_size = 0
93
  try {
94
  model_size = (await fetch(`https://huggingface.co/${hf_model}/resolve/main/model.safetensors.index.json`, auth).then(r => r.json()))["metadata"]["total_size"] / 2
95
  if (isNaN(model_size)) {
96
+ throw new Error("no size in safetensors metadata")
97
  }
98
  } catch (e) {
99
  try {
100
  model_size = (await fetch(`https://huggingface.co/${hf_model}/resolve/main/pytorch_model.bin.index.json`, auth).then(r => r.json()))["metadata"]["total_size"] / 2
101
  if (isNaN(model_size)) {
102
+ throw new Error("no size in pytorch metadata")
103
  }
104
  } catch {
105
+ throw new Error("Neither model.safetensors.index.json nor pytorch_model.bin.index.json contain size of model")
106
+ // huggingface is now blocking corsproxy
107
+ // let model_page = await fetch(
108
+ // "https://corsproxy.io/?" + encodeURIComponent(`https://huggingface.co/${hf_model}`)
109
+ // ).then(r => r.text())
110
+ // let el = document.createElement( 'html' );
111
+ // el.innerHTML = model_page
112
+ // let params_el = el.querySelector('div[data-target="ModelSafetensorsParams"]')
113
+ // if (params_el !== null) {
114
+ // model_size = JSON.parse(params_el.attributes.getNamedItem("data-props").value)["safetensors"]["total"]
115
+ // } else {
116
+ // params_el = el.querySelector('div[data-target="ModelHeader"]')
117
+ // model_size = JSON.parse(params_el.attributes.getNamedItem("data-props").value)["model"]["safetensors"]["total"]
118
+ // }
119
  }
120
  }
121
  config.parameters = model_size