|
""" |
|
This script orchestrates the design process by utilizing the DesignAssistant and DesignProcess classes. |
|
It extracts design parameters using the DesignAssistant and applies them using the DesignProcess. |
|
""" |
|
from .sk_render_ai import DesignAssistant |
|
from .render_app import DesignProcess |
|
import requests |
|
import time |
|
|
|
|
|
|
|
def flow(image_path, output_path, user_prompt="", design_type="Interior", ai_intervention="Mid", no_design=1, house_angle=None, garden_type=None, internal_prompt=None, design_style=None): |
|
""" |
|
Orchestrates the design process by extracting design parameters and applying them. |
|
|
|
Args: |
|
user_prompt (str): The prompt provided by the user to generate design parameters. |
|
image_path (str): The path to the input image for the design process. |
|
output_path (str): The path where the output image will be saved. |
|
|
|
Returns: |
|
str: The path to the saved output image if successful, or an error message if failed. |
|
""" |
|
|
|
|
|
try: |
|
|
|
print("=====Flow SR function=====") |
|
print("User Prompt: ", user_prompt, "Image Path: ", image_path, "Output Path: ", output_path, "Design Type: ", design_type, "AI Intervention: ", ai_intervention, "No Design: ", no_design, "House Angle: ", house_angle, "Garden Type: ", garden_type, "Internal Prompt: ", internal_prompt, "Design Style: ", design_style) |
|
print("=============================") |
|
|
|
if design_style is None: |
|
assistant = DesignAssistant() |
|
thread = assistant.create_thread() |
|
_user_prompt = f"The information can be in italian aswell, so choose the closest values from the above lists for the dict's values as the response will be always in english.\n{user_prompt}" |
|
message = assistant.create_message(thread.id, _user_prompt) |
|
run = assistant.run_and_poll(thread.id) |
|
|
|
if run.status == 'completed': |
|
messages = assistant.get_messages(thread.id) |
|
design_info = eval(messages.data[0].content[0].text.value) |
|
|
|
print(design_info) |
|
print(type(design_info)) |
|
print(design_info.keys()) |
|
print("---------------------------------------------") |
|
else: |
|
print("Failed to extract design information.") |
|
return |
|
else: |
|
design_info = { |
|
'design_style': design_style, |
|
'room_type': None |
|
} |
|
|
|
|
|
design_process = DesignProcess( |
|
image_path=image_path, |
|
design_style=design_info['design_style'], |
|
room_type=design_info['room_type'], |
|
design_type=design_type, |
|
ai_intervention=ai_intervention, |
|
no_design=no_design, |
|
house_angle=house_angle, |
|
garden_type=garden_type, |
|
internal_prompt=internal_prompt |
|
) |
|
|
|
response = design_process.start_process() |
|
print(response) |
|
|
|
|
|
|
|
|
|
if 'success' in response: |
|
print("Design process completed successfully. Image saved as new_design.jpg.") |
|
print("---------------------------------------------") |
|
|
|
print(response['success']['generated_image']) |
|
|
|
image_data = requests.get(response['success']['generated_image'][0]).content |
|
with open(output_path, "wb") as f: |
|
f.write(image_data) |
|
print("Design process completed successfully. Image saved as new_design.jpg.") |
|
return output_path |
|
else: |
|
print("Design process failed.") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
except Exception as e: |
|
raise |
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
flow( |
|
image_path = "sketch_bedroom.jpg", |
|
output_path = "new_design.jpg", |
|
design_type = "Interior", |
|
ai_intervention = "Mid", |
|
no_design = 1, |
|
house_angle = None, |
|
garden_type = None, |
|
user_prompt = "I want to generate a design for a scandanavian bedroom") |