File size: 5,241 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 |
"""
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 all args
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("=============================")
# Extract design parameters using render_ai.py
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) # Assuming the response is a dict in string format
# Debugging information
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
}
# Use the extracted design parameters in render_app.py
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)
# request_id = response['id']
# print(request_id)
# print(type(request_id))
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.")
# while True:
# status = design_process.check_status(request_id)
# print(status) # Prints the status of the redesign request
# # Wait for the process to complete or fail
# if status['status'] in ['succeeded', 'error']:
# break
# time.sleep(7)
# if status.get('status') == 'succeeded':
# image_url = status['output'][0] # Assuming you want the first image
# # Save the image to the specified output path
# image_data = requests.get(image_url).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.")
# return "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") |