Spaces:
Build error
Build error
秋山翔
commited on
Commit
·
af3dcd2
1
Parent(s):
8bc4bd8
MAINT: auto-resize
Browse files
app.py
CHANGED
|
@@ -9,6 +9,8 @@ import torchvision.transforms as transforms
|
|
| 9 |
from torch.autograd import Variable
|
| 10 |
from network.Transformer import Transformer
|
| 11 |
|
|
|
|
|
|
|
| 12 |
import logging
|
| 13 |
|
| 14 |
logger = logging.getLogger(__name__)
|
|
@@ -67,16 +69,16 @@ def get_model(style):
|
|
| 67 |
return shinkai_model
|
| 68 |
|
| 69 |
|
| 70 |
-
def
|
| 71 |
logger.info(f"Image Height: {img.height}, Image Width: {img.width}")
|
| 72 |
if img.height > MAX_DIMENSION or img.width > MAX_DIMENSION:
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
|
| 77 |
|
| 78 |
def inference(img, style):
|
| 79 |
-
|
| 80 |
|
| 81 |
# load image
|
| 82 |
input_image = img.convert(COLOUR_MODEL)
|
|
|
|
| 9 |
from torch.autograd import Variable
|
| 10 |
from network.Transformer import Transformer
|
| 11 |
|
| 12 |
+
from PIL import Image
|
| 13 |
+
|
| 14 |
import logging
|
| 15 |
|
| 16 |
logger = logging.getLogger(__name__)
|
|
|
|
| 69 |
return shinkai_model
|
| 70 |
|
| 71 |
|
| 72 |
+
def adjust_image_for_model(img):
|
| 73 |
logger.info(f"Image Height: {img.height}, Image Width: {img.width}")
|
| 74 |
if img.height > MAX_DIMENSION or img.width > MAX_DIMENSION:
|
| 75 |
+
img = img.thumbnail(MAX_DIMENSION, Image.ANTIALIAS)
|
| 76 |
+
|
| 77 |
+
return img
|
| 78 |
|
| 79 |
|
| 80 |
def inference(img, style):
|
| 81 |
+
img = adjust_image_for_model(img)
|
| 82 |
|
| 83 |
# load image
|
| 84 |
input_image = img.convert(COLOUR_MODEL)
|