zhiweili
commited on
Commit
Β·
3772beb
1
Parent(s):
44785f8
test gfpgan
Browse files- app_onediff.py +32 -1
- requirements.txt +4 -0
app_onediff.py
CHANGED
|
@@ -4,6 +4,7 @@ import time
|
|
| 4 |
import torch
|
| 5 |
import os
|
| 6 |
import json
|
|
|
|
| 7 |
|
| 8 |
from diffusers import (
|
| 9 |
DDPMScheduler,
|
|
@@ -11,6 +12,20 @@ from diffusers import (
|
|
| 11 |
AutoencoderKL,
|
| 12 |
)
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
os.system("python3 -m pip --no-cache-dir install --pre nexfort -f https://github.com/siliconflow/nexfort_releases/releases/expanded_assets/torch2.4.1_cu121")
|
| 15 |
os.system("git clone https://github.com/siliconflow/onediff.git")
|
| 16 |
os.system("cd onediff && python3 -m pip install .")
|
|
@@ -44,7 +59,23 @@ base_pipe = AutoPipelineForText2Image.from_pretrained(
|
|
| 44 |
)
|
| 45 |
base_pipe.to(device)
|
| 46 |
|
| 47 |
-
base_pipe = nexfort_compile(base_pipe)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
def create_demo() -> gr.Blocks:
|
| 50 |
|
|
|
|
| 4 |
import torch
|
| 5 |
import os
|
| 6 |
import json
|
| 7 |
+
import subprocess
|
| 8 |
|
| 9 |
from diffusers import (
|
| 10 |
DDPMScheduler,
|
|
|
|
| 12 |
AutoencoderKL,
|
| 13 |
)
|
| 14 |
|
| 15 |
+
def runcmd(cmd, verbose = False, *args, **kwargs):
|
| 16 |
+
|
| 17 |
+
process = subprocess.Popen(
|
| 18 |
+
cmd,
|
| 19 |
+
stdout = subprocess.PIPE,
|
| 20 |
+
stderr = subprocess.PIPE,
|
| 21 |
+
text = True,
|
| 22 |
+
shell = True
|
| 23 |
+
)
|
| 24 |
+
std_out, std_err = process.communicate()
|
| 25 |
+
if verbose:
|
| 26 |
+
print(std_out.strip(), std_err)
|
| 27 |
+
pass
|
| 28 |
+
|
| 29 |
os.system("python3 -m pip --no-cache-dir install --pre nexfort -f https://github.com/siliconflow/nexfort_releases/releases/expanded_assets/torch2.4.1_cu121")
|
| 30 |
os.system("git clone https://github.com/siliconflow/onediff.git")
|
| 31 |
os.system("cd onediff && python3 -m pip install .")
|
|
|
|
| 59 |
)
|
| 60 |
base_pipe.to(device)
|
| 61 |
|
| 62 |
+
# base_pipe = nexfort_compile(base_pipe)
|
| 63 |
+
|
| 64 |
+
from gfpgan.utils import GFPGANer
|
| 65 |
+
from basicsr.archs.srvgg_arch import SRVGGNetCompact
|
| 66 |
+
from realesrgan.utils import RealESRGANer
|
| 67 |
+
|
| 68 |
+
if not os.path.exists('GFPGANv1.4.pth'):
|
| 69 |
+
runcmd("wget https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.4.pth -P .")
|
| 70 |
+
if not os.path.exists('realesr-general-x4v3.pth'):
|
| 71 |
+
runcmd("wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-x4v3.pth -P .")
|
| 72 |
+
|
| 73 |
+
model = SRVGGNetCompact(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=32, upscale=4, act_type='prelu')
|
| 74 |
+
model_path = 'realesr-general-x4v3.pth'
|
| 75 |
+
half = True if torch.cuda.is_available() else False
|
| 76 |
+
upsampler = RealESRGANer(scale=4, model_path=model_path, model=model, tile=0, tile_pad=10, pre_pad=0, half=half)
|
| 77 |
+
|
| 78 |
+
face_enhancer = GFPGANer(model_path='GFPGANv1.4.pth', upscale=2, arch='clean', channel_multiplier=2, bg_upsampler=upsampler)
|
| 79 |
|
| 80 |
def create_demo() -> gr.Blocks:
|
| 81 |
|
requirements.txt
CHANGED
|
@@ -5,3 +5,7 @@ diffusers
|
|
| 5 |
transformers
|
| 6 |
accelerate
|
| 7 |
spaces
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
transformers
|
| 6 |
accelerate
|
| 7 |
spaces
|
| 8 |
+
gfpgan
|
| 9 |
+
facexlib
|
| 10 |
+
realesrgan
|
| 11 |
+
basicsr
|