File size: 16,584 Bytes
56b65c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
import gradio as gr
from perfect_redesign.main import flow as perfect_redesign_flow
from sketch_design.main import flow as sketch_to_render_flow
import random
import os

def get_image_path():
    return os.path.join(os.getcwd(), "instruction_assets/design_styles.png")

with gr.Blocks(theme='JohnSmith9982/small_and_pretty') as demo:
# with gr.Blocks() as demo:
    gr.HTML(
    """
    <h1 style="font-size: 3.5em; text-align: center; color: #02c160; font-weight: bold;">Architecture Render Bot</h1>
    """
)
    
    with gr.Tabs():
        

        with gr.Tab("Design Process"):

            with gr.Tabs():
                 
                with gr.Tab("Perfect Redesign (Interior)"):
                    with gr.Row():
                        with gr.Column():
                            with gr.Row(scale=1):
                                image_upload_pr = gr.Image(label="Upload an Image", type="filepath")
                    
                        # Input for user prompt and button to start the design process

                        with gr.Column():
                            # with gr.Column(scale=1, min_width=30):
                                design_output_pr = gr.Image(label="Design Output")

                    with gr.Row():
                            # with gr.Column(scale=1, min_width=30):
                            user_prompt_input_pr = gr.Textbox(label="Enter your Prompt", placeholder="A bedroom in a scandanavian style.")
                    # Output for the design process
                    with gr.Row():
                        # with gr.Column(scale=1, min_width=30):
                            start_btn_pr = gr.Button("Start Design Process")

                with gr.Tab("Sketch to Render (Interior)"):
                    with gr.Row():
                        with gr.Column():
                            with gr.Row(scale=1):
                                image_upload_sr = gr.Image(label="Upload an Image", type="filepath")
                    
                        # Input for user prompt and button to start the design process

                        with gr.Column():
                            # with gr.Column(scale=1, min_width=30):
                                design_output_sr = gr.Image(label="Design Output")

                    with gr.Row():

                        with gr.Column():

                            ai_intervention_radio_sr = gr.Radio(label="AI Intervention", choices=["Very Low", "Low", "Mid", "Extreme"], info='Indicates the level of AI intervention in the design process. "Very Low" means minimal changes, while "Extreme" allows for significant alterations to the original design. (Required Parameter)')
                    with gr.Row():
                            # with gr.Column(scale=1, min_width=30):
                            user_prompt_input_sr = gr.Textbox(label="Enter your Prompt", placeholder="A bedroom in a scandanavian style.", info = "A natural language instruction which provides room type and design style. Check instructions for possible Room Types & Design Styles (Required Parameter)")

                    with gr.Row():
                        # with gr.Column(scale=1, min_width=30):
                            start_btn_sr = gr.Button("Start Design Process")

                with gr.Tab("Sketch to Render (Exterior)"):
                    with gr.Row():
                        with gr.Column():
                            with gr.Row(scale=1):
                                image_upload_sr_ext = gr.Image(label="Upload an Image", type="filepath")
                    
                        # Input for user prompt and button to start the design process

                        with gr.Column():
                            # with gr.Column(scale=1, min_width=30):
                                design_output_sr_ext = gr.Image(label="Design Output")

                    with gr.Row():

                        with gr.Column():

                            ai_intervention_radio_sr_ext = gr.Radio(label="AI Intervention", choices=["Very Low", "Low", "Mid", "Extreme"], info='Indicates the level of AI intervention in the design process. "Very Low" means minimal changes, while "Extreme" allows for significant alterations to the original design. (Required Parameter)')

                        with gr.Column():
                             
                            house_angle_dp_sr_ext = gr.Dropdown(["Front of House", "Side of House", "Back of House"], label="House Angle", info="Indicates the angle of house for which the design is intended\n(Required Parameter)", interactive=True)
                    with gr.Row():
                            # with gr.Column(scale=1, min_width=30):
                            # user_prompt_input_sr_ext = gr.Textbox(label="Enter your Prompt", placeholder="A bedroom in a scandanavian style.", info = "A natural language instruction which provides room type and design style. (Required Parameter)")
                        # with gr.Column():
                             
                            design_style_sr_ext = gr.Dropdown(["No Style", "Modern", "Mediterranean", "International", "Moody Colors", "Wood Accents", "Bohemian", "Industrial", "Retreat", "Elegant", "Painted Brick", "Red Brick", "Modern Blend", "Stone Clad", "Glass House", "Ranch", "Modern Farm House", "Portuguese", "Traditional", "Craftsman", "Tudor", "Prairie", "Chalet", "Colonial", "Dutch Colonial", "Georgian", "Green", "Contemporary", "Christmas", "Cottage", "Farmhouse", "French Country", "Futuristic", "Gothic", "Greek Revival", "Mansion", "Townhouse", "Victorian", "Corporate Building"], label="Design Style", info="Defines the overall aesthetic style you want to achieve. (Required Parameter)", interactive=True)

                    with gr.Row():
                        # with gr.Column(scale=1, min_width=30):
                            start_btn_sr_ext = gr.Button("Start Design Process")

                with gr.Tab("Sketch to Render (Garden)"):
                    with gr.Row():
                        with gr.Column():
                            with gr.Row(scale=1):
                                image_upload_sr_garden = gr.Image(label="Upload an Image", type="filepath")
                    
                        # Input for user prompt and button to start the design process

                        with gr.Column():
                            # with gr.Column(scale=1, min_width=30):
                                design_output_sr_garden = gr.Image(label="Design Output")

                    with gr.Row():

                        with gr.Column():

                            ai_intervention_radio_sr_garden = gr.Radio(label="AI Intervention", choices=["Very Low", "Low", "Mid", "Extreme"], info='Indicates the level of AI intervention in the design process. "Very Low" means minimal changes, while "Extreme" allows for significant alterations to the original design. (Required Parameter)')

                        with gr.Column():
                             
                            garden_type_dp_sr_garden = gr.Dropdown(["Backyard", "Patio", "Terrace", "Front Yard", "Garden", "Courtyard", "Pool Area", "Porch", "Playground"], label="Garden Type", info="Indicates the type of garden for which the design is intended\n(Required Parameter)", interactive=True)
                    with gr.Row():
                         
                        design_style_sr_garden = gr.Dropdown(["No Style", "Modern", "City", "Contemporary", "Luxury", "Apartment", "Small", "Vegetable", "Low Budget", "Beach", "Wedding", "Rural", "Mediterranean", "Restaurant", "Formal", "American", "English", "Traditional", "Meditation", "Coastal", "Tropical", "Christmas", "Japanese Zen", "Cottage", "Wildflower", "Desert", "Butterfly", "Herb", "Vertical", "Zen Rock", "Rooftop", "Perennial", "Water", "Shade", "Winter", "Zen Bamboo", "Sculpture"], label="Design Style", info="Defines the overall aesthetic style you want to achieve. (Required Parameter)", interactive=True)

                    with gr.Row():
                        # with gr.Column(scale=1, min_width=30):
                            start_btn_sr_garden = gr.Button("Start Design Process")



        with gr.Tab("Instructions"):
            gr.HTML(
                f"""

                <p style="text-align: center; font-weight: bold;">
                Upload an image and a natural language prompt to generate a perfect redesign & Sketch to Render (Interior) of a room</p>
                <p style="text-align: center; font-weight: bold;"> Example prompt: "A bedroom in a scandanavian style."</p>

                <p style="text-align: center; font-weight: bold;"> For more information on design styles and room types, refer to the images below:</p>
                <p style="text-align: center; padding-bottom: 60px; font-weight: bold;">
                <span style="color: red;">Important:</span>
                Please upload a .jpg image not less that 512x512 dimensions and clearly mention the room type and the desired design style in the prompt.</p>
                
                """
            )
            gr.Image("instruction_assets/design_styles.png", label="Design Styles")
            gr.Image("instruction_assets/room_types.png", label="Room Types")
            


    
    # Design process button functionality
    def after_start_pr(user_prompt, image_path):
        """
        Processes the user prompt and image path, then generates and saves the output image.

        Args:
            user_prompt (str): The prompt provided by the user to guide the image generation.
            image_path (str): The path to the input image to be processed.

        Returns:
            response: The response from the flow function after processing the input.
        """
        try:
            output_path = "output_image.jpg"  # Path to save the output image
            response = perfect_redesign_flow(user_prompt, image_path, output_path)
            print(response)
            return response
        
        except Exception as e:
            # raise Exception(f"An error occurred in function after_start_pr: {e}")
            return Exception(f"An error occurred in function after_start_pr: {e}")
            
    start_btn_pr.click(after_start_pr, inputs=[user_prompt_input_pr, image_upload_pr], outputs=design_output_pr)

    # Sketch to render button functionality
    def after_start_sr(user_prompt, image_path, ai_intervention):
        """
        Processes the user prompt and image path, then generates and saves the output image.

        Args:
            user_prompt (str): The prompt provided by the user to guide the image generation.
            image_path (str): The path to the input image to be processed.
            ai_intervention (str): The level of AI intervention in the design process.

        Returns:
            response: The response from the flow function after processing the input.
        """
        try:
            output_path = "output_image.jpg"  # Path to save the output image
            print("=====Gradio sr function=====")
            # print("User Prompt: ", user_prompt, "Image Path: ", image_path, "AI Intervention: ", ai_intervention, "Output Path: ", output_path)
            # as a dict
            print({"User Prompt": user_prompt, "Image Path": image_path, "AI Intervention": ai_intervention, "Output Path": output_path})
            print("=============================")
            response = sketch_to_render_flow(user_prompt = user_prompt,
             image_path = image_path,
              output_path = output_path,
               ai_intervention=ai_intervention,
                design_type="Interior",
                 no_design=1,
                  house_angle=None,
                   garden_type=None)

            print(response)
            return response
        
        except Exception as e:
            # raise Exception(f"An error occurred in function after_start_sr: {e}")
            return Exception(f"An error occurred in function after_start_sr: {e}")
    
    start_btn_sr.click(after_start_sr, inputs=[user_prompt_input_sr, image_upload_sr, ai_intervention_radio_sr], outputs=design_output_sr)


    # Sketch to render ext button functionality
    def after_start_sr_ext(image_path, ai_intervention, house_angle, design_style):
        """
        Processes the user prompt and image path, then generates and saves the output image.

        Args:
            user_prompt (str): The prompt provided by the user to guide the image generation.
            image_path (str): The path to the input image to be processed.
            ai_intervention (str): The level of AI intervention in the design process.
            house_angle (str): The angle of the house for which the design is intended.
            design_style (str): The design style to be applied to the output image.

        Returns:
            response: The response from the flow function after processing the input.
        """
        try:
            output_path = "output_image.jpg"  # Path to save the output image
            print("=====Gradio sr ext function=====")
            # print("User Prompt: ", user_prompt, "Image Path: ", image_path, "AI Intervention: ", ai_intervention, "Output Path: ", output_path)
            # as a dict
            print({"Image Path": image_path, "AI Intervention": ai_intervention, "Output Path": output_path, "House Angle": house_angle, "Design Style": design_style})
            print("=============================")
            response = sketch_to_render_flow(
             image_path = image_path,
              output_path = output_path,
               ai_intervention=ai_intervention,
                design_type="Exterior",
                 no_design=1,
                  house_angle=house_angle,
                #    garden_type=None,
                   design_style=design_style)

            print(response)
            return response
        
        except Exception as e:
            # raise Exception(f"An error occurred in function after_start_sr: {e}")
            return Exception(f"An error occurred in function after_start_sr: {e}")

    start_btn_sr_ext.click(after_start_sr_ext, inputs=[image_upload_sr_ext, ai_intervention_radio_sr_ext, house_angle_dp_sr_ext, design_style_sr_ext], outputs=design_output_sr_ext)


    def after_start_sr_garden(image_path, ai_intervention, garden_type, design_style):
        """
        Processes the user prompt and image path, then generates and saves the output image.

        Args:
            user_prompt (str): The prompt provided by the user to guide the image generation.
            image_path (str): The path to the input image to be processed.
            ai_intervention (str): The level of AI intervention in the design process.
            garden_type (str): The type of garden for which the design is intended.
            design_style (str): The design style to be applied to the output image.

        Returns:
            response: The response from the flow function after processing the input.
        """
        try:
            output_path = "output_image.jpg"  # Path to save the output image
            print("=====Gradio sr garden function=====")
            # print("User Prompt: ", user_prompt, "Image Path: ", image_path, "AI Intervention: ", ai_intervention, "Output Path: ", output_path)
            # as a dict
            print({"Image Path": image_path, "AI Intervention": ai_intervention, "Output Path": output_path, "Garden Type": garden_type, "Design Style": design_style})
            print("=============================")
            response = sketch_to_render_flow(
             image_path = image_path,
              output_path = output_path,
               ai_intervention=ai_intervention,
                design_type="Garden",
                 no_design=1,
                  house_angle=None,
                   garden_type=garden_type,
                   design_style=design_style)

            print(response)
            return response
        
        except Exception as e:
            # raise Exception(f"An error occurred in function after_start_sr: {e}")
            return Exception(f"An error occurred in function after_start_sr: {e}")
        
    start_btn_sr_garden.click(after_start_sr_garden, inputs=[image_upload_sr_garden, ai_intervention_radio_sr_garden, garden_type_dp_sr_garden, design_style_sr_garden], outputs=design_output_sr_garden)

demo.launch(share=True, pwa=True, debug=True)