|
""" |
|
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 .render_ai import DesignAssistant |
|
from .render_app import DesignProcess |
|
import requests |
|
import time |
|
|
|
|
|
|
|
def flow(user_prompt, image_path, output_path): |
|
""" |
|
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: |
|
|
|
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 |
|
|
|
|
|
design_process = DesignProcess( |
|
image_path=image_path, |
|
design_style=design_info['design_style'], |
|
room_type=design_info['room_type'] |
|
) |
|
response = design_process.start_process() |
|
|
|
request_id = response['id'] |
|
print("_________!!!!!Perfect Redesign Request ID!!!!!_________") |
|
print(request_id) |
|
print(type(request_id)) |
|
|
|
while True: |
|
status = design_process.check_status(request_id) |
|
print(status) |
|
|
|
|
|
|
|
|
|
if "status" not in status.keys(): |
|
break |
|
|
|
time.sleep(7) |
|
|
|
if "output_images" in status: |
|
image_url = status['output_images'][0] |
|
|
|
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 |
|
|