simon-simon-simon commited on
Commit
46f700c
·
verified ·
1 Parent(s): 9eeb198

Support webp images for community share button

Browse files

Fixes issue of community forum post images with `<img src="{"error":"Only GIF, JPEG, JPG, MOV, MP3, MP4, MPGA, PNG, QT, WAV, WEBM, WEBP files are supported"}" />` output. E.g. https://huggingface.co/spaces/multimodalart/LoraTheExplorer/discussions/212

Files changed (1) hide show
  1. share_btn.py +7 -0
share_btn.py CHANGED
@@ -31,9 +31,16 @@ share_js = """async () => {
31
  console.log(blob.type)
32
  const imgId = Date.now() % 200;
33
  const isPng = blob.type == 'image/png';
 
 
 
 
34
  if(isPng){
35
  const fileName = `sd-perception-${imgId}.png`;
36
  return new File([blob], fileName, { type: 'image/png' });
 
 
 
37
  }else{
38
  const fileName = `sd-perception-${imgId}.jpg`;
39
  return new File([blob], fileName, { type: 'image/jpeg' });
 
31
  console.log(blob.type)
32
  const imgId = Date.now() % 200;
33
  const isPng = blob.type == 'image/png';
34
+ const isWebp = blob.type == 'image/webp';
35
+ const isOctetStream = blob.type == 'application/octet-stream';
36
+ const isLikelyWebp = isOctetStream && imgEl.src.toLowerCase().endsWith('.webp');
37
+
38
  if(isPng){
39
  const fileName = `sd-perception-${imgId}.png`;
40
  return new File([blob], fileName, { type: 'image/png' });
41
+ }else if(isWebp || isLikelyWebp){
42
+ const fileName = `sd-perception-${imgId}.webp`;
43
+ return new File([blob], fileName, { type: 'image/webp' });
44
  }else{
45
  const fileName = `sd-perception-${imgId}.jpg`;
46
  return new File([blob], fileName, { type: 'image/jpeg' });