multimodalart HF staff commited on
Commit
5a2a7f7
1 Parent(s): 72a0488

Update share_btn.py

Browse files
Files changed (1) hide show
  1. share_btn.py +4 -3
share_btn.py CHANGED
@@ -11,9 +11,6 @@ loading_icon_html = """<svg id="share-btn-loading-icon" style="display:none;" cl
11
  share_js = """async () => {
12
  async function uploadFile(file){
13
  const UPLOAD_URL = 'https://huggingface.co/uploads';
14
- if(file.type == ""){
15
- file.type = "webp"
16
- }
17
  console.log(file.type)
18
  const response = await fetch(UPLOAD_URL, {
19
  method: 'POST',
@@ -32,9 +29,13 @@ share_js = """async () => {
32
  const blob = await res.blob();
33
  const imgId = Date.now() % 200;
34
  const isPng = imgEl.src.startsWith(`data:image/png`);
 
35
  if(isPng){
36
  const fileName = `sd-perception-${{imgId}}.png`;
37
  return new File([blob], fileName, { type: 'image/png' });
 
 
 
38
  }else{
39
  const fileName = `sd-perception-${{imgId}}.jpg`;
40
  return new File([blob], fileName, { type: 'image/jpeg' });
 
11
  share_js = """async () => {
12
  async function uploadFile(file){
13
  const UPLOAD_URL = 'https://huggingface.co/uploads';
 
 
 
14
  console.log(file.type)
15
  const response = await fetch(UPLOAD_URL, {
16
  method: 'POST',
 
29
  const blob = await res.blob();
30
  const imgId = Date.now() % 200;
31
  const isPng = imgEl.src.startsWith(`data:image/png`);
32
+ const isWebp = imgEl.src.startsWith(`data:;`) || imgEl.src.startsWith(`data:image/webp`);
33
  if(isPng){
34
  const fileName = `sd-perception-${{imgId}}.png`;
35
  return new File([blob], fileName, { type: 'image/png' });
36
+ }else if(isWebp){
37
+ const fileName = `sd-perception-${{imgId}}.webp`;
38
+ return new File([blob], fileName, { type: 'image/webp' });
39
  }else{
40
  const fileName = `sd-perception-${{imgId}}.jpg`;
41
  return new File([blob], fileName, { type: 'image/jpeg' });