Spaces:
Running
Running
yizhangliu
commited on
Commit
•
a5ca5a6
1
Parent(s):
0e6e5ed
Update app.py
Browse files
app.py
CHANGED
@@ -14,12 +14,68 @@ from matplotlib import pyplot as plt
|
|
14 |
from torchvision import transforms
|
15 |
# from diffusers import DiffusionPipeline
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
from share_btn import community_icon_html, loading_icon_html, share_js
|
18 |
|
19 |
HF_TOKEN_SD = os.environ.get('HF_TOKEN_SD') or True
|
20 |
|
21 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
'''
|
24 |
pipe = DiffusionPipeline.from_pretrained("runwayml/stable-diffusion-inpainting", dtype=torch.float16, revision="fp16", use_auth_token=auth_token).to(device)
|
25 |
|
|
|
14 |
from torchvision import transforms
|
15 |
# from diffusers import DiffusionPipeline
|
16 |
|
17 |
+
import io
|
18 |
+
import multiprocessing
|
19 |
+
import random
|
20 |
+
import time
|
21 |
+
import imghdr
|
22 |
+
from pathlib import Path
|
23 |
+
from typing import Union
|
24 |
+
# from loguru import logger
|
25 |
+
|
26 |
+
from lama_cleaner.model_manager import ModelManager
|
27 |
+
from lama_cleaner.schema import Config
|
28 |
+
|
29 |
+
try:
|
30 |
+
torch._C._jit_override_can_fuse_on_cpu(False)
|
31 |
+
torch._C._jit_override_can_fuse_on_gpu(False)
|
32 |
+
torch._C._jit_set_texpr_fuser_enabled(False)
|
33 |
+
torch._C._jit_set_nvfuser_enabled(False)
|
34 |
+
except:
|
35 |
+
pass
|
36 |
+
|
37 |
+
from lama_cleaner.helper import (
|
38 |
+
load_img,
|
39 |
+
numpy_to_bytes,
|
40 |
+
resize_max_size,
|
41 |
+
)
|
42 |
+
|
43 |
+
NUM_THREADS = str(multiprocessing.cpu_count())
|
44 |
+
|
45 |
+
# fix libomp problem on windows https://github.com/Sanster/lama-cleaner/issues/56
|
46 |
+
os.environ["KMP_DUPLICATE_LIB_OK"] = "True"
|
47 |
+
|
48 |
+
os.environ["OMP_NUM_THREADS"] = NUM_THREADS
|
49 |
+
os.environ["OPENBLAS_NUM_THREADS"] = NUM_THREADS
|
50 |
+
os.environ["MKL_NUM_THREADS"] = NUM_THREADS
|
51 |
+
os.environ["VECLIB_MAXIMUM_THREADS"] = NUM_THREADS
|
52 |
+
os.environ["NUMEXPR_NUM_THREADS"] = NUM_THREADS
|
53 |
+
if os.environ.get("CACHE_DIR"):
|
54 |
+
os.environ["TORCH_HOME"] = os.environ["CACHE_DIR"]
|
55 |
+
|
56 |
+
BUILD_DIR = os.environ.get("LAMA_CLEANER_BUILD_DIR", "app/build")
|
57 |
+
|
58 |
+
|
59 |
from share_btn import community_icon_html, loading_icon_html, share_js
|
60 |
|
61 |
HF_TOKEN_SD = os.environ.get('HF_TOKEN_SD') or True
|
62 |
|
63 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
64 |
|
65 |
+
def diffuser_callback(i, t, latents):
|
66 |
+
pass
|
67 |
+
|
68 |
+
model = ModelManager(
|
69 |
+
name='lama',
|
70 |
+
device=device,
|
71 |
+
hf_access_token=HF_TOKEN_SD,
|
72 |
+
sd_disable_nsfw=False,
|
73 |
+
sd_cpu_textencoder=True,
|
74 |
+
sd_run_local=True,
|
75 |
+
callback=diffuser_callback,
|
76 |
+
)
|
77 |
+
|
78 |
+
|
79 |
'''
|
80 |
pipe = DiffusionPipeline.from_pretrained("runwayml/stable-diffusion-inpainting", dtype=torch.float16, revision="fp16", use_auth_token=auth_token).to(device)
|
81 |
|