Spaces:
Running
Running
Update src/util.py
Browse files- src/util.py +2 -13
src/util.py
CHANGED
@@ -20,15 +20,6 @@ bucket = oss2.Bucket(oss2.Auth(access_key_id, access_key_secret), endpoint, buck
|
|
20 |
oss_path = "hejunjie.hjj/TransferAnythingHF"
|
21 |
oss_path_img_gallery = "hejunjie.hjj/TransferAnythingHF_img_gallery"
|
22 |
|
23 |
-
|
24 |
-
def resize(image, short_side_length=768):
|
25 |
-
width, height = image.size
|
26 |
-
ratio = short_side_length / min(width, height)
|
27 |
-
new_width = int(width * ratio)
|
28 |
-
new_height = int(height * ratio)
|
29 |
-
resized_image = image.resize((new_width, new_height))
|
30 |
-
return resized_image
|
31 |
-
|
32 |
|
33 |
def download_img_pil(index, img_url):
|
34 |
# print(img_url)
|
@@ -60,13 +51,11 @@ def download_images(img_urls, batch_size):
|
|
60 |
|
61 |
def upload_np_2_oss(input_image, name="cache.png", gallery=False):
|
62 |
assert name.lower().endswith((".png", ".jpg")), name
|
63 |
-
if name.lower().endswith(".png"):
|
64 |
-
name = name[:-4] + ".jpg"
|
65 |
imgByteArr = io.BytesIO()
|
66 |
if name.lower().endswith(".png"):
|
67 |
-
|
68 |
else:
|
69 |
-
|
70 |
imgByteArr = imgByteArr.getvalue()
|
71 |
|
72 |
if gallery:
|
|
|
20 |
oss_path = "hejunjie.hjj/TransferAnythingHF"
|
21 |
oss_path_img_gallery = "hejunjie.hjj/TransferAnythingHF_img_gallery"
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
def download_img_pil(index, img_url):
|
25 |
# print(img_url)
|
|
|
51 |
|
52 |
def upload_np_2_oss(input_image, name="cache.png", gallery=False):
|
53 |
assert name.lower().endswith((".png", ".jpg")), name
|
|
|
|
|
54 |
imgByteArr = io.BytesIO()
|
55 |
if name.lower().endswith(".png"):
|
56 |
+
Image.fromarray(input_image).save(imgByteArr, format="PNG")
|
57 |
else:
|
58 |
+
Image.fromarray(input_image).save(imgByteArr, format="JPEG", quality=95)
|
59 |
imgByteArr = imgByteArr.getvalue()
|
60 |
|
61 |
if gallery:
|