File size: 5,416 Bytes
2e40cec
68e098f
eea7d12
2e40cec
bfe0a04
a8f5725
2e40cec
4ddd13d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4fb9833
e453372
 
 
 
4ddd13d
 
4fb9833
68e098f
4fb9833
 
aeb7cb4
4fb9833
 
7815fb5
937ea93
eea7d12
 
 
 
 
 
 
a65d535
4fb9833
a65d535
 
4fb9833
a65d535
 
69b2ced
 
4fb9833
69b2ced
 
4fb9833
 
70d6477
4fb9833
2069ee0
68e098f
 
 
 
35a15c6
18a36b2
 
 
e453372
9cda3f2
4ddd13d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0607a3e
18a36b2
 
ff1294b
0607a3e
9cda3f2
6696be0
68e098f
 
35a15c6
b110321
 
 
 
b2f67f7
b110321
 
 
9cda3f2
2ec47eb
68e098f
 
b110321
 
 
058ee47
b110321
 
02a57d7
b110321
02a57d7
2ec47eb
f8ac765
b110321
68e098f
 
 
 
 
 
 
 
 
 
 
b110321
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import modal
import gradio as gr 
import numpy as np 

f = modal.Cls.lookup("casa-interior-hf-v3", "DesignModel")
f_gc = modal.Cls.lookup("casa-interior-gc-v1", "GetProduct") 

# def casa_ai_run_tab1(image=None, room_type=None, interior_style=None, objects=None): 
    
#     if image is None: 
#         print('Please provide image of empty room to design')
#         return None

#     if (room_type is None or interior_style is None or objects is None): 
#         print('Please select all three (Room type, Interior Style and Objects')
#         return None

#     objects_str = ", ".join(objects)
#     text = f"A {room_type} in style of {interior_style} with {objects_str}."
    
#     result_image = f.inference.remote("tab1", image, text)
#     return result_image

def casa_ai_run_tab1(image=None, text=None): 
    
    if image is None: 
        print('Please provide image of empty room to design')
        return None

    if text is None: 
        print('Please provide a text prompt')
        return None

    result_image = f.inference.remote("tab1", image, text)
    return result_image

def casa_ai_run_tab2(dict=None, text=None):
    
    image = dict["background"].convert("RGB")
    mask = dict["layers"][0].convert('L')

    if np.sum(np.array(mask)) == 0: 
        mask = None 
        
    if mask is None: 
        print('Please provide a mask over the object you want to generate again.')
        
    if image is None and text is None: 
        print('Please provide context in form of image, text')
        return None
    
    result_image = f.inference.remote("tab2", image, text, mask)
    return result_image

def casa_ai_run_tab3(dict=None):
    selected_crop = dict["layers"][0].convert("RGB")
    
    if selected_crop is None: 
        print('Please provide cropped object')
        return None
    
    result_image = f_gc.inference.remote(selected_crop)
    return result_image

with gr.Blocks() as casa:
    title = "Casa-AI Demo"
    description = "A Gradio interface to use CasaAI for virtual staging"

    with gr.Tab("Reimagine"):
        with gr.Row():
            with gr.Column():
                inputs = [
                            gr.Image(sources='upload', type="pil", label="Upload"), 
                            gr.Textbox(label="Room description.")
                            # gr.Dropdown(
                            #             label="Room type",
                            #             choices=["Living Room", "Bedroom", "Home Office", "Dining Room", "Kitchen", "Bathroom"],
                            #             multiselect=False
                            #         ), 
                            # gr.Dropdown(
                            #             label="Interior Style",
                            #             choices=["Modern", "Traditional", "Contemporary", "Minimalist", "Rustic", "Industrial", "Scandinavian"],
                            #             multiselect=False
                            #         ), 
                            # gr.Dropdown(
                            #             label="Objects",
                            #             choices=["Sofa", "Bed", "Table", "Chair", "Fridge", "Dinning table", "Coffee table"],
                            #             multiselect=True
                            #         ),
                        ]
            with gr.Column():
                outputs = [gr.Image(label="Generated room image")]

        
        submit_btn = gr.Button("Generate!")
        submit_btn.click(casa_ai_run_tab1, inputs=inputs, outputs=outputs)

        
    with gr.Tab("Redesign"):
        with gr.Row():
            with gr.Column():
                inputs = [
                            gr.ImageEditor(sources='upload', brush=gr.Brush(colors=["#FFFFFF"]), elem_id="image_upload", type="pil", label="Upload", layers=False, eraser=True, transforms=[]),
                            gr.Textbox(label="Description for redesigning masked object")]
            with gr.Column():
                outputs = [gr.Image(label="Image with new designed object")]
                
        submit_btn = gr.Button("Redesign!")
        submit_btn.click(casa_ai_run_tab2, inputs=inputs, outputs=outputs)

    with gr.Tab("Recommendation"):
        with gr.Row():
            with gr.Column():
                inputs = [
                            gr.ImageEditor(sources='upload', elem_id="image_upload", type="pil", label="Upload", layers=False, eraser=False, brush=False, transforms=['crop']),
                            ]
            with gr.Column():
                outputs = [gr.Gallery(label="Similar products")]
                
        submit_btn = gr.Button("Find similar products!")
        submit_btn.click(casa_ai_run_tab3, inputs=inputs, outputs=outputs)

casa.launch()

# demo = gr.Interface(casa_ai_run,
#                     inputs = [gr.ImageEditor(sources='upload', brush=gr.Brush(colors=["#FFFFFF"]), elem_id="image_upload", type="pil", label="Upload", layers=False, eraser=True, transforms=[]),
#                               gr.Textbox(label="Prompt to design room"), 
#                               ],
#                     outputs = [
#                               gr.Image(label="Generated room image"),
#                               ],
#                     title = title,
#                     description = description,
#                     )
# demo.launch()