HariLogicgo commited on
Commit
9b92c1c
·
1 Parent(s): 500d1fa

fastapi added

Browse files
Files changed (1) hide show
  1. app.py +152 -149
app.py CHANGED
@@ -17,9 +17,12 @@ from basicsr.utils.realesrganer import RealESRGANer
17
  from utils.dataops import auto_split_upscale
18
  from typing import List, Optional
19
 
 
 
 
20
  # Ensure required directories exist at import time (for API mode)
21
- os.makedirs('output', exist_ok=True)
22
- os.makedirs('input', exist_ok=True)
23
 
24
  # FastAPI imports
25
  from fastapi import FastAPI, UploadFile, File, Form, Depends, HTTPException, status
@@ -47,31 +50,31 @@ input_images_limit = 5
47
  # Define URLs and their corresponding local storage paths
48
  face_models = {
49
  "GFPGANv1.4.pth": ["https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.4.pth",
50
- "https://github.com/TencentARC/GFPGAN/",
51
- """GFPGAN: Towards Real-World Blind Face Restoration and Upscalling of the image with a Generative Facial Prior.
52
  GFPGAN aims at developing a Practical Algorithm for Real-world Face Restoration.
53
  It leverages rich and diverse priors encapsulated in a pretrained face GAN (e.g., StyleGAN2) for blind face restoration."""],
54
  "RestoreFormer++.ckpt": ["https://github.com/wzhouxiff/RestoreFormerPlusPlus/releases/download/v1.0.0/RestoreFormer++.ckpt",
55
- "https://github.com/wzhouxiff/RestoreFormerPlusPlus",
56
- """RestoreFormer++: Towards Real-World Blind Face Restoration from Undegraded Key-Value Pairs.
57
  RestoreFormer++ is an extension of RestoreFormer. It proposes to restore a degraded face image with both fidelity and realness by using the powerful fully-spacial attention mechanisms to model the abundant contextual information in the face and its interplay with reconstruction-oriented high-quality priors."""],
58
  "CodeFormer.pth": ["https://github.com/sczhou/CodeFormer/releases/download/v0.1.0/codeformer.pth",
59
- "https://github.com/sczhou/CodeFormer",
60
- """CodeFormer: Towards Robust Blind Face Restoration with Codebook Lookup Transformer (NeurIPS 2022).
61
  CodeFormer is a Transformer-based model designed to tackle the challenging problem of blind face restoration, where inputs are often severely degraded.
62
  By framing face restoration as a code prediction task, this approach ensures both improved mapping from degraded inputs to outputs and the generation of visually rich, high-quality faces."""],
63
  "GPEN-BFR-512.pth": ["https://huggingface.co/akhaliq/GPEN-BFR-512/resolve/main/GPEN-BFR-512.pth",
64
- "https://github.com/yangxy/GPEN",
65
- """GPEN: GAN Prior Embedded Network for Blind Face Restoration in the Wild.
66
  GPEN addresses blind face restoration (BFR) by embedding a GAN into a U-shaped DNN, combining GAN’s ability to generate high-quality images with DNN’s feature extraction.
67
  This design reconstructs global structure, fine details, and backgrounds from degraded inputs.
68
  Simple yet effective, GPEN outperforms state-of-the-art methods, delivering realistic results even for severely degraded images."""],
69
  "GPEN-BFR-1024.pt": ["https://www.modelscope.cn/models/iic/cv_gpen_image-portrait-enhancement-hires/resolve/master/pytorch_model.pt",
70
- "https://www.modelscope.cn/models/iic/cv_gpen_image-portrait-enhancement-hires/files",
71
- """The same as GPEN but for 1024 resolution."""],
72
  "GPEN-BFR-2048.pt": ["https://www.modelscope.cn/models/iic/cv_gpen_image-portrait-enhancement-hires/resolve/master/pytorch_model-2048.pt",
73
- "https://www.modelscope.cn/models/iic/cv_gpen_image-portrait-enhancement-hires/files",
74
- """The same as GPEN but for 2048 resolution."""],
75
  "GFPGANv1.3.pth": ["https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth",
76
  "https://github.com/TencentARC/GFPGAN/",
77
  "The same as GFPGAN but legacy model"],
@@ -85,245 +88,245 @@ Simple yet effective, GPEN outperforms state-of-the-art methods, delivering real
85
 
86
  upscale_models = {
87
  "realesr-general-x4v3.pth": ["https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-x4v3.pth",
88
- "https://github.com/xinntao/Real-ESRGAN/releases/tag/v0.3.0",
89
- """Compression Removal, General Upscaler, JPEG, Realistic, Research, Restoration
90
  xinntao: add realesr-general-x4v3 and realesr-general-wdn-x4v3. They are very tiny models for general scenes, and they may more robust. But as they are tiny models, their performance may be limited."""],
91
  "realesr-animevideov3.pth": ["https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-animevideov3.pth",
92
- "https://github.com/xinntao/Real-ESRGAN/releases/tag/v0.2.5.0",
93
- """Anime, Cartoon, Compression Removal, General Upscaler, JPEG, Realistic, Research, Restoration
94
  xinntao: update the RealESRGAN AnimeVideo-v3 model, which can achieve better results with a faster inference speed."""],
95
  "4xLSDIRCompact.pth": ["https://github.com/Phhofm/models/releases/download/4xLSDIRCompact/4xLSDIRCompact.pth",
96
- "https://github.com/Phhofm/models/releases/tag/4xLSDIRCompact",
97
- """Realistic
98
  Phhofm: Upscale small good quality photos to 4x their size. This is my first ever released self-trained sisr upscaling model."""],
99
  "4xLSDIRCompactC.pth": ["https://github.com/Phhofm/models/releases/download/4xLSDIRCompactC/4xLSDIRCompactC.pth",
100
- "https://github.com/Phhofm/models/releases/tag/4xLSDIRCompactC",
101
- """Compression Removal, JPEG, Realistic, Restoration
102
  Phhofm: 4x photo upscaler that handler jpg compression. Trying to extend my previous model to be able to handle compression (JPG 100-30) by manually altering the training dataset, since 4xLSDIRCompact cant handle compression. Use this instead of 4xLSDIRCompact if your photo has compression (like an image from the web)."""],
103
  "4xLSDIRCompactR.pth": ["https://github.com/Phhofm/models/releases/download/4xLSDIRCompactC/4xLSDIRCompactR.pth",
104
- "https://github.com/Phhofm/models/releases/tag/4xLSDIRCompactC",
105
- """Compression Removal, Realistic, Restoration
106
  Phhofm: 4x photo uspcaler that handles jpg compression, noise and slight. Extending my last 4xLSDIRCompact model to Real-ESRGAN, meaning trained on synthetic data instead to handle more kinds of degradations, it should be able to handle compression, noise, and slight blur."""],
107
  "4xLSDIRCompactN.pth": ["https://github.com/Phhofm/models/releases/download/4xLSDIRCompact3/4xLSDIRCompactC3.pth",
108
- "https://github.com/Phhofm/models/releases/tag/4xLSDIRCompact3",
109
- """Realistic
110
  Phhofm: Upscale good quality input photos to x4 their size. The original 4xLSDIRCompact a bit more trained, cannot handle degradation."""],
111
  "4xLSDIRCompactC3.pth": ["https://github.com/Phhofm/models/releases/download/4xLSDIRCompact3/4xLSDIRCompactC3.pth",
112
- "https://github.com/Phhofm/models/releases/tag/4xLSDIRCompact3",
113
  """Compression Removal, JPEG, Realistic, Restoration
114
  Phhofm: Upscale compressed photos to x4 their size. Able to handle JPG compression (30-100)."""],
115
  "4xLSDIRCompactR3.pth": ["https://github.com/Phhofm/models/releases/download/4xLSDIRCompact3/4xLSDIRCompactR3.pth",
116
- "https://github.com/Phhofm/models/releases/tag/4xLSDIRCompact3",
117
- """Realistic, Restoration
118
  Phhofm: Upscale (degraded) photos to x4 their size. Trained on synthetic data, meant to handle more degradations."""],
119
  "4xLSDIRCompactCR3.pth": ["https://github.com/Phhofm/models/releases/download/4xLSDIRCompact3/4xLSDIRCompactCR3.pth",
120
- "https://github.com/Phhofm/models/releases/tag/4xLSDIRCompact3",
121
- """Phhofm: I am releasing the Series 3 from my 4xLSDIRCompact models. In general my suggestion is, if you have good quality input images use 4xLSDIRCompactN3, otherwise try 4xLSDIRCompactC3 which will be able to handle jpg compression and a bit of blur, or then 4xLSDIRCompactCR3, which is an interpolation between C3 and R3 to be able to handle a bit of noise additionally."""],
122
  "2xParimgCompact.pth": ["https://github.com/Phhofm/models/releases/download/2xParimgCompact/2xParimgCompact.pth",
123
- "https://github.com/Phhofm/models/releases/tag/2xParimgCompact",
124
- """Realistic
125
  Phhofm: A 2x photo upscaling compact model based on Microsoft's ImagePairs. This was one of the earliest models I started training and finished it now for release. As can be seen in the examples, this model will affect colors."""],
126
  "1xExposureCorrection_compact.pth": ["https://github.com/Phhofm/models/releases/download/1xExposureCorrection_compact/1xExposureCorrection_compact.pth",
127
- "https://github.com/Phhofm/models/releases/tag/1xExposureCorrection_compact",
128
- """Restoration
129
  Phhofm: This model is meant as an experiment to see if compact can be used to train on photos to exposure correct those using the pixel, perceptual, color, color and ldl losses. There is no brightness loss. Still it seems to kinda work."""],
130
  "1xUnderExposureCorrection_compact.pth": ["https://github.com/Phhofm/models/releases/download/1xExposureCorrection_compact/1xUnderExposureCorrection_compact.pth",
131
- "https://github.com/Phhofm/models/releases/tag/1xExposureCorrection_compact",
132
- """Restoration
133
  Phhofm: This model is meant as an experiment to see if compact can be used to train on underexposed images to exposure correct those using the pixel, perceptual, color, color and ldl losses. There is no brightness loss. Still it seems to kinda work."""],
134
  "1xOverExposureCorrection_compact.pth": ["https://github.com/Phhofm/models/releases/download/1xExposureCorrection_compact/1xOverExposureCorrection_compact.pth",
135
- "https://github.com/Phhofm/models/releases/tag/1xExposureCorrection_compact",
136
- """Restoration
137
  Phhofm: This model is meant as an experiment to see if compact can be used to train on overexposed images to exposure correct those using the pixel, perceptual, color, color and ldl losses. There is no brightness loss. Still it seems to kinda work."""],
138
  "2x-sudo-UltraCompact.pth": ["https://objectstorage.us-phoenix-1.oraclecloud.com/n/ax6ygfvpvzka/b/open-modeldb-files/o/2x-sudo-UltraCompact.pth",
139
- "https://openmodeldb.info/models/2x-sudo-UltraCompact",
140
- """Anime, Cartoon, Restoration
141
  sudo: Realtime animation restauration and doing stuff like deblur and compression artefact removal."""],
142
  "2x_AnimeJaNai_HD_V3_SuperUltraCompact.pth": ["https://github.com/the-database/mpv-upscale-2x_animejanai/releases/download/3.0.0/2x_AnimeJaNai_HD_V3_ModelsOnly.zip",
143
- "https://openmodeldb.info/models/2x-AnimeJaNai-HD-V3-SuperUltraCompact",
144
- """Anime, Compression Removal, Restoration
145
  the-database: Real-time 2x Real-ESRGAN Compact/UltraCompact/SuperUltraCompact models designed for upscaling 1080p anime to 4K."""],
146
  "2x_AnimeJaNai_HD_V3_UltraCompact.pth": ["https://github.com/the-database/mpv-upscale-2x_animejanai/releases/download/3.0.0/2x_AnimeJaNai_HD_V3_ModelsOnly.zip",
147
- "https://openmodeldb.info/models/2x-AnimeJaNai-HD-V3-UltraCompact",
148
- """Anime, Compression Removal, Restoration
149
  the-database: Real-time 2x Real-ESRGAN Compact/UltraCompact/SuperUltraCompact models designed for upscaling 1080p anime to 4K."""],
150
  "2x_AnimeJaNai_HD_V3_Compact.pth": ["https://github.com/the-database/mpv-upscale-2x_animejanai/releases/download/3.0.0/2x_AnimeJaNai_HD_V3_ModelsOnly.zip",
151
- "https://openmodeldb.info/models/2x-AnimeJaNai-HD-V3-Compact",
152
- """Anime, Compression Removal, Restoration
153
  the-database: Real-time 2x Real-ESRGAN Compact/UltraCompact/SuperUltraCompact models designed for upscaling 1080p anime to 4K."""],
154
  "RealESRGAN_x4plus_anime_6B.pth": ["https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth",
155
- "https://github.com/xinntao/Real-ESRGAN/releases/tag/v0.2.2.4",
156
- """Anime, Cartoon, Compression Removal, General Upscaler, JPEG, Realistic, Research, Restoration
157
  xinntao: We add RealESRGAN_x4plus_anime_6B.pth, which is optimized for anime images with much smaller model size."""],
158
  "RealESRGAN_x2plus.pth": ["https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.1/RealESRGAN_x2plus.pth",
159
- "https://github.com/xinntao/Real-ESRGAN/releases/tag/v0.2.1",
160
- """Compression Removal, General Upscaler, JPEG, Realistic, Research, Restoration
161
  xinntao: Add RealESRGAN_x2plus.pth model"""],
162
  "RealESRNet_x4plus.pth": ["https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.1/RealESRNet_x4plus.pth",
163
- "https://github.com/xinntao/Real-ESRGAN/releases/tag/v0.1.1",
164
- """Compression Removal, General Upscaler, JPEG, Realistic, Research, Restoration
165
  xinntao: This release is mainly for storing pre-trained models and executable files."""],
166
  "RealESRGAN_x4plus.pth": ["https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth",
167
- "https://github.com/xinntao/Real-ESRGAN/releases/tag/v0.1.0",
168
- """Compression Removal, General Upscaler, JPEG, Realistic, Research, Restoration
169
  xinntao: This release is mainly for storing pre-trained models and executable files."""],
170
  "4x-AnimeSharp.pth": ["https://huggingface.co/utnah/esrgan/resolve/main/4x-AnimeSharp.pth?download=true",
171
- "https://openmodeldb.info/models/4x-AnimeSharp",
172
- """Anime, Cartoon, Text
173
  Kim2091: Interpolation between 4x-UltraSharp and 4x-TextSharp-v0.5. Works amazingly on anime."""],
174
  "4x_IllustrationJaNai_V1_ESRGAN_135k.pth": ["https://drive.google.com/uc?export=download&confirm=1&id=1qpioSqBkB_IkSBhEAewSSNFt6qgkBimP",
175
- "https://openmodeldb.info/models/4x-IllustrationJaNai-V1-DAT2",
176
- """Anime, Cartoon, Compression Removal, Dehalftone, General Upscaler, JPEG, Manga, Restoration
177
  the-database: Model for color images including manga covers and color illustrations, digital art, visual novel art, artbooks, and more."""],
178
  "2x-sudo-RealESRGAN.pth": ["https://objectstorage.us-phoenix-1.oraclecloud.com/n/ax6ygfvpvzka/b/open-modeldb-files/o/2x-sudo-RealESRGAN.pth",
179
- "https://openmodeldb.info/models/2x-sudo-RealESRGAN",
180
- """Anime, Cartoon
181
  sudo: Tried to make the best 2x model there is for drawings."""],
182
  "2x-sudo-RealESRGAN-Dropout.pth": ["https://objectstorage.us-phoenix-1.oraclecloud.com/n/ax6ygfvpvzka/b/open-modeldb-files/o/2x-sudo-RealESRGAN-Dropout.pth",
183
- "https://openmodeldb.info/models/2x-sudo-RealESRGAN-Dropout",
184
- """Anime, Cartoon
185
  sudo: Tried to make the best 2x model there is for drawings."""],
186
  "4xNomos2_otf_esrgan.pth": ["https://github.com/Phhofm/models/releases/download/4xNomos2_otf_esrgan/4xNomos2_otf_esrgan.pth",
187
- "https://github.com/Phhofm/models/releases/tag/4xNomos2_otf_esrgan",
188
- """Compression Removal, JPEG, Realistic, Restoration
189
  Phhofm: Restoration, 4x ESRGAN model for photography, trained using the Real-ESRGAN otf degradation pipeline."""],
190
  "4xNomosWebPhoto_esrgan.pth": ["https://github.com/Phhofm/models/releases/download/4xNomosWebPhoto_esrgan/4xNomosWebPhoto_esrgan.pth",
191
- "https://github.com/Phhofm/models/releases/tag/4xNomosWebPhoto_esrgan",
192
- """Realistic, Restoration
193
  Phhofm: Restoration, 4x ESRGAN model for photography, trained with realistic noise, lens blur, jpg and webp re-compression."""],
194
  "4x_foolhardy_Remacri.pth": ["https://civitai.com/api/download/models/164821?type=Model&format=PickleTensor",
195
- "https://openmodeldb.info/models/4x-Remacri",
196
- """Original
197
  FoolhardyVEVO: A creation of BSRGAN with more details and less smoothing."""],
198
  "4x_foolhardy_Remacri_ExtraSmoother.pth": ["https://civitai.com/api/download/models/164822?type=Model&format=PickleTensor",
199
- "https://openmodeldb.info/models/4x-Remacri",
200
- """ExtraSmoother
201
  FoolhardyVEVO: A creation of BSRGAN with more details and less smoothing."""],
202
  "4xNomos8kDAT.pth": ["https://github.com/Phhofm/models/releases/download/4xNomos8kDAT/4xNomos8kDAT.pth",
203
- "https://openmodeldb.info/models/4x-Nomos8kDAT",
204
- """Anime, Compression Removal, General Upscaler, JPEG, Realistic, Restoration
205
  Phhofm: A 4x photo upscaler with otf jpg compression, blur and resize, trained on musl's Nomos8k_sfw dataset for realisic sr."""],
206
  "4x-DWTP-DS-dat2-v3.pth": ["https://objectstorage.us-phoenix-1.oraclecloud.com/n/ax6ygfvpvzka/b/open-modeldb-files/o/4x-DWTP-DS-dat2-v3.pth",
207
- "https://openmodeldb.info/models/4x-DWTP-DS-dat2-v3",
208
- """Dehalftone, Restoration
209
  umzi.x.dead: DAT descreenton model, designed to reduce discrepancies on tiles due to too much loss of the first version."""],
210
  "4xBHI_dat2_real.pth": ["https://github.com/Phhofm/models/releases/download/4xBHI_dat2_real/4xBHI_dat2_real.pth",
211
- "https://github.com/Phhofm/models/releases/tag/4xBHI_dat2_real",
212
- """Compression Removal, JPEG, Realistic
213
  Phhofm: 4x dat2 upscaling model for web and realistic images."""],
214
  "4xBHI_dat2_otf.pth": ["https://github.com/Phhofm/models/releases/download/4xBHI_dat2_otf/4xBHI_dat2_otf.pth",
215
- "https://github.com/Phhofm/models/releases/tag/4xBHI_dat2_otf",
216
- """Compression Removal, JPEG
217
  Phhofm: 4x dat2 upscaling model, trained with the real-esrgan otf pipeline on my bhi dataset."""],
218
  "4xBHI_dat2_multiblur.pth": ["https://github.com/Phhofm/models/releases/download/4xBHI_dat2_multiblurjpg/4xBHI_dat2_multiblur.pth",
219
- "https://github.com/Phhofm/models/releases/tag/4xBHI_dat2_multiblurjpg",
220
- """Phhofm: the 4xBHI_dat2_multiblur checkpoint (trained to 250000 iters), which cannot handle compression but might give just slightly better output on non-degraded input."""],
221
  "4xBHI_dat2_multiblurjpg.pth": ["https://github.com/Phhofm/models/releases/download/4xBHI_dat2_multiblurjpg/4xBHI_dat2_multiblurjpg.pth",
222
- "https://github.com/Phhofm/models/releases/tag/4xBHI_dat2_multiblurjpg",
223
- """Compression Removal, JPEG
224
  Phhofm: 4x dat2 upscaling model, trained with down_up,linear, cubic_mitchell, lanczos, gauss and box scaling algos, some average, gaussian and anisotropic blurs and jpg compression."""],
225
  "4x_IllustrationJaNai_V1_DAT2_190k.pth": ["https://drive.google.com/uc?export=download&confirm=1&id=1qpioSqBkB_IkSBhEAewSSNFt6qgkBimP",
226
- "https://openmodeldb.info/models/4x-IllustrationJaNai-V1-DAT2",
227
- """Anime, Cartoon, Compression Removal, Dehalftone, General Upscaler, JPEG, Manga, Restoration
228
  the-database: Model for color images including manga covers and color illustrations, digital art, visual novel art, artbooks, and more."""],
229
  "4x-PBRify_UpscalerDAT2_V1.pth": ["https://github.com/Kim2091/Kim2091-Models/releases/download/4x-PBRify_UpscalerDAT2_V1/4x-PBRify_UpscalerDAT2_V1.pth",
230
- "https://github.com/Kim2091/Kim2091-Models/releases/tag/4x-PBRify_UpscalerDAT2_V1",
231
- """Compression Removal, DDS, Game Textures, Restoration
232
  Kim2091: Yet another model in the PBRify_Remix series."""],
233
  "4xBHI_dat2_otf_nn.pth": ["https://github.com/Phhofm/models/releases/download/4xBHI_dat2_otf_nn/4xBHI_dat2_otf_nn.pth",
234
- "https://github.com/Phhofm/models/releases/tag/4xBHI_dat2_otf_nn",
235
- """Compression Removal, JPEG
236
  Phhofm: 4x dat2 upscaling model, trained with the real-esrgan otf pipeline but without noise, on my bhi dataset."""],
237
  "4xNomos8kSCHAT-L.pth": ["https://github.com/Phhofm/models/releases/download/4xNomos8kSCHAT/4xNomos8kSCHAT-L.pth",
238
- "https://openmodeldb.info/models/4x-Nomos8kSCHAT-L",
239
- """Anime, Compression Removal, General Upscaler, JPEG, Realistic, Restoration
240
  Phhofm: 4x photo upscaler with otf jpg compression and blur, trained on musl's Nomos8k_sfw dataset for realisic sr."""],
241
  "4xNomos8kSCHAT-S.pth": ["https://github.com/Phhofm/models/releases/download/4xNomos8kSCHAT/4xNomos8kSCHAT-S.pth",
242
- "https://openmodeldb.info/models/4x-Nomos8kSCHAT-S",
243
- """Anime, Compression Removal, General Upscaler, JPEG, Realistic, Restoration
244
  Phhofm: 4x photo upscaler with otf jpg compression and blur, trained on musl's Nomos8k_sfw dataset for realisic sr."""],
245
  "4xNomos8kHAT-L_otf.pth": ["https://github.com/Phhofm/models/releases/download/4xNomos8kHAT-L_otf/4xNomos8kHAT-L_otf.pth",
246
- "https://openmodeldb.info/models/4x-Nomos8kHAT-L-otf",
247
- """Faces, General Upscaler, Realistic, Restoration
248
  Phhofm: 4x photo upscaler trained with otf, handles some jpg compression, some blur and some noise."""],
249
  "4xBHI_small_hat-l.pth": ["https://github.com/Phhofm/models/releases/download/4xBHI_small_hat-l/4xBHI_small_hat-l.pth",
250
- "https://github.com/Phhofm/models/releases/tag/4xBHI_small_hat-l",
251
  """Phhofm: 4x hat-l upscaling model for good quality input. This model does not handle any degradations."""],
252
  "4xHFA2k_ludvae_realplksr_dysample.pth": ["https://github.com/Phhofm/models/releases/download/4xHFA2k_ludvae_realplksr_dysample/4xHFA2k_ludvae_realplksr_dysample.pth",
253
- "https://openmodeldb.info/models/4x-HFA2k-ludvae-realplksr-dysample",
254
- """Anime, Compression Removal, Restoration
255
  Phhofm: A Dysample RealPLKSR 4x upscaling model for anime single-image resolution."""],
256
  "4xArtFaces_realplksr_dysample.pth": ["https://github.com/Phhofm/models/releases/download/4xArtFaces_realplksr_dysample/4xArtFaces_realplksr_dysample.pth",
257
- "https://openmodeldb.info/models/4x-ArtFaces-realplksr-dysample",
258
- """ArtFaces
259
  Phhofm: A Dysample RealPLKSR 4x upscaling model for art / painted faces."""],
260
  "4x-PBRify_RPLKSRd_V3.pth": ["https://github.com/Kim2091/Kim2091-Models/releases/download/4x-PBRify_RPLKSRd_V3/4x-PBRify_RPLKSRd_V3.pth",
261
- "https://github.com/Kim2091/Kim2091-Models/releases/tag/4x-PBRify_RPLKSRd_V3",
262
- """Compression Removal, DDS, Debanding, Dedither, Dehalo, Game Textures, Restoration
263
  Kim2091: This update brings a new upscaling model, 4x-PBRify_RPLKSRd_V3."""],
264
  "4xNomos2_realplksr_dysample.pth": ["https://github.com/Phhofm/models/releases/download/4xNomos2_realplksr_dysample/4xNomos2_realplksr_dysample.pth",
265
- "https://openmodeldb.info/models/4x-Nomos2-realplksr-dysample",
266
- """Compression Removal, JPEG, Realistic, Restoration
267
  Phhofm: A Dysample RealPLKSR 4x upscaling model that was trained with / handles jpg compression down to 70 on the Nomosv2 dataset."""],
268
  "2x-AnimeSharpV2_RPLKSR_Sharp.pth": ["https://github.com/Kim2091/Kim2091-Models/releases/download/2x-AnimeSharpV2_Set/2x-AnimeSharpV2_RPLKSR_Sharp.pth",
269
- "https://github.com/Kim2091/Kim2091-Models/releases/tag/2x-AnimeSharpV2_Set",
270
- """Anime, Compression Removal, Restoration
271
  Kim2091: This is my first anime model in years. Sharp: For heavily degraded sources."""],
272
  "2x-AnimeSharpV2_RPLKSR_Soft.pth": ["https://github.com/Kim2091/Kim2091-Models/releases/download/2x-AnimeSharpV2_Set/2x-AnimeSharpV2_RPLKSR_Soft.pth",
273
- "https://github.com/Kim2091/Kim2091-Models/releases/tag/2x-AnimeSharpV2_Set",
274
- """Anime, Compression Removal, Restoration
275
  Kim2091: This is my first anime model in years. Soft: For cleaner sources."""],
276
  "4xPurePhoto-RealPLSKR.pth": ["https://github.com/starinspace/StarinspaceUpscale/releases/download/Models/4xPurePhoto-RealPLSKR.pth",
277
- "https://openmodeldb.info/models/4x-PurePhoto-RealPLSKR",
278
- """AI Generated, Compression Removal, JPEG, Realistic, Restoration
279
  asterixcool: Skilled in working with cats, hair, parties, and creating clear images."""],
280
  "2x_Text2HD_v.1-RealPLKSR.pth": ["https://github.com/starinspace/StarinspaceUpscale/releases/download/Models/2x_Text2HD_v.1-RealPLKSR.pth",
281
- "https://openmodeldb.info/models/2x-Text2HD-v-1",
282
- """Compression Removal, Denoise, General Upscaler, JPEG, Restoration, Text
283
  asterixcool: The upscale model is specifically designed to enhance lower-quality text images."""],
284
  "2xVHS2HD-RealPLKSR.pth": ["https://github.com/starinspace/StarinspaceUpscale/releases/download/Models/2xVHS2HD-RealPLKSR.pth",
285
- "https://openmodeldb.info/models/2x-VHS2HD",
286
- """Compression Removal, Dehalo, Realistic, Restoration, Video Frame
287
  asterixcool: An advanced VHS recording model designed to enhance video quality by reducing artifacts."""],
288
  "4xNomosWebPhoto_RealPLKSR.pth": ["https://github.com/Phhofm/models/releases/download/4xNomosWebPhoto_RealPLKSR/4xNomosWebPhoto_RealPLKSR.pth",
289
- "https://openmodeldb.info/models/4x-NomosWebPhoto-RealPLKSR",
290
- """Realistic, Restoration
291
  Phhofm: 4x RealPLKSR model for photography, trained with realistic noise, lens blur, jpg and webp re-compression."""],
292
  "4xNomos2_hq_drct-l.pth": ["https://github.com/Phhofm/models/releases/download/4xNomos2_hq_drct-l/4xNomos2_hq_drct-l.pth",
293
- "https://github.com/Phhofm/models/releases/tag/4xNomos2_hq_drct-l",
294
- """General Upscaler, Realistic
295
  Phhofm: An drct-l 4x upscaling model, similiar to the 4xNomos2_hq_atd, 4xNomos2_hq_dat2 and 4xNomos2_hq_mosr models."""],
296
  "4xNomos2_hq_atd.pth": ["https://github.com/Phhofm/models/releases/download/4xNomos2_hq_atd/4xNomos2_hq_atd.pth",
297
- "https://github.com/Phhofm/models/releases/tag/4xNomos2_hq_atd",
298
- """General Upscaler, Realistic
299
  Phhofm: An atd 4x upscaling model, similiar to the 4xNomos2_hq_dat2 or 4xNomos2_hq_mosr models."""],
300
  "4xNomos2_hq_mosr.pth": ["https://github.com/Phhofm/models/releases/download/4xNomos2_hq_mosr/4xNomos2_hq_mosr.pth",
301
- "https://github.com/Phhofm/models/releases/tag/4xNomos2_hq_mosr",
302
- """General Upscaler, Realistic
303
  Phhofm: A 4x MoSR upscaling model, meant for non-degraded input."""],
304
  "2x-AnimeSharpV2_MoSR_Sharp.pth": ["https://github.com/Kim2091/Kim2091-Models/releases/download/2x-AnimeSharpV2_Set/2x-AnimeSharpV2_MoSR_Sharp.pth",
305
- "https://github.com/Kim2091/Kim2091-Models/releases/tag/2x-AnimeSharpV2_Set",
306
- """Anime, Compression Removal, Restoration
307
  Kim2091: This is my first anime model in years. Sharp: For heavily degraded sources."""],
308
  "2x-AnimeSharpV2_MoSR_Soft.pth": ["https://github.com/Kim2091/Kim2091-Models/releases/download/2x-AnimeSharpV2_Set/2x-AnimeSharpV2_MoSR_Soft.pth",
309
- "https://github.com/Kim2091/Kim2091-Models/releases/tag/2x-AnimeSharpV2_Set",
310
- """Anime, Compression Removal, Restoration
311
  Kim2091: This is my first anime model in years. Soft: For cleaner sources."""],
312
  "4xNomos8kSCSRFormer.pth": ["https://github.com/Phhofm/models/releases/download/4xNomos8kSCSRFormer/4xNomos8kSCSRFormer.pth",
313
- "https://github.com/Phhofm/models/releases/tag/4xNomos8kSCSRFormer",
314
- """Anime, Compression Removal, General Upscaler, JPEG, Realistic, Restoration
315
  Phhofm: 4x photo upscaler with otf jpg compression and blur, trained on musl's Nomos8k_sfw dataset for realisic sr."""],
316
  "4xFrankendataFullDegradation_SRFormer460K_g.pth": ["https://drive.google.com/uc?export=download&confirm=1&id=1PZrj-8ofxhORv_OgTVSoRt3dYi-BtiDj",
317
- "https://openmodeldb.info/models/4x-Frankendata-FullDegradation-SRFormer",
318
- """Compression Removal, Denoise, Realistic, Restoration
319
  Crustaceous D: 4x realistic upscaler that may also work for general purpose usage."""],
320
  "4xFrankendataPretrainer_SRFormer400K_g.pth": ["https://drive.google.com/uc?export=download&confirm=1&id=1SaKvpYYIm2Vj2m9GifUMlNCbmkE6JZmr",
321
- "https://openmodeldb.info/models/4x-FrankendataPretainer-SRFormer",
322
- """Realistic, Restoration
323
  Crustaceous D: 4x realistic upscaler that may also work for general purpose usage."""],
324
  "1xFrankenfixer_SRFormerLight_g.pth": ["https://drive.google.com/uc?export=download&confirm=1&id=1UJ0iyFn4IGNhPIgNgrQrBxYsdDloFc9I",
325
- "https://openmodeldb.info/models/1x-Frankenfixer-SRFormerLight",
326
- """Realistic, Restoration
327
  Crustaceous D: A 1x model designed to reduce artifacts and restore detail to images upscaled by 4xFrankendata_FullDegradation_SRFormer."""],
328
  }
329
 
@@ -415,7 +418,7 @@ class Upscale:
415
  if "layers.0.blocks.0.attn.attns.0.rpe_biases" in loadnet:
416
  split_sizes = loadnet["layers.0.blocks.0.attn.attns.0.rpe_biases"][-1] + 1
417
  split_size = [int(x) for x in split_sizes]
418
- model = DAT(img_size=img_size, in_chans=in_chans, embed_dim=embed_dim, split_size=split_size, depth=depth, num_heads=num_heads, expansion_factor=expansion_factor,
419
  qkv_bias=qkv_bias, resi_connection=resi_connection, upsampler=upsampler, upscale=netscale)
420
  elif upscale_type == "HAT":
421
  half = False
@@ -473,7 +476,7 @@ class Upscale:
473
  ape = "absolute_pos_embed" in loadnet
474
  model = DRCT(in_chans=in_chans, img_size=64, window_size=window_size, compress_ratio=3, squeeze_factor=30,
475
  conv_scale=0.01, overlap_ratio=0.5, img_range=1., depths=depths, embed_dim=embed_dim, num_heads=num_heads,
476
- mlp_ratio=mlp_ratio, qkv_bias=qkv_bias, ape=ape, patch_norm=patch_norm, use_checkpoint=False,
477
  upscale=netscale, upsampler=upsampler, resi_connection=resi_connection, gc=gc_adjust1)
478
  elif upscale_type == "ATD":
479
  half = False
@@ -560,7 +563,7 @@ class Upscale:
560
  if nice_number == patches_resolution:
561
  img_size = nice_number
562
  break
563
- model = SRFormer(img_size=img_size, in_chans=in_chans, embed_dim=embed_dim, depths=depths, num_heads=num_heads, window_size=window_size, mlp_ratio=mlp_ratio,
564
  qkv_bias=qkv_bias, qk_scale=None, ape=ape, patch_norm=patch_norm, upscale=netscale, upsampler=upsampler, resi_connection=resi_connection)
565
  if model:
566
  self.realesrganer = RealESRGANer(scale=netscale, model_path=os.path.join("weights", "upscale", upscale_model), model=model, tile=0, tile_pad=10, pre_pad=0, half=half)
@@ -662,13 +665,13 @@ class Upscale:
662
  self.modelInUse = ""
663
  files = []
664
  unique_id = str(int(time.time()))
665
- zip_cropf_path = f"output/{unique_id}_cropped_faces{self.modelInUse}.zip"
666
  zipf_cropf = zipfile.ZipFile(zip_cropf_path, 'w', zipfile.ZIP_DEFLATED)
667
- zip_restoref_path = f"output/{unique_id}_restored_faces{self.modelInUse}.zip"
668
  zipf_restoref = zipfile.ZipFile(zip_restoref_path, 'w', zipfile.ZIP_DEFLATED)
669
- zip_cmp_path = f"output/{unique_id}_cmp{self.modelInUse}.zip"
670
  zipf_cmp = zipfile.ZipFile(zip_cmp_path, 'w', zipfile.ZIP_DEFLATED)
671
- zip_restore_path = f"output/{unique_id}_restored_images{self.modelInUse}.zip"
672
  zipf_restore = zipfile.ZipFile(zip_restore_path, 'w', zipfile.ZIP_DEFLATED)
673
  is_auto_split_upscale = True
674
  name_counters = defaultdict(int)
@@ -703,13 +706,13 @@ class Upscale:
703
  cropped_faces, restored_aligned, bg_upsample_img = self.face_enhancer.enhance(img_cv2, has_aligned=False, only_center_face=face_detection_only_center, paste_back=True, bg_upsample_img=bg_upsample_img, eye_dist_threshold=face_detection_threshold)
704
  if cropped_faces and restored_aligned:
705
  for idx, (cropped_face, restored_face) in enumerate(zip(cropped_faces, restored_aligned)):
706
- save_crop_path = f"output/{basename}_{idx:02d}_cropped_faces{self.modelInUse}.png"
707
  self.imwriteUTF8(save_crop_path, cropped_face)
708
  zipf_cropf.write(save_crop_path, arcname=os.path.basename(save_crop_path))
709
- save_restore_path = f"output/{basename}_{idx:02d}_restored_faces{self.modelInUse}.png"
710
  self.imwriteUTF8(save_restore_path, restored_face)
711
  zipf_restoref.write(save_restore_path, arcname=os.path.basename(save_restore_path))
712
- save_cmp_path = f"output/{basename}_{idx:02d}_cmp{self.modelInUse}.png"
713
  cmp_img = np.concatenate((cropped_face, restored_face), axis=1)
714
  self.imwriteUTF8(save_cmp_path, cmp_img)
715
  zipf_cmp.write(save_cmp_path, arcname=os.path.basename(save_cmp_path))
@@ -723,13 +726,13 @@ class Upscale:
723
  restored_img = bg_upsample_img
724
  timer.report()
725
  if restored_img is None:
726
- print(f"Warning: Processing resulted in no image for '{img_path}'. Skipping output.")
727
- continue
728
  if save_as_png:
729
  final_extension = ".png"
730
  else:
731
  final_extension = ".png" if img_mode == "RGBA" else (extension if extension else ".jpg")
732
- save_path = f"output/{basename}{self.modelInUse}{final_extension}"
733
  self.imwriteUTF8(save_path, restored_img)
734
  zipf_restore.write(save_path, arcname=os.path.basename(save_path))
735
  restored_img = cv2.cvtColor(restored_img, cv2.COLOR_BGR2RGB)
@@ -913,7 +916,7 @@ async def submit(
913
  for f in files:
914
  raw_bytes = await f.read()
915
  safe_name = os.path.basename(f.filename)
916
- save_path = os.path.join('input', f"{int(time.time()*1000)}_{safe_name}")
917
  with open(save_path, 'wb') as out:
918
  out.write(raw_bytes)
919
  saved_paths.append(save_path)
@@ -979,7 +982,7 @@ async def submit(
979
  @fastapi_app.get("/download/{filename}")
980
  def download(filename: str, _: bool = Depends(_verify_bearer_token)):
981
  safe_name = os.path.basename(filename)
982
- for p in [os.path.join('output', safe_name), os.path.join('input', safe_name)]:
983
  if os.path.isfile(p):
984
  return FileResponse(p, filename=safe_name)
985
  raise HTTPException(status_code=404, detail="File not found")
 
17
  from utils.dataops import auto_split_upscale
18
  from typing import List, Optional
19
 
20
+ # Writable directories (Spaces often allow /tmp). Override via env if needed.
21
+ OUTPUT_DIR = os.environ.get("OUTPUT_DIR", "/tmp/face_upscale/output")
22
+ INPUT_DIR = os.environ.get("INPUT_DIR", "/tmp/face_upscale/input")
23
  # Ensure required directories exist at import time (for API mode)
24
+ os.makedirs(OUTPUT_DIR, exist_ok=True)
25
+ os.makedirs(INPUT_DIR, exist_ok=True)
26
 
27
  # FastAPI imports
28
  from fastapi import FastAPI, UploadFile, File, Form, Depends, HTTPException, status
 
50
  # Define URLs and their corresponding local storage paths
51
  face_models = {
52
  "GFPGANv1.4.pth": ["https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.4.pth",
53
+ "https://github.com/TencentARC/GFPGAN/",
54
+ """GFPGAN: Towards Real-World Blind Face Restoration and Upscalling of the image with a Generative Facial Prior.
55
  GFPGAN aims at developing a Practical Algorithm for Real-world Face Restoration.
56
  It leverages rich and diverse priors encapsulated in a pretrained face GAN (e.g., StyleGAN2) for blind face restoration."""],
57
  "RestoreFormer++.ckpt": ["https://github.com/wzhouxiff/RestoreFormerPlusPlus/releases/download/v1.0.0/RestoreFormer++.ckpt",
58
+ "https://github.com/wzhouxiff/RestoreFormerPlusPlus",
59
+ """RestoreFormer++: Towards Real-World Blind Face Restoration from Undegraded Key-Value Pairs.
60
  RestoreFormer++ is an extension of RestoreFormer. It proposes to restore a degraded face image with both fidelity and realness by using the powerful fully-spacial attention mechanisms to model the abundant contextual information in the face and its interplay with reconstruction-oriented high-quality priors."""],
61
  "CodeFormer.pth": ["https://github.com/sczhou/CodeFormer/releases/download/v0.1.0/codeformer.pth",
62
+ "https://github.com/sczhou/CodeFormer",
63
+ """CodeFormer: Towards Robust Blind Face Restoration with Codebook Lookup Transformer (NeurIPS 2022).
64
  CodeFormer is a Transformer-based model designed to tackle the challenging problem of blind face restoration, where inputs are often severely degraded.
65
  By framing face restoration as a code prediction task, this approach ensures both improved mapping from degraded inputs to outputs and the generation of visually rich, high-quality faces."""],
66
  "GPEN-BFR-512.pth": ["https://huggingface.co/akhaliq/GPEN-BFR-512/resolve/main/GPEN-BFR-512.pth",
67
+ "https://github.com/yangxy/GPEN",
68
+ """GPEN: GAN Prior Embedded Network for Blind Face Restoration in the Wild.
69
  GPEN addresses blind face restoration (BFR) by embedding a GAN into a U-shaped DNN, combining GAN’s ability to generate high-quality images with DNN’s feature extraction.
70
  This design reconstructs global structure, fine details, and backgrounds from degraded inputs.
71
  Simple yet effective, GPEN outperforms state-of-the-art methods, delivering realistic results even for severely degraded images."""],
72
  "GPEN-BFR-1024.pt": ["https://www.modelscope.cn/models/iic/cv_gpen_image-portrait-enhancement-hires/resolve/master/pytorch_model.pt",
73
+ "https://www.modelscope.cn/models/iic/cv_gpen_image-portrait-enhancement-hires/files",
74
+ """The same as GPEN but for 1024 resolution."""],
75
  "GPEN-BFR-2048.pt": ["https://www.modelscope.cn/models/iic/cv_gpen_image-portrait-enhancement-hires/resolve/master/pytorch_model-2048.pt",
76
+ "https://www.modelscope.cn/models/iic/cv_gpen_image-portrait-enhancement-hires/files",
77
+ """The same as GPEN but for 2048 resolution."""],
78
  "GFPGANv1.3.pth": ["https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth",
79
  "https://github.com/TencentARC/GFPGAN/",
80
  "The same as GFPGAN but legacy model"],
 
88
 
89
  upscale_models = {
90
  "realesr-general-x4v3.pth": ["https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-x4v3.pth",
91
+ "https://github.com/xinntao/Real-ESRGAN/releases/tag/v0.3.0",
92
+ """Compression Removal, General Upscaler, JPEG, Realistic, Research, Restoration
93
  xinntao: add realesr-general-x4v3 and realesr-general-wdn-x4v3. They are very tiny models for general scenes, and they may more robust. But as they are tiny models, their performance may be limited."""],
94
  "realesr-animevideov3.pth": ["https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-animevideov3.pth",
95
+ "https://github.com/xinntao/Real-ESRGAN/releases/tag/v0.2.5.0",
96
+ """Anime, Cartoon, Compression Removal, General Upscaler, JPEG, Realistic, Research, Restoration
97
  xinntao: update the RealESRGAN AnimeVideo-v3 model, which can achieve better results with a faster inference speed."""],
98
  "4xLSDIRCompact.pth": ["https://github.com/Phhofm/models/releases/download/4xLSDIRCompact/4xLSDIRCompact.pth",
99
+ "https://github.com/Phhofm/models/releases/tag/4xLSDIRCompact",
100
+ """Realistic
101
  Phhofm: Upscale small good quality photos to 4x their size. This is my first ever released self-trained sisr upscaling model."""],
102
  "4xLSDIRCompactC.pth": ["https://github.com/Phhofm/models/releases/download/4xLSDIRCompactC/4xLSDIRCompactC.pth",
103
+ "https://github.com/Phhofm/models/releases/tag/4xLSDIRCompactC",
104
+ """Compression Removal, JPEG, Realistic, Restoration
105
  Phhofm: 4x photo upscaler that handler jpg compression. Trying to extend my previous model to be able to handle compression (JPG 100-30) by manually altering the training dataset, since 4xLSDIRCompact cant handle compression. Use this instead of 4xLSDIRCompact if your photo has compression (like an image from the web)."""],
106
  "4xLSDIRCompactR.pth": ["https://github.com/Phhofm/models/releases/download/4xLSDIRCompactC/4xLSDIRCompactR.pth",
107
+ "https://github.com/Phhofm/models/releases/tag/4xLSDIRCompactC",
108
+ """Compression Removal, Realistic, Restoration
109
  Phhofm: 4x photo uspcaler that handles jpg compression, noise and slight. Extending my last 4xLSDIRCompact model to Real-ESRGAN, meaning trained on synthetic data instead to handle more kinds of degradations, it should be able to handle compression, noise, and slight blur."""],
110
  "4xLSDIRCompactN.pth": ["https://github.com/Phhofm/models/releases/download/4xLSDIRCompact3/4xLSDIRCompactC3.pth",
111
+ "https://github.com/Phhofm/models/releases/tag/4xLSDIRCompact3",
112
+ """Realistic
113
  Phhofm: Upscale good quality input photos to x4 their size. The original 4xLSDIRCompact a bit more trained, cannot handle degradation."""],
114
  "4xLSDIRCompactC3.pth": ["https://github.com/Phhofm/models/releases/download/4xLSDIRCompact3/4xLSDIRCompactC3.pth",
115
+ "https://github.com/Phhofm/models/releases/tag/4xLSDIRCompact3",
116
  """Compression Removal, JPEG, Realistic, Restoration
117
  Phhofm: Upscale compressed photos to x4 their size. Able to handle JPG compression (30-100)."""],
118
  "4xLSDIRCompactR3.pth": ["https://github.com/Phhofm/models/releases/download/4xLSDIRCompact3/4xLSDIRCompactR3.pth",
119
+ "https://github.com/Phhofm/models/releases/tag/4xLSDIRCompact3",
120
+ """Realistic, Restoration
121
  Phhofm: Upscale (degraded) photos to x4 their size. Trained on synthetic data, meant to handle more degradations."""],
122
  "4xLSDIRCompactCR3.pth": ["https://github.com/Phhofm/models/releases/download/4xLSDIRCompact3/4xLSDIRCompactCR3.pth",
123
+ "https://github.com/Phhofm/models/releases/tag/4xLSDIRCompact3",
124
+ """Phhofm: I am releasing the Series 3 from my 4xLSDIRCompact models. In general my suggestion is, if you have good quality input images use 4xLSDIRCompactN3, otherwise try 4xLSDIRCompactC3 which will be able to handle jpg compression and a bit of blur, or then 4xLSDIRCompactCR3, which is an interpolation between C3 and R3 to be able to handle a bit of noise additionally."""],
125
  "2xParimgCompact.pth": ["https://github.com/Phhofm/models/releases/download/2xParimgCompact/2xParimgCompact.pth",
126
+ "https://github.com/Phhofm/models/releases/tag/2xParimgCompact",
127
+ """Realistic
128
  Phhofm: A 2x photo upscaling compact model based on Microsoft's ImagePairs. This was one of the earliest models I started training and finished it now for release. As can be seen in the examples, this model will affect colors."""],
129
  "1xExposureCorrection_compact.pth": ["https://github.com/Phhofm/models/releases/download/1xExposureCorrection_compact/1xExposureCorrection_compact.pth",
130
+ "https://github.com/Phhofm/models/releases/tag/1xExposureCorrection_compact",
131
+ """Restoration
132
  Phhofm: This model is meant as an experiment to see if compact can be used to train on photos to exposure correct those using the pixel, perceptual, color, color and ldl losses. There is no brightness loss. Still it seems to kinda work."""],
133
  "1xUnderExposureCorrection_compact.pth": ["https://github.com/Phhofm/models/releases/download/1xExposureCorrection_compact/1xUnderExposureCorrection_compact.pth",
134
+ "https://github.com/Phhofm/models/releases/tag/1xExposureCorrection_compact",
135
+ """Restoration
136
  Phhofm: This model is meant as an experiment to see if compact can be used to train on underexposed images to exposure correct those using the pixel, perceptual, color, color and ldl losses. There is no brightness loss. Still it seems to kinda work."""],
137
  "1xOverExposureCorrection_compact.pth": ["https://github.com/Phhofm/models/releases/download/1xExposureCorrection_compact/1xOverExposureCorrection_compact.pth",
138
+ "https://github.com/Phhofm/models/releases/tag/1xExposureCorrection_compact",
139
+ """Restoration
140
  Phhofm: This model is meant as an experiment to see if compact can be used to train on overexposed images to exposure correct those using the pixel, perceptual, color, color and ldl losses. There is no brightness loss. Still it seems to kinda work."""],
141
  "2x-sudo-UltraCompact.pth": ["https://objectstorage.us-phoenix-1.oraclecloud.com/n/ax6ygfvpvzka/b/open-modeldb-files/o/2x-sudo-UltraCompact.pth",
142
+ "https://openmodeldb.info/models/2x-sudo-UltraCompact",
143
+ """Anime, Cartoon, Restoration
144
  sudo: Realtime animation restauration and doing stuff like deblur and compression artefact removal."""],
145
  "2x_AnimeJaNai_HD_V3_SuperUltraCompact.pth": ["https://github.com/the-database/mpv-upscale-2x_animejanai/releases/download/3.0.0/2x_AnimeJaNai_HD_V3_ModelsOnly.zip",
146
+ "https://openmodeldb.info/models/2x-AnimeJaNai-HD-V3-SuperUltraCompact",
147
+ """Anime, Compression Removal, Restoration
148
  the-database: Real-time 2x Real-ESRGAN Compact/UltraCompact/SuperUltraCompact models designed for upscaling 1080p anime to 4K."""],
149
  "2x_AnimeJaNai_HD_V3_UltraCompact.pth": ["https://github.com/the-database/mpv-upscale-2x_animejanai/releases/download/3.0.0/2x_AnimeJaNai_HD_V3_ModelsOnly.zip",
150
+ "https://openmodeldb.info/models/2x-AnimeJaNai-HD-V3-UltraCompact",
151
+ """Anime, Compression Removal, Restoration
152
  the-database: Real-time 2x Real-ESRGAN Compact/UltraCompact/SuperUltraCompact models designed for upscaling 1080p anime to 4K."""],
153
  "2x_AnimeJaNai_HD_V3_Compact.pth": ["https://github.com/the-database/mpv-upscale-2x_animejanai/releases/download/3.0.0/2x_AnimeJaNai_HD_V3_ModelsOnly.zip",
154
+ "https://openmodeldb.info/models/2x-AnimeJaNai-HD-V3-Compact",
155
+ """Anime, Compression Removal, Restoration
156
  the-database: Real-time 2x Real-ESRGAN Compact/UltraCompact/SuperUltraCompact models designed for upscaling 1080p anime to 4K."""],
157
  "RealESRGAN_x4plus_anime_6B.pth": ["https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth",
158
+ "https://github.com/xinntao/Real-ESRGAN/releases/tag/v0.2.2.4",
159
+ """Anime, Cartoon, Compression Removal, General Upscaler, JPEG, Realistic, Research, Restoration
160
  xinntao: We add RealESRGAN_x4plus_anime_6B.pth, which is optimized for anime images with much smaller model size."""],
161
  "RealESRGAN_x2plus.pth": ["https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.1/RealESRGAN_x2plus.pth",
162
+ "https://github.com/xinntao/Real-ESRGAN/releases/tag/v0.2.1",
163
+ """Compression Removal, General Upscaler, JPEG, Realistic, Research, Restoration
164
  xinntao: Add RealESRGAN_x2plus.pth model"""],
165
  "RealESRNet_x4plus.pth": ["https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.1/RealESRNet_x4plus.pth",
166
+ "https://github.com/xinntao/Real-ESRGAN/releases/tag/v0.1.1",
167
+ """Compression Removal, General Upscaler, JPEG, Realistic, Research, Restoration
168
  xinntao: This release is mainly for storing pre-trained models and executable files."""],
169
  "RealESRGAN_x4plus.pth": ["https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth",
170
+ "https://github.com/xinntao/Real-ESRGAN/releases/tag/v0.1.0",
171
+ """Compression Removal, General Upscaler, JPEG, Realistic, Research, Restoration
172
  xinntao: This release is mainly for storing pre-trained models and executable files."""],
173
  "4x-AnimeSharp.pth": ["https://huggingface.co/utnah/esrgan/resolve/main/4x-AnimeSharp.pth?download=true",
174
+ "https://openmodeldb.info/models/4x-AnimeSharp",
175
+ """Anime, Cartoon, Text
176
  Kim2091: Interpolation between 4x-UltraSharp and 4x-TextSharp-v0.5. Works amazingly on anime."""],
177
  "4x_IllustrationJaNai_V1_ESRGAN_135k.pth": ["https://drive.google.com/uc?export=download&confirm=1&id=1qpioSqBkB_IkSBhEAewSSNFt6qgkBimP",
178
+ "https://openmodeldb.info/models/4x-IllustrationJaNai-V1-DAT2",
179
+ """Anime, Cartoon, Compression Removal, Dehalftone, General Upscaler, JPEG, Manga, Restoration
180
  the-database: Model for color images including manga covers and color illustrations, digital art, visual novel art, artbooks, and more."""],
181
  "2x-sudo-RealESRGAN.pth": ["https://objectstorage.us-phoenix-1.oraclecloud.com/n/ax6ygfvpvzka/b/open-modeldb-files/o/2x-sudo-RealESRGAN.pth",
182
+ "https://openmodeldb.info/models/2x-sudo-RealESRGAN",
183
+ """Anime, Cartoon
184
  sudo: Tried to make the best 2x model there is for drawings."""],
185
  "2x-sudo-RealESRGAN-Dropout.pth": ["https://objectstorage.us-phoenix-1.oraclecloud.com/n/ax6ygfvpvzka/b/open-modeldb-files/o/2x-sudo-RealESRGAN-Dropout.pth",
186
+ "https://openmodeldb.info/models/2x-sudo-RealESRGAN-Dropout",
187
+ """Anime, Cartoon
188
  sudo: Tried to make the best 2x model there is for drawings."""],
189
  "4xNomos2_otf_esrgan.pth": ["https://github.com/Phhofm/models/releases/download/4xNomos2_otf_esrgan/4xNomos2_otf_esrgan.pth",
190
+ "https://github.com/Phhofm/models/releases/tag/4xNomos2_otf_esrgan",
191
+ """Compression Removal, JPEG, Realistic, Restoration
192
  Phhofm: Restoration, 4x ESRGAN model for photography, trained using the Real-ESRGAN otf degradation pipeline."""],
193
  "4xNomosWebPhoto_esrgan.pth": ["https://github.com/Phhofm/models/releases/download/4xNomosWebPhoto_esrgan/4xNomosWebPhoto_esrgan.pth",
194
+ "https://github.com/Phhofm/models/releases/tag/4xNomosWebPhoto_esrgan",
195
+ """Realistic, Restoration
196
  Phhofm: Restoration, 4x ESRGAN model for photography, trained with realistic noise, lens blur, jpg and webp re-compression."""],
197
  "4x_foolhardy_Remacri.pth": ["https://civitai.com/api/download/models/164821?type=Model&format=PickleTensor",
198
+ "https://openmodeldb.info/models/4x-Remacri",
199
+ """Original
200
  FoolhardyVEVO: A creation of BSRGAN with more details and less smoothing."""],
201
  "4x_foolhardy_Remacri_ExtraSmoother.pth": ["https://civitai.com/api/download/models/164822?type=Model&format=PickleTensor",
202
+ "https://openmodeldb.info/models/4x-Remacri",
203
+ """ExtraSmoother
204
  FoolhardyVEVO: A creation of BSRGAN with more details and less smoothing."""],
205
  "4xNomos8kDAT.pth": ["https://github.com/Phhofm/models/releases/download/4xNomos8kDAT/4xNomos8kDAT.pth",
206
+ "https://openmodeldb.info/models/4x-Nomos8kDAT",
207
+ """Anime, Compression Removal, General Upscaler, JPEG, Realistic, Restoration
208
  Phhofm: A 4x photo upscaler with otf jpg compression, blur and resize, trained on musl's Nomos8k_sfw dataset for realisic sr."""],
209
  "4x-DWTP-DS-dat2-v3.pth": ["https://objectstorage.us-phoenix-1.oraclecloud.com/n/ax6ygfvpvzka/b/open-modeldb-files/o/4x-DWTP-DS-dat2-v3.pth",
210
+ "https://openmodeldb.info/models/4x-DWTP-DS-dat2-v3",
211
+ """Dehalftone, Restoration
212
  umzi.x.dead: DAT descreenton model, designed to reduce discrepancies on tiles due to too much loss of the first version."""],
213
  "4xBHI_dat2_real.pth": ["https://github.com/Phhofm/models/releases/download/4xBHI_dat2_real/4xBHI_dat2_real.pth",
214
+ "https://github.com/Phhofm/models/releases/tag/4xBHI_dat2_real",
215
+ """Compression Removal, JPEG, Realistic
216
  Phhofm: 4x dat2 upscaling model for web and realistic images."""],
217
  "4xBHI_dat2_otf.pth": ["https://github.com/Phhofm/models/releases/download/4xBHI_dat2_otf/4xBHI_dat2_otf.pth",
218
+ "https://github.com/Phhofm/models/releases/tag/4xBHI_dat2_otf",
219
+ """Compression Removal, JPEG
220
  Phhofm: 4x dat2 upscaling model, trained with the real-esrgan otf pipeline on my bhi dataset."""],
221
  "4xBHI_dat2_multiblur.pth": ["https://github.com/Phhofm/models/releases/download/4xBHI_dat2_multiblurjpg/4xBHI_dat2_multiblur.pth",
222
+ "https://github.com/Phhofm/models/releases/tag/4xBHI_dat2_multiblurjpg",
223
+ """Phhofm: the 4xBHI_dat2_multiblur checkpoint (trained to 250000 iters), which cannot handle compression but might give just slightly better output on non-degraded input."""],
224
  "4xBHI_dat2_multiblurjpg.pth": ["https://github.com/Phhofm/models/releases/download/4xBHI_dat2_multiblurjpg/4xBHI_dat2_multiblurjpg.pth",
225
+ "https://github.com/Phhofm/models/releases/tag/4xBHI_dat2_multiblurjpg",
226
+ """Compression Removal, JPEG
227
  Phhofm: 4x dat2 upscaling model, trained with down_up,linear, cubic_mitchell, lanczos, gauss and box scaling algos, some average, gaussian and anisotropic blurs and jpg compression."""],
228
  "4x_IllustrationJaNai_V1_DAT2_190k.pth": ["https://drive.google.com/uc?export=download&confirm=1&id=1qpioSqBkB_IkSBhEAewSSNFt6qgkBimP",
229
+ "https://openmodeldb.info/models/4x-IllustrationJaNai-V1-DAT2",
230
+ """Anime, Cartoon, Compression Removal, Dehalftone, General Upscaler, JPEG, Manga, Restoration
231
  the-database: Model for color images including manga covers and color illustrations, digital art, visual novel art, artbooks, and more."""],
232
  "4x-PBRify_UpscalerDAT2_V1.pth": ["https://github.com/Kim2091/Kim2091-Models/releases/download/4x-PBRify_UpscalerDAT2_V1/4x-PBRify_UpscalerDAT2_V1.pth",
233
+ "https://github.com/Kim2091/Kim2091-Models/releases/tag/4x-PBRify_UpscalerDAT2_V1",
234
+ """Compression Removal, DDS, Game Textures, Restoration
235
  Kim2091: Yet another model in the PBRify_Remix series."""],
236
  "4xBHI_dat2_otf_nn.pth": ["https://github.com/Phhofm/models/releases/download/4xBHI_dat2_otf_nn/4xBHI_dat2_otf_nn.pth",
237
+ "https://github.com/Phhofm/models/releases/tag/4xBHI_dat2_otf_nn",
238
+ """Compression Removal, JPEG
239
  Phhofm: 4x dat2 upscaling model, trained with the real-esrgan otf pipeline but without noise, on my bhi dataset."""],
240
  "4xNomos8kSCHAT-L.pth": ["https://github.com/Phhofm/models/releases/download/4xNomos8kSCHAT/4xNomos8kSCHAT-L.pth",
241
+ "https://openmodeldb.info/models/4x-Nomos8kSCHAT-L",
242
+ """Anime, Compression Removal, General Upscaler, JPEG, Realistic, Restoration
243
  Phhofm: 4x photo upscaler with otf jpg compression and blur, trained on musl's Nomos8k_sfw dataset for realisic sr."""],
244
  "4xNomos8kSCHAT-S.pth": ["https://github.com/Phhofm/models/releases/download/4xNomos8kSCHAT/4xNomos8kSCHAT-S.pth",
245
+ "https://openmodeldb.info/models/4x-Nomos8kSCHAT-S",
246
+ """Anime, Compression Removal, General Upscaler, JPEG, Realistic, Restoration
247
  Phhofm: 4x photo upscaler with otf jpg compression and blur, trained on musl's Nomos8k_sfw dataset for realisic sr."""],
248
  "4xNomos8kHAT-L_otf.pth": ["https://github.com/Phhofm/models/releases/download/4xNomos8kHAT-L_otf/4xNomos8kHAT-L_otf.pth",
249
+ "https://openmodeldb.info/models/4x-Nomos8kHAT-L-otf",
250
+ """Faces, General Upscaler, Realistic, Restoration
251
  Phhofm: 4x photo upscaler trained with otf, handles some jpg compression, some blur and some noise."""],
252
  "4xBHI_small_hat-l.pth": ["https://github.com/Phhofm/models/releases/download/4xBHI_small_hat-l/4xBHI_small_hat-l.pth",
253
+ "https://github.com/Phhofm/models/releases/tag/4xBHI_small_hat-l",
254
  """Phhofm: 4x hat-l upscaling model for good quality input. This model does not handle any degradations."""],
255
  "4xHFA2k_ludvae_realplksr_dysample.pth": ["https://github.com/Phhofm/models/releases/download/4xHFA2k_ludvae_realplksr_dysample/4xHFA2k_ludvae_realplksr_dysample.pth",
256
+ "https://openmodeldb.info/models/4x-HFA2k-ludvae-realplksr-dysample",
257
+ """Anime, Compression Removal, Restoration
258
  Phhofm: A Dysample RealPLKSR 4x upscaling model for anime single-image resolution."""],
259
  "4xArtFaces_realplksr_dysample.pth": ["https://github.com/Phhofm/models/releases/download/4xArtFaces_realplksr_dysample/4xArtFaces_realplksr_dysample.pth",
260
+ "https://openmodeldb.info/models/4x-ArtFaces-realplksr-dysample",
261
+ """ArtFaces
262
  Phhofm: A Dysample RealPLKSR 4x upscaling model for art / painted faces."""],
263
  "4x-PBRify_RPLKSRd_V3.pth": ["https://github.com/Kim2091/Kim2091-Models/releases/download/4x-PBRify_RPLKSRd_V3/4x-PBRify_RPLKSRd_V3.pth",
264
+ "https://github.com/Kim2091/Kim2091-Models/releases/tag/4x-PBRify_RPLKSRd_V3",
265
+ """Compression Removal, DDS, Debanding, Dedither, Dehalo, Game Textures, Restoration
266
  Kim2091: This update brings a new upscaling model, 4x-PBRify_RPLKSRd_V3."""],
267
  "4xNomos2_realplksr_dysample.pth": ["https://github.com/Phhofm/models/releases/download/4xNomos2_realplksr_dysample/4xNomos2_realplksr_dysample.pth",
268
+ "https://openmodeldb.info/models/4x-Nomos2-realplksr-dysample",
269
+ """Compression Removal, JPEG, Realistic, Restoration
270
  Phhofm: A Dysample RealPLKSR 4x upscaling model that was trained with / handles jpg compression down to 70 on the Nomosv2 dataset."""],
271
  "2x-AnimeSharpV2_RPLKSR_Sharp.pth": ["https://github.com/Kim2091/Kim2091-Models/releases/download/2x-AnimeSharpV2_Set/2x-AnimeSharpV2_RPLKSR_Sharp.pth",
272
+ "https://github.com/Kim2091/Kim2091-Models/releases/tag/2x-AnimeSharpV2_Set",
273
+ """Anime, Compression Removal, Restoration
274
  Kim2091: This is my first anime model in years. Sharp: For heavily degraded sources."""],
275
  "2x-AnimeSharpV2_RPLKSR_Soft.pth": ["https://github.com/Kim2091/Kim2091-Models/releases/download/2x-AnimeSharpV2_Set/2x-AnimeSharpV2_RPLKSR_Soft.pth",
276
+ "https://github.com/Kim2091/Kim2091-Models/releases/tag/2x-AnimeSharpV2_Set",
277
+ """Anime, Compression Removal, Restoration
278
  Kim2091: This is my first anime model in years. Soft: For cleaner sources."""],
279
  "4xPurePhoto-RealPLSKR.pth": ["https://github.com/starinspace/StarinspaceUpscale/releases/download/Models/4xPurePhoto-RealPLSKR.pth",
280
+ "https://openmodeldb.info/models/4x-PurePhoto-RealPLSKR",
281
+ """AI Generated, Compression Removal, JPEG, Realistic, Restoration
282
  asterixcool: Skilled in working with cats, hair, parties, and creating clear images."""],
283
  "2x_Text2HD_v.1-RealPLKSR.pth": ["https://github.com/starinspace/StarinspaceUpscale/releases/download/Models/2x_Text2HD_v.1-RealPLKSR.pth",
284
+ "https://openmodeldb.info/models/2x-Text2HD-v-1",
285
+ """Compression Removal, Denoise, General Upscaler, JPEG, Restoration, Text
286
  asterixcool: The upscale model is specifically designed to enhance lower-quality text images."""],
287
  "2xVHS2HD-RealPLKSR.pth": ["https://github.com/starinspace/StarinspaceUpscale/releases/download/Models/2xVHS2HD-RealPLKSR.pth",
288
+ "https://openmodeldb.info/models/2x-VHS2HD",
289
+ """Compression Removal, Dehalo, Realistic, Restoration, Video Frame
290
  asterixcool: An advanced VHS recording model designed to enhance video quality by reducing artifacts."""],
291
  "4xNomosWebPhoto_RealPLKSR.pth": ["https://github.com/Phhofm/models/releases/download/4xNomosWebPhoto_RealPLKSR/4xNomosWebPhoto_RealPLKSR.pth",
292
+ "https://openmodeldb.info/models/4x-NomosWebPhoto-RealPLKSR",
293
+ """Realistic, Restoration
294
  Phhofm: 4x RealPLKSR model for photography, trained with realistic noise, lens blur, jpg and webp re-compression."""],
295
  "4xNomos2_hq_drct-l.pth": ["https://github.com/Phhofm/models/releases/download/4xNomos2_hq_drct-l/4xNomos2_hq_drct-l.pth",
296
+ "https://github.com/Phhofm/models/releases/tag/4xNomos2_hq_drct-l",
297
+ """General Upscaler, Realistic
298
  Phhofm: An drct-l 4x upscaling model, similiar to the 4xNomos2_hq_atd, 4xNomos2_hq_dat2 and 4xNomos2_hq_mosr models."""],
299
  "4xNomos2_hq_atd.pth": ["https://github.com/Phhofm/models/releases/download/4xNomos2_hq_atd/4xNomos2_hq_atd.pth",
300
+ "https://github.com/Phhofm/models/releases/tag/4xNomos2_hq_atd",
301
+ """General Upscaler, Realistic
302
  Phhofm: An atd 4x upscaling model, similiar to the 4xNomos2_hq_dat2 or 4xNomos2_hq_mosr models."""],
303
  "4xNomos2_hq_mosr.pth": ["https://github.com/Phhofm/models/releases/download/4xNomos2_hq_mosr/4xNomos2_hq_mosr.pth",
304
+ "https://github.com/Phhofm/models/releases/tag/4xNomos2_hq_mosr",
305
+ """General Upscaler, Realistic
306
  Phhofm: A 4x MoSR upscaling model, meant for non-degraded input."""],
307
  "2x-AnimeSharpV2_MoSR_Sharp.pth": ["https://github.com/Kim2091/Kim2091-Models/releases/download/2x-AnimeSharpV2_Set/2x-AnimeSharpV2_MoSR_Sharp.pth",
308
+ "https://github.com/Kim2091/Kim2091-Models/releases/tag/2x-AnimeSharpV2_Set",
309
+ """Anime, Compression Removal, Restoration
310
  Kim2091: This is my first anime model in years. Sharp: For heavily degraded sources."""],
311
  "2x-AnimeSharpV2_MoSR_Soft.pth": ["https://github.com/Kim2091/Kim2091-Models/releases/download/2x-AnimeSharpV2_Set/2x-AnimeSharpV2_MoSR_Soft.pth",
312
+ "https://github.com/Kim2091/Kim2091-Models/releases/tag/2x-AnimeSharpV2_Set",
313
+ """Anime, Compression Removal, Restoration
314
  Kim2091: This is my first anime model in years. Soft: For cleaner sources."""],
315
  "4xNomos8kSCSRFormer.pth": ["https://github.com/Phhofm/models/releases/download/4xNomos8kSCSRFormer/4xNomos8kSCSRFormer.pth",
316
+ "https://github.com/Phhofm/models/releases/tag/4xNomos8kSCSRFormer",
317
+ """Anime, Compression Removal, General Upscaler, JPEG, Realistic, Restoration
318
  Phhofm: 4x photo upscaler with otf jpg compression and blur, trained on musl's Nomos8k_sfw dataset for realisic sr."""],
319
  "4xFrankendataFullDegradation_SRFormer460K_g.pth": ["https://drive.google.com/uc?export=download&confirm=1&id=1PZrj-8ofxhORv_OgTVSoRt3dYi-BtiDj",
320
+ "https://openmodeldb.info/models/4x-Frankendata-FullDegradation-SRFormer",
321
+ """Compression Removal, Denoise, Realistic, Restoration
322
  Crustaceous D: 4x realistic upscaler that may also work for general purpose usage."""],
323
  "4xFrankendataPretrainer_SRFormer400K_g.pth": ["https://drive.google.com/uc?export=download&confirm=1&id=1SaKvpYYIm2Vj2m9GifUMlNCbmkE6JZmr",
324
+ "https://openmodeldb.info/models/4x-FrankendataPretainer-SRFormer",
325
+ """Realistic, Restoration
326
  Crustaceous D: 4x realistic upscaler that may also work for general purpose usage."""],
327
  "1xFrankenfixer_SRFormerLight_g.pth": ["https://drive.google.com/uc?export=download&confirm=1&id=1UJ0iyFn4IGNhPIgNgrQrBxYsdDloFc9I",
328
+ "https://openmodeldb.info/models/1x-Frankenfixer-SRFormerLight",
329
+ """Realistic, Restoration
330
  Crustaceous D: A 1x model designed to reduce artifacts and restore detail to images upscaled by 4xFrankendata_FullDegradation_SRFormer."""],
331
  }
332
 
 
418
  if "layers.0.blocks.0.attn.attns.0.rpe_biases" in loadnet:
419
  split_sizes = loadnet["layers.0.blocks.0.attn.attns.0.rpe_biases"][-1] + 1
420
  split_size = [int(x) for x in split_sizes]
421
+ model = DAT(img_size=img_size, in_chans=in_chans, embed_dim=embed_dim, split_size=split_size, depth=depth, num_heads=num_heads, expansion_factor=expansion_factor,
422
  qkv_bias=qkv_bias, resi_connection=resi_connection, upsampler=upsampler, upscale=netscale)
423
  elif upscale_type == "HAT":
424
  half = False
 
476
  ape = "absolute_pos_embed" in loadnet
477
  model = DRCT(in_chans=in_chans, img_size=64, window_size=window_size, compress_ratio=3, squeeze_factor=30,
478
  conv_scale=0.01, overlap_ratio=0.5, img_range=1., depths=depths, embed_dim=embed_dim, num_heads=num_heads,
479
+ mlp_ratio=mlp_ratio, qkv_bias=qkv_bias, ape=ape, patch_norm=patch_norm, use_checkpoint=False,
480
  upscale=netscale, upsampler=upsampler, resi_connection=resi_connection, gc=gc_adjust1)
481
  elif upscale_type == "ATD":
482
  half = False
 
563
  if nice_number == patches_resolution:
564
  img_size = nice_number
565
  break
566
+ model = SRFormer(img_size=img_size, in_chans=in_chans, embed_dim=embed_dim, depths=depths, num_heads=num_heads, window_size=window_size, mlp_ratio=mlp_ratio,
567
  qkv_bias=qkv_bias, qk_scale=None, ape=ape, patch_norm=patch_norm, upscale=netscale, upsampler=upsampler, resi_connection=resi_connection)
568
  if model:
569
  self.realesrganer = RealESRGANer(scale=netscale, model_path=os.path.join("weights", "upscale", upscale_model), model=model, tile=0, tile_pad=10, pre_pad=0, half=half)
 
665
  self.modelInUse = ""
666
  files = []
667
  unique_id = str(int(time.time()))
668
+ zip_cropf_path = os.path.join(OUTPUT_DIR, f"{unique_id}_cropped_faces{self.modelInUse}.zip")
669
  zipf_cropf = zipfile.ZipFile(zip_cropf_path, 'w', zipfile.ZIP_DEFLATED)
670
+ zip_restoref_path = os.path.join(OUTPUT_DIR, f"{unique_id}_restored_faces{self.modelInUse}.zip")
671
  zipf_restoref = zipfile.ZipFile(zip_restoref_path, 'w', zipfile.ZIP_DEFLATED)
672
+ zip_cmp_path = os.path.join(OUTPUT_DIR, f"{unique_id}_cmp{self.modelInUse}.zip")
673
  zipf_cmp = zipfile.ZipFile(zip_cmp_path, 'w', zipfile.ZIP_DEFLATED)
674
+ zip_restore_path = os.path.join(OUTPUT_DIR, f"{unique_id}_restored_images{self.modelInUse}.zip")
675
  zipf_restore = zipfile.ZipFile(zip_restore_path, 'w', zipfile.ZIP_DEFLATED)
676
  is_auto_split_upscale = True
677
  name_counters = defaultdict(int)
 
706
  cropped_faces, restored_aligned, bg_upsample_img = self.face_enhancer.enhance(img_cv2, has_aligned=False, only_center_face=face_detection_only_center, paste_back=True, bg_upsample_img=bg_upsample_img, eye_dist_threshold=face_detection_threshold)
707
  if cropped_faces and restored_aligned:
708
  for idx, (cropped_face, restored_face) in enumerate(zip(cropped_faces, restored_aligned)):
709
+ save_crop_path = os.path.join(OUTPUT_DIR, f"{basename}_{idx:02d}_cropped_faces{self.modelInUse}.png")
710
  self.imwriteUTF8(save_crop_path, cropped_face)
711
  zipf_cropf.write(save_crop_path, arcname=os.path.basename(save_crop_path))
712
+ save_restore_path = os.path.join(OUTPUT_DIR, f"{basename}_{idx:02d}_restored_faces{self.modelInUse}.png")
713
  self.imwriteUTF8(save_restore_path, restored_face)
714
  zipf_restoref.write(save_restore_path, arcname=os.path.basename(save_restore_path))
715
+ save_cmp_path = os.path.join(OUTPUT_DIR, f"{basename}_{idx:02d}_cmp{self.modelInUse}.png")
716
  cmp_img = np.concatenate((cropped_face, restored_face), axis=1)
717
  self.imwriteUTF8(save_cmp_path, cmp_img)
718
  zipf_cmp.write(save_cmp_path, arcname=os.path.basename(save_cmp_path))
 
726
  restored_img = bg_upsample_img
727
  timer.report()
728
  if restored_img is None:
729
+ print(f"Warning: Processing resulted in no image for '{img_path}'. Skipping output.")
730
+ continue
731
  if save_as_png:
732
  final_extension = ".png"
733
  else:
734
  final_extension = ".png" if img_mode == "RGBA" else (extension if extension else ".jpg")
735
+ save_path = os.path.join(OUTPUT_DIR, f"{basename}{self.modelInUse}{final_extension}")
736
  self.imwriteUTF8(save_path, restored_img)
737
  zipf_restore.write(save_path, arcname=os.path.basename(save_path))
738
  restored_img = cv2.cvtColor(restored_img, cv2.COLOR_BGR2RGB)
 
916
  for f in files:
917
  raw_bytes = await f.read()
918
  safe_name = os.path.basename(f.filename)
919
+ save_path = os.path.join(INPUT_DIR, f"{int(time.time()*1000)}_{safe_name}")
920
  with open(save_path, 'wb') as out:
921
  out.write(raw_bytes)
922
  saved_paths.append(save_path)
 
982
  @fastapi_app.get("/download/{filename}")
983
  def download(filename: str, _: bool = Depends(_verify_bearer_token)):
984
  safe_name = os.path.basename(filename)
985
+ for p in [os.path.join(OUTPUT_DIR, safe_name), os.path.join(INPUT_DIR, safe_name)]:
986
  if os.path.isfile(p):
987
  return FileResponse(p, filename=safe_name)
988
  raise HTTPException(status_code=404, detail="File not found")