hysts HF staff commited on
Commit
115ddf5
·
1 Parent(s): d9db1f6
.pre-commit-config.yaml CHANGED
@@ -1,6 +1,6 @@
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
@@ -18,13 +18,15 @@ repos:
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"]
@@ -35,14 +37,8 @@ repos:
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:
@@ -51,7 +47,7 @@ repos:
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
 
1
  repos:
2
  - repo: https://github.com/pre-commit/pre-commit-hooks
3
+ rev: v5.0.0
4
  hooks:
5
  - id: check-executables-have-shebangs
6
  - id: check-json
 
18
  hooks:
19
  - id: docformatter
20
  args: ["--in-place"]
21
+ - repo: https://github.com/astral-sh/ruff-pre-commit
22
+ rev: v0.8.4
23
  hooks:
24
+ - id: ruff
25
+ args: ["--fix"]
26
+ - id: ruff-format
27
+ args: ["--line-length", "119"]
28
  - repo: https://github.com/pre-commit/mirrors-mypy
29
+ rev: v1.14.0
30
  hooks:
31
  - id: mypy
32
  args: ["--ignore-missing-imports"]
 
37
  "types-PyYAML",
38
  "types-pytz",
39
  ]
 
 
 
 
 
 
40
  - repo: https://github.com/kynan/nbstripout
41
+ rev: 0.8.1
42
  hooks:
43
  - id: nbstripout
44
  args:
 
47
  "metadata.interpreter metadata.kernelspec cell.metadata.pycharm",
48
  ]
49
  - repo: https://github.com/nbQA-dev/nbQA
50
+ rev: 1.9.1
51
  hooks:
52
  - id: nbqa-black
53
  - id: nbqa-pyupgrade
.python-version ADDED
@@ -0,0 +1 @@
 
 
1
+ 3.10
.vscode/extensions.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "recommendations": [
3
+ "ms-python.python",
4
+ "charliermarsh.ruff",
5
+ "streetsidesoftware.code-spell-checker",
6
+ "tamasfe.even-better-toml"
7
+ ]
8
+ }
.vscode/settings.json CHANGED
@@ -2,29 +2,20 @@
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
  }
 
2
  "editor.formatOnSave": true,
3
  "files.insertFinalNewline": false,
4
  "[python]": {
5
+ "editor.defaultFormatter": "charliermarsh.ruff",
6
  "editor.formatOnType": true,
7
  "editor.codeActionsOnSave": {
8
+ "source.fixAll.ruff": "explicit",
9
  "source.organizeImports": "explicit"
10
  }
11
  },
12
  "[jupyter]": {
13
  "files.insertFinalNewline": false
14
  },
 
 
 
 
 
 
 
 
 
 
15
  "notebook.output.scrolling": true,
16
  "notebook.formatOnCellExecution": true,
17
  "notebook.formatOnSave.enabled": true,
18
+ "notebook.codeActionsOnSave": {
19
+ "source.organizeImports": "explicit"
20
+ }
21
  }
README.md CHANGED
@@ -4,7 +4,7 @@ emoji: 👀
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
 
4
  colorFrom: blue
5
  colorTo: purple
6
  sdk: gradio
7
+ sdk_version: 5.9.1
8
  app_file: app.py
9
  pinned: false
10
  license: cc-by-nc-sa-4.0
app.py CHANGED
@@ -1,7 +1,5 @@
1
  #!/usr/bin/env python
2
 
3
- from __future__ import annotations
4
-
5
  import os
6
  import pathlib
7
  import shlex
@@ -24,20 +22,24 @@ 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()
 
 
 
1
  #!/usr/bin/env python
2
 
 
 
3
  import os
4
  import pathlib
5
  import shlex
 
22
  MODEL_DIR = pathlib.Path("DDNM/hq_demo/data/pretrained")
23
  if not MODEL_DIR.exists():
24
  MODEL_DIR.mkdir()
25
+ subprocess.run( # noqa: S603
26
  shlex.split("wget https://openaipublic.blob.core.windows.net/diffusion/jul-2021/256x256_classifier.pt"),
27
  cwd=MODEL_DIR.as_posix(),
28
+ check=False,
29
  )
30
+ subprocess.run( # noqa: S603
31
  shlex.split("wget https://openaipublic.blob.core.windows.net/diffusion/jul-2021/256x256_diffusion.pt"),
32
  cwd=MODEL_DIR.as_posix(),
33
+ check=False,
34
  )
35
 
36
+ with gr.Blocks(css_paths="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
+
44
+ if __name__ == "__main__":
45
+ demo.queue(api_open=False, max_size=5).launch()
app_colorization.py CHANGED
@@ -1,8 +1,7 @@
1
  #!/usr/bin/env python
2
 
3
- from __future__ import annotations
4
-
5
  import json
 
6
  import shlex
7
  import subprocess
8
 
@@ -11,16 +10,17 @@ import gradio as gr
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",
@@ -34,7 +34,7 @@ def create_demo():
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:
 
1
  #!/usr/bin/env python
2
 
 
 
3
  import json
4
+ import pathlib
5
  import shlex
6
  import subprocess
7
 
 
10
 
11
  def run(image_path: str, class_index: int, sigma_y: float) -> str:
12
  out_name = image_path.split("/")[-1].split(".")[0]
13
+ subprocess.run( # noqa: S603
14
  shlex.split(
15
  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}"
16
  ),
17
  cwd="DDNM/hq_demo",
18
+ check=False,
19
  )
20
  return f"DDNM/hq_demo/results/{out_name}/final/00000.png"
21
 
22
 
23
+ def create_demo() -> gr.Blocks:
24
  examples = [
25
  [
26
  "sample_images/monarch_gray.png",
 
34
  ],
35
  ]
36
 
37
+ with pathlib.Path("imagenet_classes.json").open() as f:
38
  imagenet_class_names = json.load(f)
39
 
40
  with gr.Blocks() as demo:
app_superresolution.py CHANGED
@@ -1,8 +1,7 @@
1
  #!/usr/bin/env python
2
 
3
- from __future__ import annotations
4
-
5
  import json
 
6
  import shlex
7
  import subprocess
8
 
@@ -11,16 +10,17 @@ import gradio as gr
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",
@@ -66,7 +66,7 @@ def create_demo():
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:
 
1
  #!/usr/bin/env python
2
 
 
 
3
  import json
4
+ import pathlib
5
  import shlex
6
  import subprocess
7
 
 
10
 
11
  def run(image_path: str, class_index: int, scale: str, sigma_y: float) -> str:
12
  out_name = image_path.split("/")[-1].split(".")[0]
13
+ subprocess.run( # noqa: S603
14
  shlex.split(
15
  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}"
16
  ),
17
  cwd="DDNM/hq_demo",
18
+ check=False,
19
  )
20
  return f"DDNM/hq_demo/results/{out_name}/final/00000.png"
21
 
22
 
23
+ def create_demo() -> gr.Blocks:
24
  examples = [
25
  [
26
  "DDNM/hq_demo/data/datasets/gts/inet256/323.png",
 
66
  ],
67
  ]
68
 
69
+ with pathlib.Path("imagenet_classes.json").open() as f:
70
  imagenet_class_names = json.load(f)
71
 
72
  with gr.Blocks() as demo:
pyproject.toml ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [project]
2
+ name = "ddnm-hq"
3
+ version = "0.1.0"
4
+ description = ""
5
+ readme = "README.md"
6
+ requires-python = ">=3.10"
7
+ dependencies = [
8
+ "blobfile>=3.0.0",
9
+ "gradio>=5.9.1",
10
+ "torch==1.13.1",
11
+ "torchvision>=0.14.1",
12
+ ]
13
+
14
+ [tool.ruff]
15
+ line-length = 119
16
+
17
+ [tool.ruff.lint]
18
+ select = ["ALL"]
19
+ ignore = [
20
+ "COM812", # missing-trailing-comma
21
+ "D203", # one-blank-line-before-class
22
+ "D213", # multi-line-summary-second-line
23
+ "E501", # line-too-long
24
+ "SIM117", # multiple-with-statements
25
+ ]
26
+ extend-ignore = [
27
+ "D100", # undocumented-public-module
28
+ "D101", # undocumented-public-class
29
+ "D102", # undocumented-public-method
30
+ "D103", # undocumented-public-function
31
+ "D104", # undocumented-public-package
32
+ "D105", # undocumented-magic-method
33
+ "D107", # undocumented-public-init
34
+ "EM101", # raw-string-in-exception
35
+ "FBT001", # boolean-type-hint-positional-argument
36
+ "FBT002", # boolean-default-value-positional-argument
37
+ "PD901", # pandas-df-variable-name
38
+ "PGH003", # blanket-type-ignore
39
+ "PLR0913", # too-many-arguments
40
+ "PLR0915", # too-many-statements
41
+ "TRY003", # raise-vanilla-args
42
+ ]
43
+ unfixable = [
44
+ "F401", # unused-import
45
+ ]
46
+
47
+ [tool.ruff.format]
48
+ docstring-code-format = true
requirements.txt CHANGED
@@ -1,7 +1,190 @@
1
- blobfile==2.0.1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  numpy==1.24.2
3
- Pillow==9.5.0
4
- PyYAML==6.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  torch==1.13.1
 
 
 
6
  torchvision==0.14.1
 
7
  tqdm==4.65.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file was autogenerated by uv via the following command:
2
+ # uv pip compile pyproject.toml -o requirements.txt
3
+ aiofiles==23.2.1
4
+ # via gradio
5
+ annotated-types==0.7.0
6
+ # via pydantic
7
+ anyio==4.7.0
8
+ # via
9
+ # gradio
10
+ # httpx
11
+ # starlette
12
+ blobfile==3.0.0
13
+ # via ddnm-hq (pyproject.toml)
14
+ certifi==2024.12.14
15
+ # via
16
+ # httpcore
17
+ # httpx
18
+ # requests
19
+ charset-normalizer==3.4.1
20
+ # via requests
21
+ click==8.1.8
22
+ # via
23
+ # typer
24
+ # uvicorn
25
+ exceptiongroup==1.2.2
26
+ # via anyio
27
+ fastapi==0.115.6
28
+ # via gradio
29
+ ffmpy==0.5.0
30
+ # via gradio
31
+ filelock==3.16.1
32
+ # via
33
+ # blobfile
34
+ # huggingface-hub
35
+ fsspec==2024.12.0
36
+ # via
37
+ # gradio-client
38
+ # huggingface-hub
39
+ gradio==5.9.1
40
+ # via ddnm-hq (pyproject.toml)
41
+ gradio-client==1.5.2
42
+ # via gradio
43
+ h11==0.14.0
44
+ # via
45
+ # httpcore
46
+ # uvicorn
47
+ httpcore==1.0.7
48
+ # via httpx
49
+ httpx==0.28.1
50
+ # via
51
+ # gradio
52
+ # gradio-client
53
+ # safehttpx
54
+ huggingface-hub==0.27.0
55
+ # via
56
+ # gradio
57
+ # gradio-client
58
+ idna==3.10
59
+ # via
60
+ # anyio
61
+ # httpx
62
+ # requests
63
+ jinja2==3.1.5
64
+ # via gradio
65
+ lxml==5.3.0
66
+ # via blobfile
67
+ markdown-it-py==3.0.0
68
+ # via rich
69
+ markupsafe==2.1.5
70
+ # via
71
+ # gradio
72
+ # jinja2
73
+ mdurl==0.1.2
74
+ # via markdown-it-py
75
  numpy==1.24.2
76
+ # via
77
+ # gradio
78
+ # pandas
79
+ # torchvision
80
+ nvidia-cublas-cu11==11.10.3.66
81
+ # via
82
+ # nvidia-cudnn-cu11
83
+ # torch
84
+ nvidia-cuda-nvrtc-cu11==11.7.99
85
+ # via torch
86
+ nvidia-cuda-runtime-cu11==11.7.99
87
+ # via torch
88
+ nvidia-cudnn-cu11==8.5.0.96
89
+ # via torch
90
+ orjson==3.10.13
91
+ # via gradio
92
+ packaging==24.2
93
+ # via
94
+ # gradio
95
+ # gradio-client
96
+ # huggingface-hub
97
+ pandas==2.2.3
98
+ # via gradio
99
+ pillow==9.5.0
100
+ # via
101
+ # gradio
102
+ # torchvision
103
+ pycryptodomex==3.21.0
104
+ # via blobfile
105
+ pydantic==2.10.4
106
+ # via
107
+ # fastapi
108
+ # gradio
109
+ pydantic-core==2.27.2
110
+ # via pydantic
111
+ pydub==0.25.1
112
+ # via gradio
113
+ pygments==2.18.0
114
+ # via rich
115
+ python-dateutil==2.9.0.post0
116
+ # via pandas
117
+ python-multipart==0.0.20
118
+ # via gradio
119
+ pytz==2024.2
120
+ # via pandas
121
+ pyyaml==6.0
122
+ # via
123
+ # gradio
124
+ # huggingface-hub
125
+ requests==2.32.3
126
+ # via
127
+ # huggingface-hub
128
+ # torchvision
129
+ rich==13.9.4
130
+ # via typer
131
+ ruff==0.8.4
132
+ # via gradio
133
+ safehttpx==0.1.6
134
+ # via gradio
135
+ semantic-version==2.10.0
136
+ # via gradio
137
+ setuptools==75.6.0
138
+ # via
139
+ # nvidia-cublas-cu11
140
+ # nvidia-cuda-runtime-cu11
141
+ shellingham==1.5.4
142
+ # via typer
143
+ six==1.17.0
144
+ # via python-dateutil
145
+ sniffio==1.3.1
146
+ # via anyio
147
+ starlette==0.41.3
148
+ # via
149
+ # fastapi
150
+ # gradio
151
+ tomlkit==0.13.2
152
+ # via gradio
153
  torch==1.13.1
154
+ # via
155
+ # ddnm-hq (pyproject.toml)
156
+ # torchvision
157
  torchvision==0.14.1
158
+ # via ddnm-hq (pyproject.toml)
159
  tqdm==4.65.0
160
+ # via huggingface-hub
161
+ typer==0.15.1
162
+ # via gradio
163
+ typing-extensions==4.12.2
164
+ # via
165
+ # anyio
166
+ # fastapi
167
+ # gradio
168
+ # gradio-client
169
+ # huggingface-hub
170
+ # pydantic
171
+ # pydantic-core
172
+ # rich
173
+ # torch
174
+ # torchvision
175
+ # typer
176
+ # uvicorn
177
+ tzdata==2024.2
178
+ # via pandas
179
+ urllib3==2.3.0
180
+ # via
181
+ # blobfile
182
+ # requests
183
+ uvicorn==0.34.0
184
+ # via gradio
185
+ websockets==14.1
186
+ # via gradio-client
187
+ wheel==0.45.1
188
+ # via
189
+ # nvidia-cublas-cu11
190
+ # nvidia-cuda-runtime-cu11
uv.lock ADDED
The diff for this file is too large to render. See raw diff