Spaces:
Paused
Paused
improve the ability to follow reference copy
Browse files
app.py
CHANGED
|
@@ -254,31 +254,55 @@ def generate(*data):
|
|
| 254 |
batch = []
|
| 255 |
for i in range(visible + 1):
|
| 256 |
structure = struct_ref[2 * i]
|
| 257 |
-
|
| 258 |
-
if len((structure +
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 282 |
batch.append(messages)
|
| 283 |
|
| 284 |
description = ""
|
|
@@ -286,38 +310,38 @@ def generate(*data):
|
|
| 286 |
response = chat.batch(batch, temperature=temperature)
|
| 287 |
print(response)
|
| 288 |
|
| 289 |
-
batch = []
|
| 290 |
-
rewrite_map = {}
|
| 291 |
-
for i in range(visible + 1):
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
print("Rewrite_map", rewrite_map)
|
| 314 |
-
print("Rewriting")
|
| 315 |
-
re_response = chat.batch(batch, temperature=temperature)
|
| 316 |
-
for i in range(len(re_response)):
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
response = [re_response[rewrite_map[i]] if i in rewrite_map else response[i] for i in range(visible + 1)]
|
| 320 |
-
print("Done rewriting")
|
| 321 |
|
| 322 |
description = "\n---\n".join([msg.content for msg in response])
|
| 323 |
md_content = description
|
|
|
|
| 254 |
batch = []
|
| 255 |
for i in range(visible + 1):
|
| 256 |
structure = struct_ref[2 * i]
|
| 257 |
+
copy = struct_ref[2 * i + 1]
|
| 258 |
+
if len((structure + copy).strip()) > 0:
|
| 259 |
+
if len(copy.strip()) > 0:
|
| 260 |
+
print('------------')
|
| 261 |
+
print("Using copy")
|
| 262 |
+
messages = [
|
| 263 |
+
SystemMessage(content=f"""You are a helpful assistant that writes about products for ecommerce websites. Make sure to write in {languages[i]} language."""),
|
| 264 |
+
HumanMessage(content=f"""Write a product description with the following features.
|
| 265 |
+
Make sure that the output follows the structure and tone of voice of the reference copy.
|
| 266 |
+
Make sure that the output really sounds like the reference copy.
|
| 267 |
+
Use markdown format for the output.
|
| 268 |
+
Output the product description only, do not include any preceeding text like "Here is your product description".
|
| 269 |
+
Use a consistent tone of voice throughout the text.
|
| 270 |
+
Do not include any part of the reference structure in the output.
|
| 271 |
+
Do not use any of the excluded words in the output.
|
| 272 |
+
Make sure to include all of the included words in the output.
|
| 273 |
+
Do not hallucinate any information.
|
| 274 |
+
|
| 275 |
+
{feature + detected_features}
|
| 276 |
+
{intended_use}
|
| 277 |
+
Reference copy: {copy}
|
| 278 |
+
Included words: {included_words}
|
| 279 |
+
Excluded words: {excluded_words}"""),]
|
| 280 |
+
print(messages[1].content)
|
| 281 |
+
print('------------')
|
| 282 |
+
elif len(structure.strip()) > 0:
|
| 283 |
+
print('------------')
|
| 284 |
+
print("Using structure")
|
| 285 |
+
messages = [
|
| 286 |
+
SystemMessage(content=f"""You are a helpful assistant that writes about products for ecommerce websites. Make sure to write in {languages[i]} language."""),
|
| 287 |
+
HumanMessage(content=f"""Write a product description with the following features.
|
| 288 |
+
Make sure that the description follows the structure of the reference structure.
|
| 289 |
+
Make sure to use markdown format for the output.
|
| 290 |
+
Make sure that the entire output is written entirely in language defined in the reference structure.
|
| 291 |
+
Make sure to output the product description only, do not include any preceeding text like "Here is your product description".
|
| 292 |
+
Use language that is suitable for the type of document specified in the reference structure.
|
| 293 |
+
Use a consistent tone of voice throughout the text.
|
| 294 |
+
Do not include any part of the reference structure in the output.
|
| 295 |
+
Do not use any of the excluded words in the output.
|
| 296 |
+
Make sure to include all of the included words in the output.
|
| 297 |
+
Do not hallucinate any information.
|
| 298 |
+
|
| 299 |
+
{feature + detected_features}
|
| 300 |
+
{intended_use}
|
| 301 |
+
Reference structure: {structure}
|
| 302 |
+
Included words: {included_words}
|
| 303 |
+
Excluded words: {excluded_words}"""),]
|
| 304 |
+
print(messages[1].content)
|
| 305 |
+
print('------------')
|
| 306 |
batch.append(messages)
|
| 307 |
|
| 308 |
description = ""
|
|
|
|
| 310 |
response = chat.batch(batch, temperature=temperature)
|
| 311 |
print(response)
|
| 312 |
|
| 313 |
+
# batch = []
|
| 314 |
+
# rewrite_map = {}
|
| 315 |
+
# for i in range(visible + 1):
|
| 316 |
+
# structure = struct_ref[2 * i]
|
| 317 |
+
# reference = struct_ref[2 * i + 1]
|
| 318 |
+
# if len(reference.strip()) > 0:
|
| 319 |
+
# messages = [
|
| 320 |
+
# SystemMessage(content=f"""You are a helpful assistant that writes about products for ecommerce websites. You write in {languages[i]} language."""),
|
| 321 |
+
# HumanMessage(content=f"""Rewrite the following product description in the style and tone of voice
|
| 322 |
+
# of the reference product description.
|
| 323 |
+
# Make sure that the structure and length of the output is similar to the reference product description.
|
| 324 |
+
# Make sure that the output is written in {languages[i]} language.
|
| 325 |
+
# Output the product description in markdown format.
|
| 326 |
+
|
| 327 |
+
# Product description to rewirte:
|
| 328 |
+
# ```{response[i].content}```
|
| 329 |
+
|
| 330 |
+
# Reference product description:
|
| 331 |
+
# ```{reference}```
|
| 332 |
+
# """)
|
| 333 |
+
# ]
|
| 334 |
+
# batch.append(messages)
|
| 335 |
+
# rewrite_map[i] = len(batch) - 1
|
| 336 |
+
|
| 337 |
+
# print("Rewrite_map", rewrite_map)
|
| 338 |
+
# print("Rewriting")
|
| 339 |
+
# re_response = chat.batch(batch, temperature=temperature)
|
| 340 |
+
# for i in range(len(re_response)):
|
| 341 |
+
# print(f"Original: {response[i].content}")
|
| 342 |
+
# print(f"Rewritten: {re_response[i].content}")
|
| 343 |
+
# response = [re_response[rewrite_map[i]] if i in rewrite_map else response[i] for i in range(visible + 1)]
|
| 344 |
+
# print("Done rewriting")
|
| 345 |
|
| 346 |
description = "\n---\n".join([msg.content for msg in response])
|
| 347 |
md_content = description
|