Pierre Chapuis commited on
Commit
08db796
1 Parent(s): e678d7d

add Rye config for local development + linting

Browse files
Files changed (5) hide show
  1. .gitignore +2 -0
  2. .python-version +1 -0
  3. pyproject.toml +54 -0
  4. requirements.lock +231 -0
  5. src/app.py +17 -10
.gitignore CHANGED
@@ -163,3 +163,5 @@ cython_debug/
163
  # and can be added to the global gitignore or merged into this file. For a more nuclear
164
  # option (not recommended) you can uncomment the following to ignore the entire idea folder.
165
  #.idea/
 
 
 
163
  # and can be added to the global gitignore or merged into this file. For a more nuclear
164
  # option (not recommended) you can uncomment the following to ignore the entire idea folder.
165
  #.idea/
166
+
167
+ requirements-dev.lock
.python-version ADDED
@@ -0,0 +1 @@
 
 
1
+ 3.12.2
pyproject.toml ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [project]
2
+ name = "enhancer"
3
+ version = "0.1.0"
4
+ description = "Finegrain Image Enhancer"
5
+ authors = [
6
+ { name = "Laurent Fainsin", email = "laurent@lagon.tech" }
7
+ ]
8
+ dependencies = [
9
+ "gradio>=4.42.0",
10
+ "pillow>=10.4.0",
11
+ "gradio-imageslider>=0.0.20",
12
+ "pillow-heif>=0.18.0",
13
+ "refiners @ git+https://github.com/finegrain-ai/refiners",
14
+ "spaces>=0.29.3",
15
+ "numpy<2.0.0",
16
+ ]
17
+ readme = "README.md"
18
+ requires-python = ">= 3.12, <3.13"
19
+
20
+ [build-system]
21
+ requires = ["hatchling"]
22
+ build-backend = "hatchling.build"
23
+
24
+ [tool.rye]
25
+ managed = true
26
+ dev-dependencies = []
27
+
28
+ [tool.hatch.metadata]
29
+ allow-direct-references = true
30
+
31
+ [tool.hatch.build.targets.wheel]
32
+ packages = ["src/enhancer"]
33
+
34
+ [tool.ruff]
35
+ src = ["src"] # https://docs.astral.sh/ruff/settings/#src
36
+ exclude = ["esrgan_model.py"]
37
+ line-length = 120
38
+ target-version = "py312"
39
+
40
+ [tool.ruff.lint]
41
+ select = [
42
+ "E", # pycodestyle errors
43
+ "W", # pycodestyle warnings
44
+ "F", # pyflakes
45
+ "UP", # pyupgrade
46
+ "A", # flake8-builtins
47
+ "B", # flake8-bugbear
48
+ "Q", # flake8-quotes
49
+ "I", # isort
50
+ ]
51
+
52
+ [tool.pyright]
53
+ include = ["src"]
54
+ exclude = ["**/__pycache__"]
requirements.lock ADDED
@@ -0,0 +1,231 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # generated by rye
2
+ # use `rye lock` or `rye sync` to update this lockfile
3
+ #
4
+ # last locked with the following flags:
5
+ # pre: false
6
+ # features: []
7
+ # all-features: false
8
+ # with-sources: false
9
+ # generate-hashes: false
10
+ # universal: false
11
+
12
+ -e file:.
13
+ aiofiles==23.2.1
14
+ # via gradio
15
+ annotated-types==0.7.0
16
+ # via pydantic
17
+ anyio==4.4.0
18
+ # via gradio
19
+ # via httpx
20
+ # via starlette
21
+ certifi==2024.8.30
22
+ # via httpcore
23
+ # via httpx
24
+ # via requests
25
+ charset-normalizer==3.3.2
26
+ # via requests
27
+ click==8.1.7
28
+ # via typer
29
+ # via uvicorn
30
+ contourpy==1.3.0
31
+ # via matplotlib
32
+ cycler==0.12.1
33
+ # via matplotlib
34
+ fastapi==0.113.0
35
+ # via gradio
36
+ ffmpy==0.4.0
37
+ # via gradio
38
+ filelock==3.15.4
39
+ # via huggingface-hub
40
+ # via torch
41
+ # via triton
42
+ fonttools==4.53.1
43
+ # via matplotlib
44
+ fsspec==2024.9.0
45
+ # via gradio-client
46
+ # via huggingface-hub
47
+ # via torch
48
+ gradio==4.42.0
49
+ # via enhancer
50
+ # via gradio-imageslider
51
+ # via spaces
52
+ gradio-client==1.3.0
53
+ # via gradio
54
+ gradio-imageslider==0.0.20
55
+ # via enhancer
56
+ h11==0.14.0
57
+ # via httpcore
58
+ # via uvicorn
59
+ httpcore==1.0.5
60
+ # via httpx
61
+ httpx==0.27.2
62
+ # via gradio
63
+ # via gradio-client
64
+ # via spaces
65
+ huggingface-hub==0.24.6
66
+ # via gradio
67
+ # via gradio-client
68
+ idna==3.8
69
+ # via anyio
70
+ # via httpx
71
+ # via requests
72
+ importlib-resources==6.4.4
73
+ # via gradio
74
+ jaxtyping==0.2.34
75
+ # via refiners
76
+ jinja2==3.1.4
77
+ # via gradio
78
+ # via torch
79
+ kiwisolver==1.4.7
80
+ # via matplotlib
81
+ markdown-it-py==3.0.0
82
+ # via rich
83
+ markupsafe==2.1.5
84
+ # via gradio
85
+ # via jinja2
86
+ matplotlib==3.9.2
87
+ # via gradio
88
+ mdurl==0.1.2
89
+ # via markdown-it-py
90
+ mpmath==1.3.0
91
+ # via sympy
92
+ networkx==3.3
93
+ # via torch
94
+ numpy==1.26.4
95
+ # via contourpy
96
+ # via enhancer
97
+ # via gradio
98
+ # via matplotlib
99
+ # via pandas
100
+ # via refiners
101
+ nvidia-cublas-cu12==12.1.3.1
102
+ # via nvidia-cudnn-cu12
103
+ # via nvidia-cusolver-cu12
104
+ # via torch
105
+ nvidia-cuda-cupti-cu12==12.1.105
106
+ # via torch
107
+ nvidia-cuda-nvrtc-cu12==12.1.105
108
+ # via torch
109
+ nvidia-cuda-runtime-cu12==12.1.105
110
+ # via torch
111
+ nvidia-cudnn-cu12==9.1.0.70
112
+ # via torch
113
+ nvidia-cufft-cu12==11.0.2.54
114
+ # via torch
115
+ nvidia-curand-cu12==10.3.2.106
116
+ # via torch
117
+ nvidia-cusolver-cu12==11.4.5.107
118
+ # via torch
119
+ nvidia-cusparse-cu12==12.1.0.106
120
+ # via nvidia-cusolver-cu12
121
+ # via torch
122
+ nvidia-nccl-cu12==2.20.5
123
+ # via torch
124
+ nvidia-nvjitlink-cu12==12.6.68
125
+ # via nvidia-cusolver-cu12
126
+ # via nvidia-cusparse-cu12
127
+ nvidia-nvtx-cu12==12.1.105
128
+ # via torch
129
+ orjson==3.10.7
130
+ # via gradio
131
+ packaging==24.1
132
+ # via gradio
133
+ # via gradio-client
134
+ # via huggingface-hub
135
+ # via matplotlib
136
+ # via refiners
137
+ # via spaces
138
+ pandas==2.2.2
139
+ # via gradio
140
+ pillow==10.4.0
141
+ # via enhancer
142
+ # via gradio
143
+ # via gradio-imageslider
144
+ # via matplotlib
145
+ # via pillow-heif
146
+ # via refiners
147
+ pillow-heif==0.18.0
148
+ # via enhancer
149
+ psutil==5.9.8
150
+ # via spaces
151
+ pydantic==2.8.2
152
+ # via fastapi
153
+ # via gradio
154
+ # via spaces
155
+ pydantic-core==2.20.1
156
+ # via pydantic
157
+ pydub==0.25.1
158
+ # via gradio
159
+ pygments==2.18.0
160
+ # via rich
161
+ pyparsing==3.1.4
162
+ # via matplotlib
163
+ python-dateutil==2.9.0.post0
164
+ # via matplotlib
165
+ # via pandas
166
+ python-multipart==0.0.9
167
+ # via gradio
168
+ pytz==2024.1
169
+ # via pandas
170
+ pyyaml==6.0.2
171
+ # via gradio
172
+ # via huggingface-hub
173
+ refiners @ git+https://github.com/finegrain-ai/refiners@cf247a1b20609479565618f49bf70c8aa65a7cfd
174
+ # via enhancer
175
+ requests==2.32.3
176
+ # via huggingface-hub
177
+ # via spaces
178
+ rich==13.8.0
179
+ # via typer
180
+ ruff==0.6.4
181
+ # via gradio
182
+ safetensors==0.4.5
183
+ # via refiners
184
+ semantic-version==2.10.0
185
+ # via gradio
186
+ setuptools==74.1.2
187
+ # via torch
188
+ shellingham==1.5.4
189
+ # via typer
190
+ six==1.16.0
191
+ # via python-dateutil
192
+ sniffio==1.3.1
193
+ # via anyio
194
+ # via httpx
195
+ spaces==0.30.1
196
+ # via enhancer
197
+ starlette==0.38.4
198
+ # via fastapi
199
+ sympy==1.13.2
200
+ # via torch
201
+ tomlkit==0.12.0
202
+ # via gradio
203
+ torch==2.4.1
204
+ # via refiners
205
+ tqdm==4.66.5
206
+ # via huggingface-hub
207
+ triton==3.0.0
208
+ # via torch
209
+ typeguard==2.13.3
210
+ # via jaxtyping
211
+ typer==0.12.5
212
+ # via gradio
213
+ typing-extensions==4.12.2
214
+ # via fastapi
215
+ # via gradio
216
+ # via gradio-client
217
+ # via huggingface-hub
218
+ # via pydantic
219
+ # via pydantic-core
220
+ # via spaces
221
+ # via torch
222
+ # via typer
223
+ tzdata==2024.1
224
+ # via pandas
225
+ urllib3==2.2.2
226
+ # via gradio
227
+ # via requests
228
+ uvicorn==0.30.6
229
+ # via gradio
230
+ websockets==12.0
231
+ # via gradio-client
src/app.py CHANGED
@@ -1,12 +1,12 @@
1
  from pathlib import Path
2
 
3
  import gradio as gr
 
4
  import spaces
5
  import torch
6
  from gradio_imageslider import ImageSlider
7
  from huggingface_hub import hf_hub_download
8
  from PIL import Image
9
- import pillow_heif
10
  from refiners.fluxion.utils import manual_seed
11
  from refiners.foundationals.latent_diffusion import Solver, solvers
12
 
@@ -22,12 +22,24 @@ TITLE = """
22
  Image Enhancer Powered By Refiners
23
  </h1>
24
 
25
- <div style="display: flex; align-items: center; justify-content: center; gap: 0.5rem; margin-bottom: 0.5rem; font-size: 1.25rem; flex-wrap: wrap;">
 
 
 
 
 
 
 
 
26
  <a href="https://blog.finegrain.ai/posts/reproducing-clarity-upscaler/" target="_blank">[Blog Post]</a>
27
  <a href="https://github.com/finegrain-ai/refiners" target="_blank">[Refiners]</a>
28
  <a href="https://finegrain.ai/" target="_blank">[Finegrain]</a>
29
- <a href="https://huggingface.co/spaces/finegrain/finegrain-object-eraser" target="_blank">[Finegrain Object Eraser]</a>
30
- <a href="https://huggingface.co/spaces/finegrain/finegrain-object-cutter" target="_blank">[Finegrain Object Cutter]</a>
 
 
 
 
31
  </div>
32
 
33
  <p>
@@ -108,11 +120,6 @@ CHECKPOINTS = ESRGANUpscalerCheckpoints(
108
  },
109
  )
110
 
111
- LORA_SCALES = {
112
- "more_details": 0.5,
113
- "sdxl_render": 1.0,
114
- }
115
-
116
  # initialize the enhancer, on the cpu
117
  DEVICE_CPU = torch.device("cpu")
118
  DTYPE = torch.bfloat16 if torch.cuda.is_bf16_supported() else torch.float32
@@ -154,7 +161,7 @@ def process(
154
  tile_size=(tile_height, tile_width),
155
  denoise_strength=denoise_strength,
156
  num_inference_steps=num_inference_steps,
157
- loras_scale=LORA_SCALES,
158
  solver_type=solver_type,
159
  )
160
 
 
1
  from pathlib import Path
2
 
3
  import gradio as gr
4
+ import pillow_heif
5
  import spaces
6
  import torch
7
  from gradio_imageslider import ImageSlider
8
  from huggingface_hub import hf_hub_download
9
  from PIL import Image
 
10
  from refiners.fluxion.utils import manual_seed
11
  from refiners.foundationals.latent_diffusion import Solver, solvers
12
 
 
22
  Image Enhancer Powered By Refiners
23
  </h1>
24
 
25
+ <div style="
26
+ display: flex;
27
+ align-items: center;
28
+ justify-content: center;
29
+ gap: 0.5rem;
30
+ margin-bottom: 0.5rem;
31
+ font-size: 1.25rem;
32
+ flex-wrap: wrap;
33
+ ">
34
  <a href="https://blog.finegrain.ai/posts/reproducing-clarity-upscaler/" target="_blank">[Blog Post]</a>
35
  <a href="https://github.com/finegrain-ai/refiners" target="_blank">[Refiners]</a>
36
  <a href="https://finegrain.ai/" target="_blank">[Finegrain]</a>
37
+ <a href="https://huggingface.co/spaces/finegrain/finegrain-object-eraser" target="_blank">
38
+ [Finegrain Object Eraser]
39
+ </a>
40
+ <a href="https://huggingface.co/spaces/finegrain/finegrain-object-cutter" target="_blank">
41
+ [Finegrain Object Cutter]
42
+ </a>
43
  </div>
44
 
45
  <p>
 
120
  },
121
  )
122
 
 
 
 
 
 
123
  # initialize the enhancer, on the cpu
124
  DEVICE_CPU = torch.device("cpu")
125
  DTYPE = torch.bfloat16 if torch.cuda.is_bf16_supported() else torch.float32
 
161
  tile_size=(tile_height, tile_width),
162
  denoise_strength=denoise_strength,
163
  num_inference_steps=num_inference_steps,
164
+ loras_scale={"more_details": 0.5, "sdxl_render": 1.0},
165
  solver_type=solver_type,
166
  )
167