Spaces:
Running
on
Zero
Running
on
Zero
Update codebase.md
Browse files- codebase.md +25 -27
codebase.md
CHANGED
|
@@ -1,30 +1,28 @@
|
|
| 1 |
-
# preprocess.py
|
| 2 |
|
| 3 |
-
|
| 4 |
-
import
|
| 5 |
-
import
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
self.
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
def __call__(self, image: PIL.Image.Image, **kwargs) -> PIL.Image.Image:
|
| 28 |
return self.model(image, **kwargs)
|
| 29 |
```
|
| 30 |
|
|
@@ -839,5 +837,5 @@ from .normalbae import NormalBaeDetector
|
|
| 839 |
# from .segment_anything import SamDetector
|
| 840 |
# from .shuffle import ContentShuffleDetector
|
| 841 |
# from .dwpose import DWposeDetector
|
| 842 |
-
|
| 843 |
|
|
|
|
|
|
|
| 1 |
|
| 2 |
+
import PIL.Image
|
| 3 |
+
import torch, gc
|
| 4 |
+
from controlnet_aux_local import NormalBaeDetector#, CannyDetector
|
| 5 |
+
|
| 6 |
+
class Preprocessor:
|
| 7 |
+
MODEL_ID = "lllyasviel/Annotators"
|
| 8 |
+
|
| 9 |
+
def __init__(self):
|
| 10 |
+
self.model = None
|
| 11 |
+
self.name = ""
|
| 12 |
+
|
| 13 |
+
def load(self, name: str) -> None:
|
| 14 |
+
if name == self.name:
|
| 15 |
+
return
|
| 16 |
+
elif name == "NormalBae":
|
| 17 |
+
print("Loading NormalBae")
|
| 18 |
+
self.model = NormalBaeDetector.from_pretrained(self.MODEL_ID).to("cuda")
|
| 19 |
+
torch.cuda.empty_cache()
|
| 20 |
+
self.name = name
|
| 21 |
+
else:
|
| 22 |
+
raise ValueError
|
| 23 |
+
return
|
| 24 |
+
|
| 25 |
+
def __call__(self, image: PIL.Image.Image, **kwargs) -> PIL.Image.Image:
|
|
|
|
| 26 |
return self.model(image, **kwargs)
|
| 27 |
```
|
| 28 |
|
|
|
|
| 837 |
# from .segment_anything import SamDetector
|
| 838 |
# from .shuffle import ContentShuffleDetector
|
| 839 |
# from .dwpose import DWposeDetector
|
| 840 |
+
|
| 841 |
|