Spaces:
Paused
Paused
fix list prompts, detect feature prompts
Browse files- app.py +70 -60
- str2escaped.py +1 -0
app.py
CHANGED
|
@@ -116,56 +116,56 @@ default_model = "gemini-2.0-flash-thinking-exp-01-21"
|
|
| 116 |
openai.api_key = os.environ["OPENAI_API_KEY"]
|
| 117 |
|
| 118 |
struct_copy_prompt = """Generate {nversions} versions of the product description for a product with the following information.
|
| 119 |
-
Write in a way that target the customer.
|
| 120 |
For each version, write at least {min_length} words and at most {max_length} words.
|
| 121 |
Make sure that the structure of each output follows the reference structure. Do not add any additional sentences or structures that are not in the reference structure.
|
| 122 |
Make sure to use the tone of voice, rythm, cadence and style of the reference copy for each output.
|
| 123 |
Use markdown format for each output.
|
| 124 |
-
Do not
|
| 125 |
The structure of the output should follow the reference structure.
|
| 126 |
-
|
|
|
|
| 127 |
Do not use any of the excluded words in the output.
|
| 128 |
-
Try to
|
| 129 |
-
Use the relevant information from the product features
|
| 130 |
-
Do not hallucinate any information about the product, use only the provided key features
|
| 131 |
-
Note that the reference copy should be used for style and tone only
|
| 132 |
Do not hallucinate information about size and weight. Write about size and weight only if it is available in the list of features.
|
| 133 |
Use creative language in each output, do not use the common ways of starting product descriptions.
|
| 134 |
Avoid common phrases and cliches such as "Step into something", "Elevate something", "Discover something", "Unleash something", "Embrace something", and similar phrases.
|
| 135 |
For each version, try to write in different style.
|
| 136 |
-
|
| 137 |
Rate the quality of each version based on the following criteria:
|
| 138 |
-
- how
|
| 139 |
-
- how well it follows the reference structure.
|
| 140 |
- how well it follows the tone of voice, rythm, cadence and style of the reference copy.
|
| 141 |
-
- how well it avoid the excluded words.
|
| 142 |
-
- how well it includes the included words.
|
| 143 |
-
- how creative the language is.
|
| 144 |
-
The score should be a number between 0 and 10 with 10 being the best quality.
|
| 145 |
Return the result in the following JSON format:
|
| 146 |
{{
|
| 147 |
-
"versions": [
|
| 148 |
{{
|
| 149 |
"id": 1,
|
| 150 |
"content": The first product description,
|
| 151 |
-
"explanation": A less than 20 word explanation of the score of the first product description,
|
| 152 |
"score": The score of the first product description
|
| 153 |
}},
|
| 154 |
{{
|
| 155 |
"id": 2,
|
| 156 |
"content": The second product description,
|
| 157 |
-
"explanation": A less than 20 word explanation of the score of the first product description,
|
| 158 |
"score": The score of the second product description
|
| 159 |
}},
|
| 160 |
-
...
|
| 161 |
-
],
|
| 162 |
"best_version": {{
|
| 163 |
-
"explanation": Explanation for why this version is the best,
|
| 164 |
-
"id": The id of the best version
|
| 165 |
-
}}
|
| 166 |
-
}}
|
| 167 |
-
Make sure that the output is in JSON format, no extra text should be included in the output.
|
| 168 |
-
|
| 169 |
<product_information>
|
| 170 |
<key_features>
|
| 171 |
{key_features}
|
|
@@ -190,24 +190,24 @@ Make sure that the output is in JSON format, no extra text should be included in
|
|
| 190 |
|
| 191 |
|
| 192 |
copy_prompt = """Generate {nversions} versions of the product description for a product with the following information.
|
| 193 |
-
Write in a way that target the customer.
|
| 194 |
For each version, write at least {min_length} words and at most {max_length} words.
|
| 195 |
Make sure that the structure of each output follows the structure of the reference copy.
|
| 196 |
Make sure to use the tone of voice, rythm, cadence and style of the reference copy for each output.
|
| 197 |
Use markdown format for each output.
|
| 198 |
Make sure that the structure of each output follows the structure of the reference copy.
|
|
|
|
| 199 |
Do not use any of the excluded words in the output.
|
| 200 |
-
Try to
|
| 201 |
-
Use the relevant information from the product features
|
| 202 |
-
Do not hallucinate any information about the product, use only the provided key features
|
| 203 |
-
Note that the reference copy should be used for style and tone only, do not use any part of the reference copy in the output.
|
| 204 |
Do not hallucinate information about size and weight. Write about size and weight only if it is available in the list of features.
|
| 205 |
Use creative language in each output, do not use the common ways of starting product descriptions.
|
| 206 |
Avoid common phrases and cliches such as "Step into something", "Elevate something", "Discover something", "Unleash something", "Embrace something", and similar phrases.
|
| 207 |
For each version, try to write in different style.
|
| 208 |
-
|
| 209 |
Rate the quality of each version based on the following criteria:
|
| 210 |
-
- how
|
| 211 |
- how well it follows the tone of voice, rythm, cadence and style of the reference copy.
|
| 212 |
- how well it avoid the excluded words.
|
| 213 |
- how well it includes the included words.
|
|
@@ -231,7 +231,7 @@ Return the result in the following JSON format:
|
|
| 231 |
...
|
| 232 |
],
|
| 233 |
"best_version": {{
|
| 234 |
-
"explanation": Explanation for why this version is the best,
|
| 235 |
"id": The id of the best version
|
| 236 |
}}
|
| 237 |
}}
|
|
@@ -257,53 +257,54 @@ Make sure that the output is in JSON format, no extra text should be included in
|
|
| 257 |
|
| 258 |
|
| 259 |
struct_prompt = """Generate {nversions} versions of the product description for a product with the following information.
|
| 260 |
-
Write in a way that target the customer.
|
| 261 |
For each version, write at least {min_length} words and at most {max_length} words.
|
| 262 |
Make sure that the structure of each output follows the reference structure. Do not add any additional sentences or structures that are not in the reference structure.
|
| 263 |
Use markdown format for each output.
|
| 264 |
Do not include any part of the reference structure in the output.
|
| 265 |
Make sure that the structure of each output follows the reference structure.
|
|
|
|
| 266 |
Do not use any of the excluded words in the output.
|
| 267 |
-
Try to
|
| 268 |
-
Use the relevant information from the product features
|
| 269 |
-
Do not hallucinate any information about the product, use only the provided key features
|
| 270 |
-
Note that the reference structure should be used for structure only
|
|
|
|
| 271 |
Do not hallucinate information about size and weight. Write about size and weight only if it is available in the list of features.
|
| 272 |
Use creative language in each output, do not use the common ways of starting product descriptions.
|
| 273 |
Avoid common phrases and cliches such as "Step into something", "Elevate something", "Discover something", "Unleash something", "Embrace something", and similar phrases.
|
| 274 |
For each version, try to write in different style.
|
| 275 |
-
|
| 276 |
Rate the quality of each version based on the following criteria:
|
| 277 |
-
- how
|
| 278 |
-
- how well it follows the reference structure.
|
| 279 |
-
- how well it avoid the excluded words.
|
| 280 |
-
- how well it includes the included words.
|
| 281 |
-
- how creative the language is.
|
| 282 |
-
The score should be a number between 0 and 10 with 10 being the best quality.
|
| 283 |
Return the result in the following JSON format:
|
| 284 |
{{
|
| 285 |
-
"versions": [
|
| 286 |
{{
|
| 287 |
"id": 1,
|
| 288 |
"content": The first product description,
|
| 289 |
-
"explanation": A less than 20 word explanation of the score of the first product description,
|
| 290 |
"score": The score of the first product description
|
| 291 |
}},
|
| 292 |
{{
|
| 293 |
"id": 2,
|
| 294 |
"content": The second product description,
|
| 295 |
-
"explanation": A less than 20 word explanation of the score of the first product description,
|
| 296 |
"score": The score of the second product description
|
| 297 |
}},
|
| 298 |
-
...
|
| 299 |
-
],
|
| 300 |
"best_version": {{
|
| 301 |
-
"explanation": Explanation for why this version is the best,
|
| 302 |
-
"id": The id of the best version
|
| 303 |
-
}}
|
| 304 |
-
}}
|
| 305 |
-
Make sure that the output is in JSON format, no extra text should be included in the output.
|
| 306 |
-
|
| 307 |
<product_information>
|
| 308 |
<key_features>
|
| 309 |
{key_features}
|
|
@@ -398,7 +399,7 @@ Try your best to include the included words and phrases in the product descripti
|
|
| 398 |
Make sure to keep to the requirements of the structure, writing no more or less than specified.
|
| 399 |
If the structure does not specify a length, write a description that is between {min_length} and {max_length} words.
|
| 400 |
Do not enclose the output in html tags, quotes, braces, brackets or anything.
|
| 401 |
-
|
| 402 |
Return the product description only.
|
| 403 |
|
| 404 |
<product_information>
|
|
@@ -423,6 +424,11 @@ Return the product description only.
|
|
| 423 |
|
| 424 |
|
| 425 |
detect_feature_prompt = """Describe the features of the {garment_type} in the photo in less than 150 words.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 426 |
Return the result in in the following JSON format without any preceding or trailing text:
|
| 427 |
|
| 428 |
{{
|
|
@@ -480,7 +486,7 @@ def get_json(text: str):
|
|
| 480 |
|
| 481 |
|
| 482 |
@weave.op
|
| 483 |
-
def detect_features(image_paths, garment_type, language="English"):
|
| 484 |
# Path to your image
|
| 485 |
# image_path = "path_to_your_image.jpg"
|
| 486 |
|
|
@@ -498,7 +504,9 @@ def detect_features(image_paths, garment_type, language="English"):
|
|
| 498 |
"content": [
|
| 499 |
{
|
| 500 |
"type": "text",
|
| 501 |
-
"text": detect_feature_prompt.format(
|
|
|
|
|
|
|
| 502 |
},
|
| 503 |
{
|
| 504 |
"type": "image_url",
|
|
@@ -712,7 +720,9 @@ def generate(*data):
|
|
| 712 |
# print("Languages--------------------------------------------\n", languages)
|
| 713 |
# print("Types--------------------------------------------", types)
|
| 714 |
|
| 715 |
-
image_features, base64_images = detect_features(image,
|
|
|
|
|
|
|
| 716 |
detected_features = ""
|
| 717 |
intended_use = ""
|
| 718 |
alt_texts = []
|
|
|
|
| 116 |
openai.api_key = os.environ["OPENAI_API_KEY"]
|
| 117 |
|
| 118 |
struct_copy_prompt = """Generate {nversions} versions of the product description for a product with the following information.
|
|
|
|
| 119 |
For each version, write at least {min_length} words and at most {max_length} words.
|
| 120 |
Make sure that the structure of each output follows the reference structure. Do not add any additional sentences or structures that are not in the reference structure.
|
| 121 |
Make sure to use the tone of voice, rythm, cadence and style of the reference copy for each output.
|
| 122 |
Use markdown format for each output.
|
| 123 |
+
Do not copy any part of the reference structure to the output.
|
| 124 |
The structure of the output should follow the reference structure.
|
| 125 |
+
Make sure to keep to the requirements of the structure, writing no more or less than specified.
|
| 126 |
+
Do not use the structure of the reference copy for the output.
|
| 127 |
Do not use any of the excluded words in the output.
|
| 128 |
+
Try to include included words in the output when relevant.
|
| 129 |
+
Use the relevant information from the product features in the output.
|
| 130 |
+
Do not hallucinate any information about the product, use only the provided key features to write about the product.
|
| 131 |
+
Note that the reference copy should be used for style and tone only.
|
| 132 |
Do not hallucinate information about size and weight. Write about size and weight only if it is available in the list of features.
|
| 133 |
Use creative language in each output, do not use the common ways of starting product descriptions.
|
| 134 |
Avoid common phrases and cliches such as "Step into something", "Elevate something", "Discover something", "Unleash something", "Embrace something", and similar phrases.
|
| 135 |
For each version, try to write in different style.
|
| 136 |
+
If there is a list in the output, put each item in the list on a separate line and use '-' character to start each item.
|
| 137 |
Rate the quality of each version based on the following criteria:
|
| 138 |
+
- how well it describes the product features.
|
| 139 |
+
- how well it follows the reference structure.
|
| 140 |
- how well it follows the tone of voice, rythm, cadence and style of the reference copy.
|
| 141 |
+
- how well it avoid the excluded words.
|
| 142 |
+
- how well it includes the included words.
|
| 143 |
+
- how creative the language is.
|
| 144 |
+
The score should be a number between 0 and 10 with 10 being the best quality.
|
| 145 |
Return the result in the following JSON format:
|
| 146 |
{{
|
| 147 |
+
"versions": [
|
| 148 |
{{
|
| 149 |
"id": 1,
|
| 150 |
"content": The first product description,
|
| 151 |
+
"explanation": A less than 20 word explanation of the score of the first product description,
|
| 152 |
"score": The score of the first product description
|
| 153 |
}},
|
| 154 |
{{
|
| 155 |
"id": 2,
|
| 156 |
"content": The second product description,
|
| 157 |
+
"explanation": A less than 20 word explanation of the score of the first product description,
|
| 158 |
"score": The score of the second product description
|
| 159 |
}},
|
| 160 |
+
...
|
| 161 |
+
],
|
| 162 |
"best_version": {{
|
| 163 |
+
"explanation": Explanation for why this version is the best,
|
| 164 |
+
"id": The id of the best version
|
| 165 |
+
}}
|
| 166 |
+
}}
|
| 167 |
+
Make sure that the output is in JSON format, no extra text should be included in the output.
|
| 168 |
+
|
| 169 |
<product_information>
|
| 170 |
<key_features>
|
| 171 |
{key_features}
|
|
|
|
| 190 |
|
| 191 |
|
| 192 |
copy_prompt = """Generate {nversions} versions of the product description for a product with the following information.
|
|
|
|
| 193 |
For each version, write at least {min_length} words and at most {max_length} words.
|
| 194 |
Make sure that the structure of each output follows the structure of the reference copy.
|
| 195 |
Make sure to use the tone of voice, rythm, cadence and style of the reference copy for each output.
|
| 196 |
Use markdown format for each output.
|
| 197 |
Make sure that the structure of each output follows the structure of the reference copy.
|
| 198 |
+
Make sure to keep to the requirements of the structure, writing no more or less than specified.
|
| 199 |
Do not use any of the excluded words in the output.
|
| 200 |
+
Try to include included words in the output when relevant.
|
| 201 |
+
Use the relevant information from the product features in the output.
|
| 202 |
+
Do not hallucinate any information about the product, use only the provided key features to write about the product.
|
| 203 |
+
Note that the reference copy should be used for style and tone only, do not use any part of the reference copy in the output.
|
| 204 |
Do not hallucinate information about size and weight. Write about size and weight only if it is available in the list of features.
|
| 205 |
Use creative language in each output, do not use the common ways of starting product descriptions.
|
| 206 |
Avoid common phrases and cliches such as "Step into something", "Elevate something", "Discover something", "Unleash something", "Embrace something", and similar phrases.
|
| 207 |
For each version, try to write in different style.
|
| 208 |
+
If there is a list in the output, put each item in the list on a separate line and use '-' character to start each item.
|
| 209 |
Rate the quality of each version based on the following criteria:
|
| 210 |
+
- how well it describes the product features.
|
| 211 |
- how well it follows the tone of voice, rythm, cadence and style of the reference copy.
|
| 212 |
- how well it avoid the excluded words.
|
| 213 |
- how well it includes the included words.
|
|
|
|
| 231 |
...
|
| 232 |
],
|
| 233 |
"best_version": {{
|
| 234 |
+
"explanation": Explanation for why this version is the best,
|
| 235 |
"id": The id of the best version
|
| 236 |
}}
|
| 237 |
}}
|
|
|
|
| 257 |
|
| 258 |
|
| 259 |
struct_prompt = """Generate {nversions} versions of the product description for a product with the following information.
|
|
|
|
| 260 |
For each version, write at least {min_length} words and at most {max_length} words.
|
| 261 |
Make sure that the structure of each output follows the reference structure. Do not add any additional sentences or structures that are not in the reference structure.
|
| 262 |
Use markdown format for each output.
|
| 263 |
Do not include any part of the reference structure in the output.
|
| 264 |
Make sure that the structure of each output follows the reference structure.
|
| 265 |
+
Make sure to keep to the requirements of the structure, writing no more or less than specified.
|
| 266 |
Do not use any of the excluded words in the output.
|
| 267 |
+
Try to include included words in the output when relevant.
|
| 268 |
+
Use the relevant information from the product features in the output.
|
| 269 |
+
Do not hallucinate any information about the product, use only the provided key features to write about the product.
|
| 270 |
+
Note that the reference structure should be used for structure only.
|
| 271 |
+
Do not copy any part of the reference structure to the output.
|
| 272 |
Do not hallucinate information about size and weight. Write about size and weight only if it is available in the list of features.
|
| 273 |
Use creative language in each output, do not use the common ways of starting product descriptions.
|
| 274 |
Avoid common phrases and cliches such as "Step into something", "Elevate something", "Discover something", "Unleash something", "Embrace something", and similar phrases.
|
| 275 |
For each version, try to write in different style.
|
| 276 |
+
If there is a list in the output, put each item in the list on a separate line and use '-' character to start each item.
|
| 277 |
Rate the quality of each version based on the following criteria:
|
| 278 |
+
- how well it describes the product features.
|
| 279 |
+
- how well it follows the reference structure.
|
| 280 |
+
- how well it avoid the excluded words.
|
| 281 |
+
- how well it includes the included words.
|
| 282 |
+
- how creative the language is.
|
| 283 |
+
The score should be a number between 0 and 10 with 10 being the best quality.
|
| 284 |
Return the result in the following JSON format:
|
| 285 |
{{
|
| 286 |
+
"versions": [
|
| 287 |
{{
|
| 288 |
"id": 1,
|
| 289 |
"content": The first product description,
|
| 290 |
+
"explanation": A less than 20 word explanation of the score of the first product description,
|
| 291 |
"score": The score of the first product description
|
| 292 |
}},
|
| 293 |
{{
|
| 294 |
"id": 2,
|
| 295 |
"content": The second product description,
|
| 296 |
+
"explanation": A less than 20 word explanation of the score of the first product description,
|
| 297 |
"score": The score of the second product description
|
| 298 |
}},
|
| 299 |
+
...
|
| 300 |
+
],
|
| 301 |
"best_version": {{
|
| 302 |
+
"explanation": Explanation for why this version is the best,
|
| 303 |
+
"id": The id of the best version
|
| 304 |
+
}}
|
| 305 |
+
}}
|
| 306 |
+
Make sure that the output is in JSON format, no extra text should be included in the output.
|
| 307 |
+
|
| 308 |
<product_information>
|
| 309 |
<key_features>
|
| 310 |
{key_features}
|
|
|
|
| 399 |
Make sure to keep to the requirements of the structure, writing no more or less than specified.
|
| 400 |
If the structure does not specify a length, write a description that is between {min_length} and {max_length} words.
|
| 401 |
Do not enclose the output in html tags, quotes, braces, brackets or anything.
|
| 402 |
+
If there is a list in the output, put each item in the list on a separate line and use '-' character to start each item in a list.
|
| 403 |
Return the product description only.
|
| 404 |
|
| 405 |
<product_information>
|
|
|
|
| 424 |
|
| 425 |
|
| 426 |
detect_feature_prompt = """Describe the features of the {garment_type} in the photo in less than 150 words.
|
| 427 |
+
The known features of the garment are:
|
| 428 |
+
<key_features>
|
| 429 |
+
{key_features}
|
| 430 |
+
</key_features>
|
| 431 |
+
If there are any conflicts between the detected features and the known features, use the known features in the output.
|
| 432 |
Return the result in in the following JSON format without any preceding or trailing text:
|
| 433 |
|
| 434 |
{{
|
|
|
|
| 486 |
|
| 487 |
|
| 488 |
@weave.op
|
| 489 |
+
def detect_features(image_paths, garment_type, key_features, language="English"):
|
| 490 |
# Path to your image
|
| 491 |
# image_path = "path_to_your_image.jpg"
|
| 492 |
|
|
|
|
| 504 |
"content": [
|
| 505 |
{
|
| 506 |
"type": "text",
|
| 507 |
+
"text": detect_feature_prompt.format(
|
| 508 |
+
garment_type=garment_type,
|
| 509 |
+
key_features=key_features)
|
| 510 |
},
|
| 511 |
{
|
| 512 |
"type": "image_url",
|
|
|
|
| 720 |
# print("Languages--------------------------------------------\n", languages)
|
| 721 |
# print("Types--------------------------------------------", types)
|
| 722 |
|
| 723 |
+
image_features, base64_images = detect_features(image_paths=image,
|
| 724 |
+
garment_type=garment_type,
|
| 725 |
+
key_features=feature)
|
| 726 |
detected_features = ""
|
| 727 |
intended_use = ""
|
| 728 |
alt_texts = []
|
str2escaped.py
CHANGED
|
@@ -288,6 +288,7 @@ Try your best to include the included words and phrases in the product descripti
|
|
| 288 |
Make sure to keep to the requirements of the structure, writing no more or less than specified.
|
| 289 |
If the structure does not specify a length, write a description that is between {min_length} and {max_length} words.
|
| 290 |
Do not enclose the output in html tags, quotes, braces, brackets or anything.
|
|
|
|
| 291 |
Return the product description only.
|
| 292 |
|
| 293 |
<product_information>
|
|
|
|
| 288 |
Make sure to keep to the requirements of the structure, writing no more or less than specified.
|
| 289 |
If the structure does not specify a length, write a description that is between {min_length} and {max_length} words.
|
| 290 |
Do not enclose the output in html tags, quotes, braces, brackets or anything.
|
| 291 |
+
Put each item in the list on a separate line. Always use '-' character to start each item in a list.
|
| 292 |
Return the product description only.
|
| 293 |
|
| 294 |
<product_information>
|