Update
Browse files- .pre-commit-config.yaml +2 -12
- README.md +1 -1
- app.py +76 -105
- model.py +4 -3
.pre-commit-config.yaml
CHANGED
@@ -21,11 +21,11 @@ repos:
|
|
21 |
- id: docformatter
|
22 |
args: ['--in-place']
|
23 |
- repo: https://github.com/pycqa/isort
|
24 |
-
rev: 5.
|
25 |
hooks:
|
26 |
- id: isort
|
27 |
- repo: https://github.com/pre-commit/mirrors-mypy
|
28 |
-
rev: v0.
|
29 |
hooks:
|
30 |
- id: mypy
|
31 |
args: ['--ignore-missing-imports']
|
@@ -34,13 +34,3 @@ repos:
|
|
34 |
hooks:
|
35 |
- id: yapf
|
36 |
args: ['--parallel', '--in-place']
|
37 |
-
- repo: https://github.com/kynan/nbstripout
|
38 |
-
rev: 0.5.0
|
39 |
-
hooks:
|
40 |
-
- id: nbstripout
|
41 |
-
args: ['--extra-keys', 'metadata.interpreter metadata.kernelspec cell.metadata.pycharm']
|
42 |
-
- repo: https://github.com/nbQA-dev/nbQA
|
43 |
-
rev: 1.3.1
|
44 |
-
hooks:
|
45 |
-
- id: nbqa-isort
|
46 |
-
- id: nbqa-yapf
|
|
|
21 |
- id: docformatter
|
22 |
args: ['--in-place']
|
23 |
- repo: https://github.com/pycqa/isort
|
24 |
+
rev: 5.12.0
|
25 |
hooks:
|
26 |
- id: isort
|
27 |
- repo: https://github.com/pre-commit/mirrors-mypy
|
28 |
+
rev: v0.991
|
29 |
hooks:
|
30 |
- id: mypy
|
31 |
args: ['--ignore-missing-imports']
|
|
|
34 |
hooks:
|
35 |
- id: yapf
|
36 |
args: ['--parallel', '--in-place']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
README.md
CHANGED
@@ -4,7 +4,7 @@ emoji: 🐨
|
|
4 |
colorFrom: red
|
5 |
colorTo: blue
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 3.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
|
|
4 |
colorFrom: red
|
5 |
colorTo: blue
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 3.19.1
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
app.py
CHANGED
@@ -2,31 +2,16 @@
|
|
2 |
|
3 |
from __future__ import annotations
|
4 |
|
5 |
-
import argparse
|
6 |
-
|
7 |
import gradio as gr
|
8 |
import numpy as np
|
9 |
|
10 |
from model import Model
|
11 |
|
12 |
-
TITLE = '
|
13 |
-
DESCRIPTION = '''
|
14 |
|
15 |
-
|
16 |
'''
|
17 |
-
FOOTER = '<img id="visitor-badge" alt="visitor badge" src="https://visitor-badge.glitch.me/badge?page_id=hysts.stylegan3" />'
|
18 |
-
|
19 |
-
|
20 |
-
def parse_args() -> argparse.Namespace:
|
21 |
-
parser = argparse.ArgumentParser()
|
22 |
-
parser.add_argument('--device', type=str, default='cpu')
|
23 |
-
parser.add_argument('--theme', type=str)
|
24 |
-
parser.add_argument('--share', action='store_true')
|
25 |
-
parser.add_argument('--port', type=int)
|
26 |
-
parser.add_argument('--disable-queue',
|
27 |
-
dest='enable_queue',
|
28 |
-
action='store_false')
|
29 |
-
return parser.parse_args()
|
30 |
|
31 |
|
32 |
def get_sample_image_url(name: str) -> str:
|
@@ -45,90 +30,76 @@ def get_sample_image_markdown(name: str) -> str:
|
|
45 |
![sample images]({url})'''
|
46 |
|
47 |
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
gr.
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
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 |
-
outputs=result)
|
122 |
-
model_name2.change(fn=get_sample_image_markdown,
|
123 |
-
inputs=model_name2,
|
124 |
-
outputs=sample_images)
|
125 |
-
|
126 |
-
demo.launch(
|
127 |
-
enable_queue=args.enable_queue,
|
128 |
-
server_port=args.port,
|
129 |
-
share=args.share,
|
130 |
-
)
|
131 |
-
|
132 |
-
|
133 |
-
if __name__ == '__main__':
|
134 |
-
main()
|
|
|
2 |
|
3 |
from __future__ import annotations
|
4 |
|
|
|
|
|
5 |
import gradio as gr
|
6 |
import numpy as np
|
7 |
|
8 |
from model import Model
|
9 |
|
10 |
+
TITLE = ''
|
11 |
+
DESCRIPTION = '''# StyleGAN3
|
12 |
|
13 |
+
This is an unofficial demo for [https://github.com/NVlabs/stylegan3](https://github.com/NVlabs/stylegan3).
|
14 |
'''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
|
17 |
def get_sample_image_url(name: str) -> str:
|
|
|
30 |
![sample images]({url})'''
|
31 |
|
32 |
|
33 |
+
model = Model()
|
34 |
+
|
35 |
+
with gr.Blocks(css='style.css') as demo:
|
36 |
+
gr.Markdown(DESCRIPTION)
|
37 |
+
|
38 |
+
with gr.Tabs():
|
39 |
+
with gr.TabItem('App'):
|
40 |
+
with gr.Row():
|
41 |
+
with gr.Column():
|
42 |
+
model_name = gr.Dropdown(list(
|
43 |
+
model.MODEL_NAME_DICT.keys()),
|
44 |
+
value='FFHQ-1024-R',
|
45 |
+
label='Model')
|
46 |
+
seed = gr.Slider(0,
|
47 |
+
np.iinfo(np.uint32).max,
|
48 |
+
step=1,
|
49 |
+
value=0,
|
50 |
+
label='Seed')
|
51 |
+
psi = gr.Slider(0,
|
52 |
+
2,
|
53 |
+
step=0.05,
|
54 |
+
value=0.7,
|
55 |
+
label='Truncation psi')
|
56 |
+
tx = gr.Slider(-1,
|
57 |
+
1,
|
58 |
+
step=0.05,
|
59 |
+
value=0,
|
60 |
+
label='Translate X')
|
61 |
+
ty = gr.Slider(-1,
|
62 |
+
1,
|
63 |
+
step=0.05,
|
64 |
+
value=0,
|
65 |
+
label='Translate Y')
|
66 |
+
angle = gr.Slider(-180,
|
67 |
+
180,
|
68 |
+
step=5,
|
69 |
+
value=0,
|
70 |
+
label='Angle')
|
71 |
+
run_button = gr.Button('Run')
|
72 |
+
with gr.Column():
|
73 |
+
result = gr.Image(label='Result', elem_id='result')
|
74 |
+
|
75 |
+
with gr.TabItem('Sample Images'):
|
76 |
+
with gr.Row():
|
77 |
+
model_name2 = gr.Dropdown([
|
78 |
+
'afhqv2',
|
79 |
+
'ffhq',
|
80 |
+
'ffhq-u',
|
81 |
+
'metfaces',
|
82 |
+
'metfaces-u',
|
83 |
+
],
|
84 |
+
value='afhqv2',
|
85 |
+
label='Model')
|
86 |
+
with gr.Row():
|
87 |
+
text = get_sample_image_markdown(model_name2.value)
|
88 |
+
sample_images = gr.Markdown(text)
|
89 |
+
|
90 |
+
model_name.change(fn=model.set_model, inputs=model_name, outputs=None)
|
91 |
+
run_button.click(fn=model.set_model_and_generate_image,
|
92 |
+
inputs=[
|
93 |
+
model_name,
|
94 |
+
seed,
|
95 |
+
psi,
|
96 |
+
tx,
|
97 |
+
ty,
|
98 |
+
angle,
|
99 |
+
],
|
100 |
+
outputs=result)
|
101 |
+
model_name2.change(fn=get_sample_image_markdown,
|
102 |
+
inputs=model_name2,
|
103 |
+
outputs=sample_images)
|
104 |
+
|
105 |
+
demo.queue().launch(show_api=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
model.py
CHANGED
@@ -14,7 +14,7 @@ current_dir = pathlib.Path(__file__).parent
|
|
14 |
submodule_dir = current_dir / 'stylegan3'
|
15 |
sys.path.insert(0, submodule_dir.as_posix())
|
16 |
|
17 |
-
HF_TOKEN = os.
|
18 |
|
19 |
|
20 |
class Model:
|
@@ -33,8 +33,9 @@ class Model:
|
|
33 |
'MetFaces-U-1024-T': 'stylegan3-t-metfacesu-1024x1024.pkl',
|
34 |
}
|
35 |
|
36 |
-
def __init__(self
|
37 |
-
self.device = torch.device(
|
|
|
38 |
self._download_all_models()
|
39 |
self.model_name = 'FFHQ-1024-R'
|
40 |
self.model = self._load_model(self.model_name)
|
|
|
14 |
submodule_dir = current_dir / 'stylegan3'
|
15 |
sys.path.insert(0, submodule_dir.as_posix())
|
16 |
|
17 |
+
HF_TOKEN = os.getenv('HF_TOKEN')
|
18 |
|
19 |
|
20 |
class Model:
|
|
|
33 |
'MetFaces-U-1024-T': 'stylegan3-t-metfacesu-1024x1024.pkl',
|
34 |
}
|
35 |
|
36 |
+
def __init__(self):
|
37 |
+
self.device = torch.device(
|
38 |
+
'cuda:0' if torch.cuda.is_available() else 'cpu')
|
39 |
self._download_all_models()
|
40 |
self.model_name = 'FFHQ-1024-R'
|
41 |
self.model = self._load_model(self.model_name)
|