Spaces:
Build error
Build error
Commit
·
9cc032a
1
Parent(s):
51ed1d2
Initial commit
Browse files
app.py
CHANGED
@@ -1,23 +1,5 @@
|
|
1 |
from src.designgenie.interfaces import GradioApp
|
2 |
|
3 |
-
|
4 |
-
# def run_pipeline():
|
5 |
-
# pipe = InpaintPipeline(
|
6 |
-
# segmentation_model_name="mask2former",
|
7 |
-
# diffusion_model_name="controlnet_inpaint",
|
8 |
-
# control_model_name="mlsd",
|
9 |
-
# images_root="/home/nader/Projects/DesignGenie/assets/images/",
|
10 |
-
# prompts_path="/home/nader/Projects/DesignGenie/assets/prompts.txt",
|
11 |
-
# image_size=(768, 512),
|
12 |
-
# image_extensions=(".jpg", ".jpeg", ".png", ".webp"),
|
13 |
-
# )
|
14 |
-
|
15 |
-
# results = pipe.run()
|
16 |
-
|
17 |
-
# for i, images in enumerate(results):
|
18 |
-
# for j, image in enumerate(images):
|
19 |
-
# image.save(f"./assets/results/result_{i}_{j}.png")
|
20 |
-
|
21 |
if __name__ == "__main__":
|
22 |
app = GradioApp()
|
23 |
-
app.interface.launch(
|
|
|
1 |
from src.designgenie.interfaces import GradioApp
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
if __name__ == "__main__":
|
4 |
app = GradioApp()
|
5 |
+
app.interface.launch()
|
examples/notebooks/demo_controlnet.ipynb
DELETED
The diff for this file is too large to render.
See raw diff
|
|
examples/notebooks/demo_sam.ipynb
DELETED
The diff for this file is too large to render.
See raw diff
|
|
src/designgenie/__init__.py
CHANGED
@@ -1 +0,0 @@
|
|
1 |
-
from .pipelines import InpaintPipeline
|
|
|
|
src/designgenie/pipelines/__init__.py
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
from .inpaint_pipeline import InpaintPipeline
|
|
|
|
src/designgenie/pipelines/inpaint_pipeline.py
DELETED
@@ -1,81 +0,0 @@
|
|
1 |
-
from typing import Any, Dict, List, Optional, Tuple, Union
|
2 |
-
import torch
|
3 |
-
from torch.utils.data import DataLoader
|
4 |
-
from torchvision.transforms.functional import to_pil_image
|
5 |
-
|
6 |
-
from ..data import ImageFolderDataset
|
7 |
-
from ..models import create_diffusion_model, create_segmentation_model
|
8 |
-
from ..utils import get_masked_images
|
9 |
-
|
10 |
-
|
11 |
-
class InpaintPipeline:
|
12 |
-
def __init__(
|
13 |
-
self,
|
14 |
-
segmentation_model_name: str,
|
15 |
-
diffusion_model_name: str,
|
16 |
-
control_model_name: str,
|
17 |
-
images_root: str,
|
18 |
-
prompts_path: Optional[str] = None,
|
19 |
-
sd_model_name: Optional[str] = "runwayml/stable-diffusion-inpainting",
|
20 |
-
image_size: Optional[Tuple[int, int]] = (512, 512),
|
21 |
-
image_extensions: Optional[Tuple[str]] = (".jpg", ".jpeg", ".png", ".webp"),
|
22 |
-
segmentation_model_size: Optional[str] = "large",
|
23 |
-
):
|
24 |
-
self.segmentation_model = create_segmentation_model(
|
25 |
-
segmentation_model_name=segmentation_model_name,
|
26 |
-
model_size=segmentation_model_size,
|
27 |
-
)
|
28 |
-
|
29 |
-
self.diffusion_model = create_diffusion_model(
|
30 |
-
diffusion_model_name=diffusion_model_name,
|
31 |
-
control_model_name=control_model_name,
|
32 |
-
sd_model_name=sd_model_name,
|
33 |
-
)
|
34 |
-
|
35 |
-
self.data_loader = self.build_data_loader(
|
36 |
-
images_root=images_root,
|
37 |
-
prompts_path=prompts_path,
|
38 |
-
image_size=image_size,
|
39 |
-
image_extensions=image_extensions,
|
40 |
-
)
|
41 |
-
|
42 |
-
def build_data_loader(
|
43 |
-
self,
|
44 |
-
images_root: str,
|
45 |
-
prompts_path: Optional[str] = None,
|
46 |
-
image_size: Optional[Tuple[int, int]] = (512, 512),
|
47 |
-
image_extensions: Optional[Tuple[str]] = (".jpg", ".jpeg", ".png", ".webp"),
|
48 |
-
batch_size: Optional[int] = 1,
|
49 |
-
) -> DataLoader:
|
50 |
-
dataset = ImageFolderDataset(
|
51 |
-
images_root, prompts_path, image_size, image_extensions
|
52 |
-
)
|
53 |
-
data_loader = DataLoader(
|
54 |
-
dataset, batch_size=batch_size, shuffle=False, num_workers=8
|
55 |
-
)
|
56 |
-
|
57 |
-
return data_loader
|
58 |
-
|
59 |
-
def run(self, data_loader: Optional[DataLoader] = None) -> List[Dict[str, Any]]:
|
60 |
-
if data_loader is not None:
|
61 |
-
self.data_loader = data_loader
|
62 |
-
|
63 |
-
results = []
|
64 |
-
for idx, (images, prompts) in enumerate(self.data_loader):
|
65 |
-
images = [to_pil_image(img) for img in images]
|
66 |
-
|
67 |
-
semantic_maps = self.segmentation_model.process(images)
|
68 |
-
|
69 |
-
object_masks = [
|
70 |
-
get_object_mask(seg_map, class_id=0) for seg_map in semantic_maps
|
71 |
-
]
|
72 |
-
|
73 |
-
outputs = self.diffusion_model.process(
|
74 |
-
images=images,
|
75 |
-
prompts=[prompts[0]],
|
76 |
-
mask_images=object_masks,
|
77 |
-
negative_prompt="monochrome, lowres, bad anatomy, worst quality, low quality",
|
78 |
-
)
|
79 |
-
results += outputs["output_images"]
|
80 |
-
|
81 |
-
return results
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|