xiaosu-zhu commited on
Commit
cedc10c
·
1 Parent(s): 61860b7

Auto deploy

Browse files
Files changed (1) hide show
  1. stCompressService.py +4 -5
stCompressService.py CHANGED
@@ -2,7 +2,7 @@ import os
2
  import pathlib
3
  import torch
4
  import torch.hub
5
- from torchvision.transforms.functional import convert_image_dtype
6
  from torchvision.io.image import ImageReadMode, encode_png, decode_image
7
  from PIL import Image
8
  import PIL
@@ -136,7 +136,7 @@ def main(debug: bool, quiet: bool, qp: int, disable_gpu: bool):
136
  st.download_button("Click to download restored image", data=bytes(encode_png(result.cpu()).tolist()), file_name=".".join(uploadedFile.name.split(".")[:-1] + ["png"]), mime="image/png")
137
  else:
138
  try:
139
- a = Image.open(uploadedFile)
140
  except PIL.UnidentifiedImageError:
141
  st.markdown("""
142
  <img src="https://img.shields.io/badge/ERROR-red?style=for-the-badge" alt="ERROR"/>
@@ -144,7 +144,7 @@ def main(debug: bool, quiet: bool, qp: int, disable_gpu: bool):
144
  > Image open failed. Please try other images.
145
  """, unsafe_allow_html=True)
146
  return
147
- w, h = a.size
148
  if HF_SPACE and (h > 3000 or w > 3000):
149
  st.markdown("""
150
  <img src="https://img.shields.io/badge/ERROR-red?style=for-the-badge" alt="ERROR"/>
@@ -152,8 +152,7 @@ def main(debug: bool, quiet: bool, qp: int, disable_gpu: bool):
152
  > Image is too large. Please try other images.
153
  """, unsafe_allow_html=True)
154
  return
155
- raw = torch.ByteTensor(torch.ByteStorage.from_buffer(uploadedFile.read())) # type: ignore
156
- image = decode_image(raw, ImageReadMode.RGB).to(device)
157
  # st.image(image.cpu().permute(1, 2, 0).numpy())
158
  result = compressImage(image, model, cropping)
159
 
 
2
  import pathlib
3
  import torch
4
  import torch.hub
5
+ from torchvision.transforms.functional import convert_image_dtype, pil_to_tensor
6
  from torchvision.io.image import ImageReadMode, encode_png, decode_image
7
  from PIL import Image
8
  import PIL
 
136
  st.download_button("Click to download restored image", data=bytes(encode_png(result.cpu()).tolist()), file_name=".".join(uploadedFile.name.split(".")[:-1] + ["png"]), mime="image/png")
137
  else:
138
  try:
139
+ image = Image.open(uploadedFile)
140
  except PIL.UnidentifiedImageError:
141
  st.markdown("""
142
  <img src="https://img.shields.io/badge/ERROR-red?style=for-the-badge" alt="ERROR"/>
 
144
  > Image open failed. Please try other images.
145
  """, unsafe_allow_html=True)
146
  return
147
+ w, h = image.size
148
  if HF_SPACE and (h > 3000 or w > 3000):
149
  st.markdown("""
150
  <img src="https://img.shields.io/badge/ERROR-red?style=for-the-badge" alt="ERROR"/>
 
152
  > Image is too large. Please try other images.
153
  """, unsafe_allow_html=True)
154
  return
155
+ image = pil_to_tensor(image.convert("RGB")).to(device)
 
156
  # st.image(image.cpu().permute(1, 2, 0).numpy())
157
  result = compressImage(image, model, cropping)
158