Spaces:
Build error
Build error
akiyamasho
commited on
Commit
•
bb55b33
1
Parent(s):
bc89311
MAINT: put back models due to 403 in HF Hub
Browse files- app.py +6 -26
- models/hosoda_mamoru.pth +3 -0
- models/kon_satoshi.pth +3 -0
- models/miyazaki_hayao.pth +3 -0
- models/shinkai_makoto.pth +3 -0
- requirements_dev.txt +1 -2
app.py
CHANGED
@@ -1,5 +1,3 @@
|
|
1 |
-
from cgitb import enable
|
2 |
-
from ctypes.wintypes import HFONT
|
3 |
import os
|
4 |
import sys
|
5 |
import torch
|
@@ -10,7 +8,6 @@ import torchvision.transforms as transforms
|
|
10 |
|
11 |
from torch.autograd import Variable
|
12 |
from network.Transformer import Transformer
|
13 |
-
from huggingface_hub import hf_hub_download
|
14 |
|
15 |
from PIL import Image
|
16 |
|
@@ -19,8 +16,6 @@ import logging
|
|
19 |
logging.basicConfig(level=logging.INFO)
|
20 |
logger = logging.getLogger(__name__)
|
21 |
|
22 |
-
# Constants
|
23 |
-
|
24 |
MAX_DIMENSION = 1280
|
25 |
MODEL_PATH = "models"
|
26 |
COLOUR_MODEL = "RGB"
|
@@ -32,37 +27,23 @@ STYLE_KON = "Satoshi Kon"
|
|
32 |
DEFAULT_STYLE = STYLE_SHINKAI
|
33 |
STYLE_CHOICE_LIST = [STYLE_SHINKAI, STYLE_HOSODA, STYLE_MIYAZAKI, STYLE_KON]
|
34 |
|
35 |
-
MODEL_REPO_ID = "akiyamasho/AnimeBackgroundGAN"
|
36 |
-
MODEL_FILE_SHINKAI = "shinkai_makoto.pth"
|
37 |
-
MODEL_FILE_HOSODA = "hosoda_mamoru.pth"
|
38 |
-
MODEL_FILE_MIYAZAKI = "miyazaki_hayao.pth"
|
39 |
-
MODEL_FILE_KON = "kon_satoshi.pth"
|
40 |
-
|
41 |
-
# Model Initalisation
|
42 |
-
shinkai_model_hfhub = hf_hub_download(repo_id=MODEL_REPO_ID, filename=MODEL_FILE_SHINKAI)
|
43 |
-
hosoda_model_hfhub = hf_hub_download(repo_id=MODEL_REPO_ID, filename=MODEL_FILE_HOSODA)
|
44 |
-
miyazaki_model_hfhub = hf_hub_download(repo_id=MODEL_REPO_ID, filename=MODEL_FILE_MIYAZAKI)
|
45 |
-
kon_model_hfhub = hf_hub_download(repo_id=MODEL_REPO_ID, filename=MODEL_FILE_KON)
|
46 |
-
|
47 |
shinkai_model = Transformer()
|
48 |
hosoda_model = Transformer()
|
49 |
miyazaki_model = Transformer()
|
50 |
kon_model = Transformer()
|
51 |
|
52 |
-
enable_gpu = torch.cuda.is_available()
|
53 |
-
map_location = torch.device("cuda") if enable_gpu else "cpu"
|
54 |
|
55 |
shinkai_model.load_state_dict(
|
56 |
-
torch.load(
|
57 |
)
|
58 |
hosoda_model.load_state_dict(
|
59 |
-
torch.load(
|
60 |
)
|
61 |
miyazaki_model.load_state_dict(
|
62 |
-
torch.load(
|
63 |
)
|
64 |
kon_model.load_state_dict(
|
65 |
-
torch.load(
|
66 |
)
|
67 |
|
68 |
shinkai_model.eval()
|
@@ -70,7 +51,8 @@ hosoda_model.eval()
|
|
70 |
miyazaki_model.eval()
|
71 |
kon_model.eval()
|
72 |
|
73 |
-
|
|
|
74 |
|
75 |
def get_model(style):
|
76 |
if style == STYLE_SHINKAI:
|
@@ -127,8 +109,6 @@ def inference(img, style):
|
|
127 |
return transforms.ToPILImage()(output_image)
|
128 |
|
129 |
|
130 |
-
# Gradio setup
|
131 |
-
|
132 |
title = "Anime Background GAN"
|
133 |
description = "Gradio Demo for CartoonGAN by Chen Et. Al. Models are Shinkai Makoto, Hosoda Mamoru, Kon Satoshi, and Miyazaki Hayao."
|
134 |
article = "<p style='text-align: center'><a href='http://openaccess.thecvf.com/content_cvpr_2018/CameraReady/2205.pdf' target='_blank'>CartoonGAN Whitepaper from Chen et.al</a></p><p style='text-align: center'><a href='https://github.com/venture-anime/cartoongan-pytorch' target='_blank'>Github Repo</a></p><p style='text-align: center'><a href='https://github.com/Yijunmaverick/CartoonGAN-Test-Pytorch-Torch' target='_blank'>Original Implementation from Yijunmaverick</a></p><center><img src='https://visitor-badge.glitch.me/badge?page_id=akiyamasho' alt='visitor badge'></center></p>"
|
|
|
|
|
|
|
1 |
import os
|
2 |
import sys
|
3 |
import torch
|
|
|
8 |
|
9 |
from torch.autograd import Variable
|
10 |
from network.Transformer import Transformer
|
|
|
11 |
|
12 |
from PIL import Image
|
13 |
|
|
|
16 |
logging.basicConfig(level=logging.INFO)
|
17 |
logger = logging.getLogger(__name__)
|
18 |
|
|
|
|
|
19 |
MAX_DIMENSION = 1280
|
20 |
MODEL_PATH = "models"
|
21 |
COLOUR_MODEL = "RGB"
|
|
|
27 |
DEFAULT_STYLE = STYLE_SHINKAI
|
28 |
STYLE_CHOICE_LIST = [STYLE_SHINKAI, STYLE_HOSODA, STYLE_MIYAZAKI, STYLE_KON]
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
shinkai_model = Transformer()
|
31 |
hosoda_model = Transformer()
|
32 |
miyazaki_model = Transformer()
|
33 |
kon_model = Transformer()
|
34 |
|
|
|
|
|
35 |
|
36 |
shinkai_model.load_state_dict(
|
37 |
+
torch.load(os.path.join(MODEL_PATH, "shinkai_makoto.pth"))
|
38 |
)
|
39 |
hosoda_model.load_state_dict(
|
40 |
+
torch.load(os.path.join(MODEL_PATH, "hosoda_mamoru.pth"))
|
41 |
)
|
42 |
miyazaki_model.load_state_dict(
|
43 |
+
torch.load(os.path.join(MODEL_PATH, "miyazaki_hayao.pth"))
|
44 |
)
|
45 |
kon_model.load_state_dict(
|
46 |
+
torch.load(os.path.join(MODEL_PATH, "kon_satoshi.pth"))
|
47 |
)
|
48 |
|
49 |
shinkai_model.eval()
|
|
|
51 |
miyazaki_model.eval()
|
52 |
kon_model.eval()
|
53 |
|
54 |
+
enable_gpu = torch.cuda.is_available()
|
55 |
+
|
56 |
|
57 |
def get_model(style):
|
58 |
if style == STYLE_SHINKAI:
|
|
|
109 |
return transforms.ToPILImage()(output_image)
|
110 |
|
111 |
|
|
|
|
|
112 |
title = "Anime Background GAN"
|
113 |
description = "Gradio Demo for CartoonGAN by Chen Et. Al. Models are Shinkai Makoto, Hosoda Mamoru, Kon Satoshi, and Miyazaki Hayao."
|
114 |
article = "<p style='text-align: center'><a href='http://openaccess.thecvf.com/content_cvpr_2018/CameraReady/2205.pdf' target='_blank'>CartoonGAN Whitepaper from Chen et.al</a></p><p style='text-align: center'><a href='https://github.com/venture-anime/cartoongan-pytorch' target='_blank'>Github Repo</a></p><p style='text-align: center'><a href='https://github.com/Yijunmaverick/CartoonGAN-Test-Pytorch-Torch' target='_blank'>Original Implementation from Yijunmaverick</a></p><center><img src='https://visitor-badge.glitch.me/badge?page_id=akiyamasho' alt='visitor badge'></center></p>"
|
models/hosoda_mamoru.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c666eea7700864d5972765cc43e926d900174648297bfef494006dc230fd1bf0
|
3 |
+
size 44529096
|
models/kon_satoshi.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0629352a54838e56a2ad7fca3e6e51e6889d4338c37469f9ddb43e5929ef9475
|
3 |
+
size 44529096
|
models/miyazaki_hayao.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8ab0e492efb3b705487db38679e363dc8b1f016692913bbe100587d695a9e2b5
|
3 |
+
size 44529096
|
models/shinkai_makoto.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c3547f611e780e79aebde7f7bc2b6c278555d701620f125583d666351044c486
|
3 |
+
size 44529096
|
requirements_dev.txt
CHANGED
@@ -2,5 +2,4 @@
|
|
2 |
black==21.12b0
|
3 |
flake8==4.0.1
|
4 |
gradio==2.9.1
|
5 |
-
jinja2==3.1.1
|
6 |
-
huggingface_hub==0.4.0
|
|
|
2 |
black==21.12b0
|
3 |
flake8==4.0.1
|
4 |
gradio==2.9.1
|
5 |
+
jinja2==3.1.1
|
|