Update
Browse files- .pre-commit-config.yaml +35 -0
- .style.yapf +5 -0
- README.md +11 -11
- app.py +36 -53
.pre-commit-config.yaml
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
repos:
|
2 |
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
3 |
+
rev: v4.2.0
|
4 |
+
hooks:
|
5 |
+
- id: check-executables-have-shebangs
|
6 |
+
- id: check-json
|
7 |
+
- id: check-merge-conflict
|
8 |
+
- id: check-shebang-scripts-are-executable
|
9 |
+
- id: check-toml
|
10 |
+
- id: check-yaml
|
11 |
+
- id: double-quote-string-fixer
|
12 |
+
- id: end-of-file-fixer
|
13 |
+
- id: mixed-line-ending
|
14 |
+
args: ['--fix=lf']
|
15 |
+
- id: requirements-txt-fixer
|
16 |
+
- id: trailing-whitespace
|
17 |
+
- repo: https://github.com/myint/docformatter
|
18 |
+
rev: v1.4
|
19 |
+
hooks:
|
20 |
+
- id: docformatter
|
21 |
+
args: ['--in-place']
|
22 |
+
- repo: https://github.com/pycqa/isort
|
23 |
+
rev: 5.12.0
|
24 |
+
hooks:
|
25 |
+
- id: isort
|
26 |
+
- repo: https://github.com/pre-commit/mirrors-mypy
|
27 |
+
rev: v0.991
|
28 |
+
hooks:
|
29 |
+
- id: mypy
|
30 |
+
args: ['--ignore-missing-imports']
|
31 |
+
- repo: https://github.com/google/yapf
|
32 |
+
rev: v0.32.0
|
33 |
+
hooks:
|
34 |
+
- id: yapf
|
35 |
+
args: ['--parallel', '--in-place']
|
.style.yapf
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[style]
|
2 |
+
based_on_style = pep8
|
3 |
+
blank_line_before_nested_class_or_def = false
|
4 |
+
spaces_before_comment = 2
|
5 |
+
split_before_logical_operator = true
|
README.md
CHANGED
@@ -4,35 +4,35 @@ emoji: 📚
|
|
4 |
colorFrom: pink
|
5 |
colorTo: indigo
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 3.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
11 |
|
12 |
# Configuration
|
13 |
|
14 |
-
`title`: _string_
|
15 |
Display title for the Space
|
16 |
|
17 |
-
`emoji`: _string_
|
18 |
Space emoji (emoji-only character allowed)
|
19 |
|
20 |
-
`colorFrom`: _string_
|
21 |
Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray)
|
22 |
|
23 |
-
`colorTo`: _string_
|
24 |
Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray)
|
25 |
|
26 |
-
`sdk`: _string_
|
27 |
Can be either `gradio` or `streamlit`
|
28 |
|
29 |
-
`sdk_version` : _string_
|
30 |
-
Only applicable for `streamlit` SDK.
|
31 |
See [doc](https://hf.co/docs/hub/spaces) for more info on supported versions.
|
32 |
|
33 |
-
`app_file`: _string_
|
34 |
-
Path to your main application file (which contains either `gradio` or `streamlit` Python code).
|
35 |
Path is relative to the root of the repository.
|
36 |
|
37 |
-
`pinned`: _boolean_
|
38 |
Whether the Space stays on top of your list.
|
|
|
4 |
colorFrom: pink
|
5 |
colorTo: indigo
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 3.19.1
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
11 |
|
12 |
# Configuration
|
13 |
|
14 |
+
`title`: _string_
|
15 |
Display title for the Space
|
16 |
|
17 |
+
`emoji`: _string_
|
18 |
Space emoji (emoji-only character allowed)
|
19 |
|
20 |
+
`colorFrom`: _string_
|
21 |
Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray)
|
22 |
|
23 |
+
`colorTo`: _string_
|
24 |
Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray)
|
25 |
|
26 |
+
`sdk`: _string_
|
27 |
Can be either `gradio` or `streamlit`
|
28 |
|
29 |
+
`sdk_version` : _string_
|
30 |
+
Only applicable for `streamlit` SDK.
|
31 |
See [doc](https://hf.co/docs/hub/spaces) for more info on supported versions.
|
32 |
|
33 |
+
`app_file`: _string_
|
34 |
+
Path to your main application file (which contains either `gradio` or `streamlit` Python code).
|
35 |
Path is relative to the root of the repository.
|
36 |
|
37 |
+
`pinned`: _boolean_
|
38 |
Whether the Space stays on top of your list.
|
app.py
CHANGED
@@ -2,7 +2,6 @@
|
|
2 |
|
3 |
from __future__ import annotations
|
4 |
|
5 |
-
import argparse
|
6 |
import functools
|
7 |
import os
|
8 |
import pickle
|
@@ -17,27 +16,11 @@ from huggingface_hub import hf_hub_download
|
|
17 |
sys.path.insert(0, 'stylegan3')
|
18 |
|
19 |
TITLE = 'StyleGAN3 Anime Face Generation'
|
20 |
-
DESCRIPTION = 'Expected execution time on Hugging Face Spaces: 20s'
|
21 |
-
ARTICLE = '<center><img src="https://visitor-badge.glitch.me/badge?page_id=hysts.stylegan3-anime-face-generation-exp002" alt="visitor badge"/></center>'
|
22 |
|
23 |
MODEL_REPO = 'hysts/stylegan3-anime-face-exp002-model'
|
24 |
MODEL_FILE_NAME = '009000.pkl'
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
def parse_args() -> argparse.Namespace:
|
30 |
-
parser = argparse.ArgumentParser()
|
31 |
-
parser.add_argument('--device', type=str, default='cpu')
|
32 |
-
parser.add_argument('--theme', type=str)
|
33 |
-
parser.add_argument('--live', action='store_true')
|
34 |
-
parser.add_argument('--share', action='store_true')
|
35 |
-
parser.add_argument('--port', type=int)
|
36 |
-
parser.add_argument('--disable-queue',
|
37 |
-
dest='enable_queue',
|
38 |
-
action='store_false')
|
39 |
-
parser.add_argument('--allow-flagging', type=str, default='never')
|
40 |
-
return parser.parse_args()
|
41 |
|
42 |
|
43 |
def make_transform(translate: tuple[float, float], angle: float) -> np.ndarray:
|
@@ -76,7 +59,9 @@ def generate_image(seed: int, truncation_psi: float, tx: float, ty: float,
|
|
76 |
|
77 |
|
78 |
def load_model(device: torch.device) -> nn.Module:
|
79 |
-
path = hf_hub_download(MODEL_REPO,
|
|
|
|
|
80 |
with open(path, 'rb') as f:
|
81 |
model = pickle.load(f)
|
82 |
model.eval()
|
@@ -88,37 +73,35 @@ def load_model(device: torch.device) -> nn.Module:
|
|
88 |
return model
|
89 |
|
90 |
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
func
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
)
|
121 |
-
|
122 |
-
|
123 |
-
if __name__ == '__main__':
|
124 |
-
main()
|
|
|
2 |
|
3 |
from __future__ import annotations
|
4 |
|
|
|
5 |
import functools
|
6 |
import os
|
7 |
import pickle
|
|
|
16 |
sys.path.insert(0, 'stylegan3')
|
17 |
|
18 |
TITLE = 'StyleGAN3 Anime Face Generation'
|
|
|
|
|
19 |
|
20 |
MODEL_REPO = 'hysts/stylegan3-anime-face-exp002-model'
|
21 |
MODEL_FILE_NAME = '009000.pkl'
|
22 |
|
23 |
+
HF_TOKEN = os.getenv('HF_TOKEN')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
|
26 |
def make_transform(translate: tuple[float, float], angle: float) -> np.ndarray:
|
|
|
59 |
|
60 |
|
61 |
def load_model(device: torch.device) -> nn.Module:
|
62 |
+
path = hf_hub_download(MODEL_REPO,
|
63 |
+
MODEL_FILE_NAME,
|
64 |
+
use_auth_token=HF_TOKEN)
|
65 |
with open(path, 'rb') as f:
|
66 |
model = pickle.load(f)
|
67 |
model.eval()
|
|
|
73 |
return model
|
74 |
|
75 |
|
76 |
+
device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
|
77 |
+
model = load_model(device)
|
78 |
+
func = functools.partial(generate_image, model=model, device=device)
|
79 |
+
|
80 |
+
gr.Interface(
|
81 |
+
fn=func,
|
82 |
+
inputs=[
|
83 |
+
gr.Slider(label='Seed',
|
84 |
+
minimum=0,
|
85 |
+
maximum=10000000000,
|
86 |
+
step=1,
|
87 |
+
value=3407851645),
|
88 |
+
gr.Slider(label='Truncation psi',
|
89 |
+
minimum=0,
|
90 |
+
maximum=2,
|
91 |
+
step=0.05,
|
92 |
+
value=0.7),
|
93 |
+
gr.Slider(label='Translate X',
|
94 |
+
minimum=-1,
|
95 |
+
maximum=1,
|
96 |
+
step=0.05,
|
97 |
+
value=0),
|
98 |
+
gr.Slider(label='Translate Y',
|
99 |
+
minimum=-1,
|
100 |
+
maximum=1,
|
101 |
+
step=0.05,
|
102 |
+
value=0),
|
103 |
+
gr.Slider(label='Angle', minimum=-180, maximum=180, step=5, value=0),
|
104 |
+
],
|
105 |
+
outputs=gr.Image(label='Output', type='numpy'),
|
106 |
+
title=TITLE,
|
107 |
+
).queue().launch(show_api=False)
|
|
|
|