sharoz's picture
initial +
56b65c4
raw
history blame contribute delete
5.24 kB
"""
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")