Alexandros Popov
commited on
Commit
·
95e7fc9
1
Parent(s):
03abeca
switched to catalog.
Browse files
judges.py
CHANGED
|
@@ -96,6 +96,10 @@ def call_to_director(image_path: str, user_prompt):
|
|
| 96 |
image_description = image_description["choices"][0]["message"]["content"]
|
| 97 |
system_prompt = (
|
| 98 |
"You are an AI art director. Your task is to propose a sequence of image enhancement operations "
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
"to transform the provided image according to the user's request. "
|
| 100 |
"You take strong decisions with important consequences on the image.\n"
|
| 101 |
"Consider the following possible operations:\n"
|
|
@@ -130,12 +134,12 @@ def call_to_director(image_path: str, user_prompt):
|
|
| 130 |
|
| 131 |
|
| 132 |
@tool
|
| 133 |
-
def critic(
|
| 134 |
"""
|
| 135 |
Evaluates the new image against the old image and provides feedback.
|
| 136 |
|
| 137 |
Args:
|
| 138 |
-
|
| 139 |
original_image_path (str): The file path to the new image.
|
| 140 |
user_prompt (str): Additional instructions or context provided by the user.
|
| 141 |
list_of_enhancements (str): the list of of all enhancements applied to the image.
|
|
@@ -144,24 +148,43 @@ def critic(new_image_path: str, original_image_path: str, user_prompt: str, list
|
|
| 144 |
str: Feedback on the changes made to the image.
|
| 145 |
"""
|
| 146 |
print("list_of_enhancements: ", list_of_enhancements)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
path_to_concat = concatenate_images_side_by_side(original_image_path, new_image_path)
|
| 148 |
|
| 149 |
# iterate each time between the ops and the critic
|
| 150 |
|
| 151 |
system_prompt = (
|
| 152 |
-
"You are an AI art critic. "
|
| 153 |
-
"You will be provided a single image, consisting of 2 images side by side
|
| 154 |
"On the left side, you will see the original image, "
|
| 155 |
"and on the right side, you will see the new image enhanced by AI.\n"
|
| 156 |
"Your task is to evaluate the changes made to image 2.\n"
|
| 157 |
"You will be provided with a prompt that describes the user's request to improve the image.\n"
|
| 158 |
"Does the image 2 respect the desire of the user ?\n"
|
| 159 |
-
"The application of the filters must be noticeable."
|
| 160 |
-
"
|
| 161 |
-
"
|
| 162 |
-
"
|
| 163 |
-
"
|
| 164 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
)
|
| 166 |
|
| 167 |
response = call_to_llm(
|
|
|
|
| 96 |
image_description = image_description["choices"][0]["message"]["content"]
|
| 97 |
system_prompt = (
|
| 98 |
"You are an AI art director. Your task is to propose a sequence of image enhancement operations "
|
| 99 |
+
"Overall, the modifications you are making aim at mimicking the instagm filters effect."
|
| 100 |
+
"You like to enhance pictures to make them full of light and color, happy and vibrant."
|
| 101 |
+
"The vignette effet and the grain should be use be scarcity, only if makes a lot of sense."
|
| 102 |
+
"Be careful to not overdue the shadows as well."
|
| 103 |
"to transform the provided image according to the user's request. "
|
| 104 |
"You take strong decisions with important consequences on the image.\n"
|
| 105 |
"Consider the following possible operations:\n"
|
|
|
|
| 134 |
|
| 135 |
|
| 136 |
@tool
|
| 137 |
+
def critic(output_directory: str, original_image_path: str, user_prompt: str, list_of_enhancements: str) -> str:
|
| 138 |
"""
|
| 139 |
Evaluates the new image against the old image and provides feedback.
|
| 140 |
|
| 141 |
Args:
|
| 142 |
+
output_directory (str): Path to the output directory
|
| 143 |
original_image_path (str): The file path to the new image.
|
| 144 |
user_prompt (str): Additional instructions or context provided by the user.
|
| 145 |
list_of_enhancements (str): the list of of all enhancements applied to the image.
|
|
|
|
| 148 |
str: Feedback on the changes made to the image.
|
| 149 |
"""
|
| 150 |
print("list_of_enhancements: ", list_of_enhancements)
|
| 151 |
+
# Find all files matching the pattern "trial_i" where i is an integer and extension is .jpeg
|
| 152 |
+
trial_files = [f for f in os.listdir(output_directory) if re.match(r"trial_\d+\.jpeg$", f)]
|
| 153 |
+
# Sort files by descending integer i
|
| 154 |
+
trial_files.sort(key=lambda x: (int(m.group(1)) if (m := re.search(r"trial_(\d+)\.jpeg$", x)) else -1))
|
| 155 |
+
new_image_path = os.path.join(output_directory, trial_files[0])
|
| 156 |
path_to_concat = concatenate_images_side_by_side(original_image_path, new_image_path)
|
| 157 |
|
| 158 |
# iterate each time between the ops and the critic
|
| 159 |
|
| 160 |
system_prompt = (
|
| 161 |
+
"You are an AI art critic. You provide a list adjustements to make the enhancements better\n"
|
| 162 |
+
"You will be provided a single image, consisting of 2 images side by side."
|
| 163 |
"On the left side, you will see the original image, "
|
| 164 |
"and on the right side, you will see the new image enhanced by AI.\n"
|
| 165 |
"Your task is to evaluate the changes made to image 2.\n"
|
| 166 |
"You will be provided with a prompt that describes the user's request to improve the image.\n"
|
| 167 |
"Does the image 2 respect the desire of the user ?\n"
|
| 168 |
+
"The application of the filters must be noticeable, but the effect should not look surreal."
|
| 169 |
+
"Overall, the modifications you are making aim at mimicking the instagm filters effect."
|
| 170 |
+
"Unless, specifically asked the contrary, you should stick to clear pictures full of light. "
|
| 171 |
+
"The vignette effet and the grain should be use be scarcity, only if makes a lot of sense."
|
| 172 |
+
"Here are the possible operations:\n"
|
| 173 |
+
"- adjust_contrast\n"
|
| 174 |
+
"- adjust_exposure\n"
|
| 175 |
+
"- adjust_saturation\n"
|
| 176 |
+
"- adjust_shadows_highlights\n"
|
| 177 |
+
"- adjust_temperature\n"
|
| 178 |
+
"- adjust_tint\n"
|
| 179 |
+
"- adjust_hue_color colors are [red, orange, yellow, green, aqua, blue, purple, magenta]\n"
|
| 180 |
+
"- adjust_saturation_color colors are [red, orange, yellow, green, aqua, blue, purple, magenta]'n"
|
| 181 |
+
"- adjust_luminance_color colors are [red, orange, yellow, green, aqua, blue, purple, magenta]\n"
|
| 182 |
+
"- add_vignette\n"
|
| 183 |
+
"- add_grain\n"
|
| 184 |
+
"FOR EACH, you must say what should be done to improve the image"
|
| 185 |
+
"Tool: Contrast\n"
|
| 186 |
+
"Suggestion: Reduce significantly the contrast\n"
|
| 187 |
+
"Confidence: 0.9\n"
|
| 188 |
)
|
| 189 |
|
| 190 |
response = call_to_llm(
|