|
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: |
|
|
|
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") |
|
|
|
|
|
|
|
with gr.Column(): |
|
|
|
design_output_pr = gr.Image(label="Design Output") |
|
|
|
with gr.Row(): |
|
|
|
user_prompt_input_pr = gr.Textbox(label="Enter your Prompt", placeholder="A bedroom in a scandanavian style.") |
|
|
|
with gr.Row(): |
|
|
|
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") |
|
|
|
|
|
|
|
with gr.Column(): |
|
|
|
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(): |
|
|
|
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(): |
|
|
|
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") |
|
|
|
|
|
|
|
with gr.Column(): |
|
|
|
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(): |
|
|
|
|
|
|
|
|
|
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(): |
|
|
|
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") |
|
|
|
|
|
|
|
with gr.Column(): |
|
|
|
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(): |
|
|
|
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") |
|
|
|
|
|
|
|
|
|
|
|
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" |
|
response = perfect_redesign_flow(user_prompt, image_path, output_path) |
|
print(response) |
|
return response |
|
|
|
except Exception as 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) |
|
|
|
|
|
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" |
|
print("=====Gradio sr function=====") |
|
|
|
|
|
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: |
|
|
|
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) |
|
|
|
|
|
|
|
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" |
|
print("=====Gradio sr ext function=====") |
|
|
|
|
|
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, |
|
|
|
design_style=design_style) |
|
|
|
print(response) |
|
return response |
|
|
|
except Exception as 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" |
|
print("=====Gradio sr garden function=====") |
|
|
|
|
|
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: |
|
|
|
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) |
|
|