File size: 3,258 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
"""
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:
        # Extract design parameters using render_ai.py
        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

        # 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']
        )
        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)  # Prints the status of the redesign request
            # Wait for the process to complete or fail

            # if status['status'] in ['succeeded', 'error']:
            #     break
            if "status" not in status.keys():
              break

            time.sleep(7)

        if "output_images" in status:
            image_url = status['output_images'][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