Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -133,65 +133,6 @@ def send_it1(inputs, noise_level, style, proc=proc1):
|
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
-
os.system("pip freeze")
|
| 137 |
-
# download weights
|
| 138 |
-
if not os.path.exists('realesr-general-x4v3.pth'):
|
| 139 |
-
os.system("wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-x4v3.pth -P .")
|
| 140 |
-
if not os.path.exists('GFPGANv1.2.pth'):
|
| 141 |
-
os.system("wget https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.2.pth -P .")
|
| 142 |
-
if not os.path.exists('GFPGANv1.3.pth'):
|
| 143 |
-
os.system("wget https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth -P .")
|
| 144 |
-
if not os.path.exists('GFPGANv1.4.pth'):
|
| 145 |
-
os.system("wget https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.4.pth -P .")
|
| 146 |
-
if not os.path.exists('RestoreFormer.pth'):
|
| 147 |
-
os.system("wget https://github.com/TencentARC/GFPGAN/releases/download/v1.3.4/RestoreFormer.pth -P .")
|
| 148 |
-
if not os.path.exists('CodeFormer.pth'):
|
| 149 |
-
os.system("wget https://github.com/TencentARC/GFPGAN/releases/download/v1.3.4/CodeFormer.pth -P .")
|
| 150 |
-
|
| 151 |
-
torch.hub.download_url_to_file(
|
| 152 |
-
'https://thumbs.dreamstime.com/b/tower-bridge-traditional-red-bus-black-white-colors-view-to-tower-bridge-london-black-white-colors-108478942.jpg',
|
| 153 |
-
'a1.jpg')
|
| 154 |
-
torch.hub.download_url_to_file(
|
| 155 |
-
'https://media.istockphoto.com/id/523514029/photo/london-skyline-b-w.jpg?s=612x612&w=0&k=20&c=kJS1BAtfqYeUDaORupj0sBPc1hpzJhBUUqEFfRnHzZ0=',
|
| 156 |
-
'a2.jpg')
|
| 157 |
-
torch.hub.download_url_to_file(
|
| 158 |
-
'https://i.guim.co.uk/img/media/06f614065ed82ca0e917b149a32493c791619854/0_0_3648_2789/master/3648.jpg?width=700&quality=85&auto=format&fit=max&s=05764b507c18a38590090d987c8b6202',
|
| 159 |
-
'a3.jpg')
|
| 160 |
-
torch.hub.download_url_to_file(
|
| 161 |
-
'https://i.pinimg.com/736x/46/96/9e/46969eb94aec2437323464804d27706d--victorian-london-victorian-era.jpg',
|
| 162 |
-
'a4.jpg')
|
| 163 |
-
|
| 164 |
-
# background enhancer with RealESRGAN
|
| 165 |
-
model = SRVGGNetCompact(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=32, upscale=4, act_type='prelu')
|
| 166 |
-
model_path = 'realesr-general-x4v3.pth'
|
| 167 |
-
half = True if torch.cuda.is_available() else False
|
| 168 |
-
upsampler = RealESRGANer(scale=4, model_path=model_path, model=model, tile=0, tile_pad=10, pre_pad=0, half=half)
|
| 169 |
-
|
| 170 |
-
os.makedirs('output', exist_ok=True)
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
# def inference(img, version, scale, weight):
|
| 174 |
-
def inference(img, version, scale):
|
| 175 |
-
# weight /= 100
|
| 176 |
-
print(img, version, scale)
|
| 177 |
-
try:
|
| 178 |
-
extension = os.path.splitext(os.path.basename(str(img)))[1]
|
| 179 |
-
img = cv2.imread(img, cv2.IMREAD_UNCHANGED)
|
| 180 |
-
if len(img.shape) == 3 and img.shape[2] == 4:
|
| 181 |
-
img_mode = 'RGBA'
|
| 182 |
-
elif len(img.shape) == 2: # for gray inputs
|
| 183 |
-
img_mode = None
|
| 184 |
-
img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
|
| 185 |
-
else:
|
| 186 |
-
img_mode = None
|
| 187 |
-
|
| 188 |
-
h, w = img.shape[0:2]
|
| 189 |
-
if h < 300:
|
| 190 |
-
img = cv2.resize(img, (w * 2, h * 2), interpolation=cv2.INTER_LANCZOS4)
|
| 191 |
-
|
| 192 |
-
if version == 'v1.2':
|
| 193 |
-
face_enhancer = GFPGANer(
|
| 194 |
-
model_path='GFPGANv1.2.pth', upscale=2, arch='clean', channel_multiplier=2, bg_upsampler=upsampler)
|
| 195 |
os.system("pip freeze")
|
| 196 |
# download weights
|
| 197 |
if not os.path.exists('realesr-general-x4v3.pth'):
|
|
@@ -291,6 +232,7 @@ def inference(img, version, scale):
|
|
| 291 |
return None, None
|
| 292 |
|
| 293 |
|
|
|
|
| 294 |
with gr.Blocks(
|
| 295 |
css=".gradio-container {background-color: #FDF5E6;} .dark .gradio-container {background-color: black;} footer{display:none !important;}",
|
| 296 |
) as demo:
|
|
|
|
| 133 |
|
| 134 |
|
| 135 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
os.system("pip freeze")
|
| 137 |
# download weights
|
| 138 |
if not os.path.exists('realesr-general-x4v3.pth'):
|
|
|
|
| 232 |
return None, None
|
| 233 |
|
| 234 |
|
| 235 |
+
|
| 236 |
with gr.Blocks(
|
| 237 |
css=".gradio-container {background-color: #FDF5E6;} .dark .gradio-container {background-color: black;} footer{display:none !important;}",
|
| 238 |
) as demo:
|