Update
Browse files- .pre-commit-config.yaml +59 -35
- .style.yapf +0 -5
- .vscode/settings.json +30 -0
- README.md +1 -2
- app.py +16 -16
- app_colorization.py +18 -19
- app_superresolution.py +36 -39
- style.css +1 -0
.pre-commit-config.yaml
CHANGED
@@ -1,36 +1,60 @@
|
|
1 |
repos:
|
2 |
-
- repo: https://github.com/pre-commit/pre-commit-hooks
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
- repo: https://github.com/pre-commit/mirrors-mypy
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
repos:
|
2 |
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
3 |
+
rev: v4.6.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: end-of-file-fixer
|
12 |
+
- id: mixed-line-ending
|
13 |
+
args: ["--fix=lf"]
|
14 |
+
- id: requirements-txt-fixer
|
15 |
+
- id: trailing-whitespace
|
16 |
+
- repo: https://github.com/myint/docformatter
|
17 |
+
rev: v1.7.5
|
18 |
+
hooks:
|
19 |
+
- id: docformatter
|
20 |
+
args: ["--in-place"]
|
21 |
+
- repo: https://github.com/pycqa/isort
|
22 |
+
rev: 5.13.2
|
23 |
+
hooks:
|
24 |
+
- id: isort
|
25 |
+
args: ["--profile", "black"]
|
26 |
+
- repo: https://github.com/pre-commit/mirrors-mypy
|
27 |
+
rev: v1.10.0
|
28 |
+
hooks:
|
29 |
+
- id: mypy
|
30 |
+
args: ["--ignore-missing-imports"]
|
31 |
+
additional_dependencies:
|
32 |
+
[
|
33 |
+
"types-python-slugify",
|
34 |
+
"types-requests",
|
35 |
+
"types-PyYAML",
|
36 |
+
"types-pytz",
|
37 |
+
]
|
38 |
+
- repo: https://github.com/psf/black
|
39 |
+
rev: 24.4.2
|
40 |
+
hooks:
|
41 |
+
- id: black
|
42 |
+
language_version: python3.10
|
43 |
+
args: ["--line-length", "119"]
|
44 |
+
- repo: https://github.com/kynan/nbstripout
|
45 |
+
rev: 0.7.1
|
46 |
+
hooks:
|
47 |
+
- id: nbstripout
|
48 |
+
args:
|
49 |
+
[
|
50 |
+
"--extra-keys",
|
51 |
+
"metadata.interpreter metadata.kernelspec cell.metadata.pycharm",
|
52 |
+
]
|
53 |
+
- repo: https://github.com/nbQA-dev/nbQA
|
54 |
+
rev: 1.8.5
|
55 |
+
hooks:
|
56 |
+
- id: nbqa-black
|
57 |
+
- id: nbqa-pyupgrade
|
58 |
+
args: ["--py37-plus"]
|
59 |
+
- id: nbqa-isort
|
60 |
+
args: ["--float-to-top"]
|
.style.yapf
DELETED
@@ -1,5 +0,0 @@
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
.vscode/settings.json
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"editor.formatOnSave": true,
|
3 |
+
"files.insertFinalNewline": false,
|
4 |
+
"[python]": {
|
5 |
+
"editor.defaultFormatter": "ms-python.black-formatter",
|
6 |
+
"editor.formatOnType": true,
|
7 |
+
"editor.codeActionsOnSave": {
|
8 |
+
"source.organizeImports": "explicit"
|
9 |
+
}
|
10 |
+
},
|
11 |
+
"[jupyter]": {
|
12 |
+
"files.insertFinalNewline": false
|
13 |
+
},
|
14 |
+
"black-formatter.args": [
|
15 |
+
"--line-length=119"
|
16 |
+
],
|
17 |
+
"isort.args": ["--profile", "black"],
|
18 |
+
"flake8.args": [
|
19 |
+
"--max-line-length=119"
|
20 |
+
],
|
21 |
+
"ruff.lint.args": [
|
22 |
+
"--line-length=119"
|
23 |
+
],
|
24 |
+
"notebook.output.scrolling": true,
|
25 |
+
"notebook.formatOnCellExecution": true,
|
26 |
+
"notebook.formatOnSave.enabled": true,
|
27 |
+
"notebook.codeActionsOnSave": {
|
28 |
+
"source.organizeImports": "explicit"
|
29 |
+
}
|
30 |
+
}
|
README.md
CHANGED
@@ -4,8 +4,7 @@ emoji: 👀
|
|
4 |
colorFrom: blue
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
7 |
-
sdk_version:
|
8 |
-
python_version: 3.10.11
|
9 |
app_file: app.py
|
10 |
pinned: false
|
11 |
license: cc-by-nc-sa-4.0
|
|
|
4 |
colorFrom: blue
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 4.36.1
|
|
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: cc-by-nc-sa-4.0
|
app.py
CHANGED
@@ -13,31 +13,31 @@ import torch
|
|
13 |
from app_colorization import create_demo as create_demo_colorization
|
14 |
from app_superresolution import create_demo as create_demo_superresolution
|
15 |
|
16 |
-
DESCRIPTION =
|
17 |
|
18 |
-
if (SPACE_ID := os.getenv(
|
19 |
DESCRIPTION += f'\n<p>For faster inference without waiting in queue, you may duplicate the space and upgrade to GPU in settings. <a href="https://huggingface.co/spaces/{SPACE_ID}?duplicate=true"><img style="display: inline; margin-top: 0em; margin-bottom: 0em" src="https://bit.ly/3gLdBN6" alt="Duplicate Space" /></a></p>'
|
20 |
if not torch.cuda.is_available():
|
21 |
-
DESCRIPTION +=
|
22 |
|
23 |
if torch.cuda.is_available():
|
24 |
-
MODEL_DIR = pathlib.Path(
|
25 |
if not MODEL_DIR.exists():
|
26 |
MODEL_DIR.mkdir()
|
27 |
-
subprocess.run(
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
subprocess.run(
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
with gr.Blocks(css=
|
37 |
gr.Markdown(DESCRIPTION)
|
38 |
with gr.Tabs():
|
39 |
-
with gr.TabItem(label=
|
40 |
create_demo_superresolution()
|
41 |
-
with gr.TabItem(label=
|
42 |
create_demo_colorization()
|
43 |
demo.queue(api_open=False, max_size=5).launch()
|
|
|
13 |
from app_colorization import create_demo as create_demo_colorization
|
14 |
from app_superresolution import create_demo as create_demo_superresolution
|
15 |
|
16 |
+
DESCRIPTION = "# [DDNM-HQ](https://github.com/wyhuai/DDNM/tree/main/hq_demo)"
|
17 |
|
18 |
+
if (SPACE_ID := os.getenv("SPACE_ID")) is not None:
|
19 |
DESCRIPTION += f'\n<p>For faster inference without waiting in queue, you may duplicate the space and upgrade to GPU in settings. <a href="https://huggingface.co/spaces/{SPACE_ID}?duplicate=true"><img style="display: inline; margin-top: 0em; margin-bottom: 0em" src="https://bit.ly/3gLdBN6" alt="Duplicate Space" /></a></p>'
|
20 |
if not torch.cuda.is_available():
|
21 |
+
DESCRIPTION += "\n<p>Running on CPU 🥶 This demo does not work on CPU.</p>"
|
22 |
|
23 |
if torch.cuda.is_available():
|
24 |
+
MODEL_DIR = pathlib.Path("DDNM/hq_demo/data/pretrained")
|
25 |
if not MODEL_DIR.exists():
|
26 |
MODEL_DIR.mkdir()
|
27 |
+
subprocess.run(
|
28 |
+
shlex.split("wget https://openaipublic.blob.core.windows.net/diffusion/jul-2021/256x256_classifier.pt"),
|
29 |
+
cwd=MODEL_DIR.as_posix(),
|
30 |
+
)
|
31 |
+
subprocess.run(
|
32 |
+
shlex.split("wget https://openaipublic.blob.core.windows.net/diffusion/jul-2021/256x256_diffusion.pt"),
|
33 |
+
cwd=MODEL_DIR.as_posix(),
|
34 |
+
)
|
35 |
+
|
36 |
+
with gr.Blocks(css="style.css") as demo:
|
37 |
gr.Markdown(DESCRIPTION)
|
38 |
with gr.Tabs():
|
39 |
+
with gr.TabItem(label="Super-resolution"):
|
40 |
create_demo_superresolution()
|
41 |
+
with gr.TabItem(label="Colorization"):
|
42 |
create_demo_colorization()
|
43 |
demo.queue(api_open=False, max_size=5).launch()
|
app_colorization.py
CHANGED
@@ -10,43 +10,42 @@ import gradio as gr
|
|
10 |
|
11 |
|
12 |
def run(image_path: str, class_index: int, sigma_y: float) -> str:
|
13 |
-
out_name = image_path.split(
|
14 |
-
subprocess.run(
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
19 |
|
20 |
|
21 |
def create_demo():
|
22 |
examples = [
|
23 |
[
|
24 |
-
|
25 |
-
|
26 |
0,
|
27 |
],
|
28 |
[
|
29 |
-
|
30 |
-
|
31 |
0,
|
32 |
],
|
33 |
]
|
34 |
|
35 |
-
with open(
|
36 |
imagenet_class_names = json.load(f)
|
37 |
|
38 |
with gr.Blocks() as demo:
|
39 |
with gr.Row():
|
40 |
with gr.Column():
|
41 |
-
image = gr.Image(label=
|
42 |
-
class_index = gr.Dropdown(label=
|
43 |
-
|
44 |
-
|
45 |
-
value=950)
|
46 |
-
sigma_y = gr.Number(label='sigma_y', value=0, precision=2)
|
47 |
-
run_button = gr.Button('Run')
|
48 |
with gr.Column():
|
49 |
-
result = gr.Image(label=
|
50 |
|
51 |
gr.Examples(
|
52 |
examples=examples,
|
|
|
10 |
|
11 |
|
12 |
def run(image_path: str, class_index: int, sigma_y: float) -> str:
|
13 |
+
out_name = image_path.split("/")[-1].split(".")[0]
|
14 |
+
subprocess.run(
|
15 |
+
shlex.split(
|
16 |
+
f"python main.py --config confs/inet256.yml --deg colorization --scale 1 --class {class_index} --path_y {image_path} --save_path {out_name} --sigma_y {sigma_y}"
|
17 |
+
),
|
18 |
+
cwd="DDNM/hq_demo",
|
19 |
+
)
|
20 |
+
return f"DDNM/hq_demo/results/{out_name}/final/00000.png"
|
21 |
|
22 |
|
23 |
def create_demo():
|
24 |
examples = [
|
25 |
[
|
26 |
+
"sample_images/monarch_gray.png",
|
27 |
+
"monarch, monarch butterfly, milkweed butterfly, Danaus plexippus",
|
28 |
0,
|
29 |
],
|
30 |
[
|
31 |
+
"sample_images/tiger_gray.png",
|
32 |
+
"tiger, Panthera tigris",
|
33 |
0,
|
34 |
],
|
35 |
]
|
36 |
|
37 |
+
with open("imagenet_classes.json") as f:
|
38 |
imagenet_class_names = json.load(f)
|
39 |
|
40 |
with gr.Blocks() as demo:
|
41 |
with gr.Row():
|
42 |
with gr.Column():
|
43 |
+
image = gr.Image(label="Input image", type="filepath")
|
44 |
+
class_index = gr.Dropdown(label="Class name", choices=imagenet_class_names, type="index", value=950)
|
45 |
+
sigma_y = gr.Number(label="sigma_y", value=0, precision=2)
|
46 |
+
run_button = gr.Button("Run")
|
|
|
|
|
|
|
47 |
with gr.Column():
|
48 |
+
result = gr.Image(label="Result", type="filepath")
|
49 |
|
50 |
gr.Examples(
|
51 |
examples=examples,
|
app_superresolution.py
CHANGED
@@ -10,78 +10,75 @@ import gradio as gr
|
|
10 |
|
11 |
|
12 |
def run(image_path: str, class_index: int, scale: str, sigma_y: float) -> str:
|
13 |
-
out_name = image_path.split(
|
14 |
-
subprocess.run(
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
19 |
|
20 |
|
21 |
def create_demo():
|
22 |
examples = [
|
23 |
[
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
0,
|
28 |
],
|
29 |
[
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
0,
|
34 |
],
|
35 |
[
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
0.5,
|
40 |
],
|
41 |
[
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
0,
|
46 |
],
|
47 |
[
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
0,
|
52 |
],
|
53 |
[
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
0,
|
58 |
],
|
59 |
[
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
0,
|
64 |
],
|
65 |
]
|
66 |
|
67 |
-
with open(
|
68 |
imagenet_class_names = json.load(f)
|
69 |
|
70 |
with gr.Blocks() as demo:
|
71 |
with gr.Row():
|
72 |
with gr.Column():
|
73 |
-
image = gr.Image(label=
|
74 |
-
class_index = gr.Dropdown(label=
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
scale = gr.Dropdown(label='Scale',
|
79 |
-
choices=['2', '4', '8'],
|
80 |
-
value='4')
|
81 |
-
sigma_y = gr.Number(label='sigma_y', value=0, precision=2)
|
82 |
-
run_button = gr.Button('Run')
|
83 |
with gr.Column():
|
84 |
-
result = gr.Image(label=
|
85 |
|
86 |
gr.Examples(
|
87 |
examples=examples,
|
|
|
10 |
|
11 |
|
12 |
def run(image_path: str, class_index: int, scale: str, sigma_y: float) -> str:
|
13 |
+
out_name = image_path.split("/")[-1].split(".")[0]
|
14 |
+
subprocess.run(
|
15 |
+
shlex.split(
|
16 |
+
f"python main.py --config confs/inet256.yml --resize_y --deg sr_averagepooling --scale {scale} --class {class_index} --path_y {image_path} --save_path {out_name} --sigma_y {sigma_y}"
|
17 |
+
),
|
18 |
+
cwd="DDNM/hq_demo",
|
19 |
+
)
|
20 |
+
return f"DDNM/hq_demo/results/{out_name}/final/00000.png"
|
21 |
|
22 |
|
23 |
def create_demo():
|
24 |
examples = [
|
25 |
[
|
26 |
+
"DDNM/hq_demo/data/datasets/gts/inet256/323.png",
|
27 |
+
"monarch, monarch butterfly, milkweed butterfly, Danaus plexippus",
|
28 |
+
"4",
|
29 |
0,
|
30 |
],
|
31 |
[
|
32 |
+
"DDNM/hq_demo/data/datasets/gts/inet256/orange.png",
|
33 |
+
"orange",
|
34 |
+
"4",
|
35 |
0,
|
36 |
],
|
37 |
[
|
38 |
+
"DDNM/hq_demo/data/datasets/gts/inet256/monarch.png",
|
39 |
+
"monarch, monarch butterfly, milkweed butterfly, Danaus plexippus",
|
40 |
+
"4",
|
41 |
0.5,
|
42 |
],
|
43 |
[
|
44 |
+
"DDNM/hq_demo/data/datasets/gts/inet256/bear.png",
|
45 |
+
"brown bear, bruin, Ursus arctos",
|
46 |
+
"4",
|
47 |
0,
|
48 |
],
|
49 |
[
|
50 |
+
"DDNM/hq_demo/data/datasets/gts/inet256/flamingo.png",
|
51 |
+
"flamingo",
|
52 |
+
"2",
|
53 |
0,
|
54 |
],
|
55 |
[
|
56 |
+
"DDNM/hq_demo/data/datasets/gts/inet256/kimono.png",
|
57 |
+
"kimono",
|
58 |
+
"2",
|
59 |
0,
|
60 |
],
|
61 |
[
|
62 |
+
"DDNM/hq_demo/data/datasets/gts/inet256/zebra.png",
|
63 |
+
"zebra",
|
64 |
+
"4",
|
65 |
0,
|
66 |
],
|
67 |
]
|
68 |
|
69 |
+
with open("imagenet_classes.json") as f:
|
70 |
imagenet_class_names = json.load(f)
|
71 |
|
72 |
with gr.Blocks() as demo:
|
73 |
with gr.Row():
|
74 |
with gr.Column():
|
75 |
+
image = gr.Image(label="Input image", type="filepath")
|
76 |
+
class_index = gr.Dropdown(label="Class name", choices=imagenet_class_names, type="index", value=950)
|
77 |
+
scale = gr.Dropdown(label="Scale", choices=["2", "4", "8"], value="4")
|
78 |
+
sigma_y = gr.Number(label="sigma_y", value=0, precision=2)
|
79 |
+
run_button = gr.Button("Run")
|
|
|
|
|
|
|
|
|
|
|
80 |
with gr.Column():
|
81 |
+
result = gr.Image(label="Result", type="filepath")
|
82 |
|
83 |
gr.Examples(
|
84 |
examples=examples,
|
style.css
CHANGED
@@ -1,3 +1,4 @@
|
|
1 |
h1 {
|
2 |
text-align: center;
|
|
|
3 |
}
|
|
|
1 |
h1 {
|
2 |
text-align: center;
|
3 |
+
display: block;
|
4 |
}
|