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( """
Upload an image and a natural language prompt to generate a perfect redesign & Sketch to Render (Interior) of a room
Example prompt: "A bedroom in a scandanavian style."
For more information on design styles and room types, refer to the images below:
Important: Please upload a .jpg image not less that 512x512 dimensions and clearly mention the room type and the desired design style in the prompt.
""" ) 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)