Spaces:
Sleeping
Sleeping
added summary, edited main prompt
Browse files
app.py
CHANGED
|
@@ -366,15 +366,18 @@ def find_best_price(request):
|
|
| 366 |
f"Printer 1: {printer_1}\n"
|
| 367 |
f"Printer 2: {printer_2}\n"
|
| 368 |
f"Printer 3: {printer_3}\n"
|
| 369 |
-
"For each product in request,
|
| 370 |
-
"1.
|
| 371 |
-
"If user
|
| 372 |
-
"
|
| 373 |
-
"
|
|
|
|
|
|
|
|
|
|
| 374 |
" - Finding the nearest lower quantity in the base price list.\n"
|
| 375 |
" - Multiplying by the size multiplier\n"
|
| 376 |
" - Multiplying by the user requested amount. IMPORTANT. Do not multiply by nearest lower quantity!\n"
|
| 377 |
-
"
|
| 378 |
"Example:\n"
|
| 379 |
"User: I want 25 banners in size 6x6, 2000 business cards and 5000 circle stickers in size 6x6 on matte paper\n"
|
| 380 |
"Answer:\n"
|
|
@@ -392,7 +395,7 @@ def find_best_price(request):
|
|
| 392 |
"- PrintMaster: amount (5000) * multiplier for circle shape (1.0) * multiplier for custom size (2.0) * price per unit for nearest pack size ($0.11). Total for 5000: $1100.00\n\n"
|
| 393 |
"Your response should display ONLY final pricing for each available option, nothing more.\n"
|
| 394 |
"At the end of your response, write summary in the following format:\n"
|
| 395 |
-
"Full
|
| 396 |
"- Printer1: $price of full request\n"
|
| 397 |
"- Printer2: $price of full request\n"
|
| 398 |
"- Printer3: $price of full request\n"
|
|
@@ -478,8 +481,6 @@ def render_html_page(chat_text, images_to_use):
|
|
| 478 |
if images_to_use is None:
|
| 479 |
return "<html><body><h3>Requested product is not available.</h3></body></html>"
|
| 480 |
|
| 481 |
-
# product_descriptions = chat_text.split("\n")
|
| 482 |
-
|
| 483 |
html_content = """
|
| 484 |
<html>
|
| 485 |
<head>
|
|
@@ -509,20 +510,24 @@ def render_html_page(chat_text, images_to_use):
|
|
| 509 |
.product-card button:hover {
|
| 510 |
background-color: #45a049;
|
| 511 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 512 |
</style>
|
| 513 |
</head>
|
| 514 |
<body>
|
| 515 |
"""
|
|
|
|
| 516 |
processed_images = [
|
| 517 |
image for img in images_to_use for image in IMAGES[img]["images"]
|
| 518 |
]
|
| 519 |
processed_links = [link for img in images_to_use for link in IMAGES[img]["links"]]
|
| 520 |
-
print(chat_text)
|
| 521 |
processed_prices = extract_total_prices(chat_text)
|
| 522 |
-
|
| 523 |
-
# print(product_descriptions)
|
| 524 |
for i in range(len(processed_images)):
|
| 525 |
-
print(i)
|
| 526 |
image = processed_images[i]
|
| 527 |
with open(image, "rb") as img_file:
|
| 528 |
base64_image = base64.b64encode(img_file.read()).decode("utf-8")
|
|
@@ -530,9 +535,21 @@ def render_html_page(chat_text, images_to_use):
|
|
| 530 |
html_content += f"""
|
| 531 |
<div class="product-card">
|
| 532 |
<img src="data:image/jpeg;base64,{base64_image}" alt="Product Image">
|
| 533 |
-
<p>{COMPANIES[i % 3]+': '+processed_prices[i]}</p>
|
| 534 |
<a href="{processed_links[i]}" target="_blank"><button>Buy Now</button></a>
|
| 535 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 536 |
</div>
|
| 537 |
"""
|
| 538 |
|
|
@@ -563,7 +580,7 @@ iface = gr.Interface(
|
|
| 563 |
|
| 564 |
|
| 565 |
def auth_function(username, password):
|
| 566 |
-
valid_users = {"admin": "demo4anthony1", "
|
| 567 |
return username in valid_users and valid_users[username] == password
|
| 568 |
|
| 569 |
|
|
|
|
| 366 |
f"Printer 1: {printer_1}\n"
|
| 367 |
f"Printer 2: {printer_2}\n"
|
| 368 |
f"Printer 3: {printer_3}\n"
|
| 369 |
+
"For each product in the request, follow these steps:\n"
|
| 370 |
+
"1. Verify if the requested size is available. If the requested size is unavailable, check if the vendor supports custom sizes.\n"
|
| 371 |
+
"2. If the user has not specified one or more parameters (e.g., size, shape), use the vendor's default values for those parameters.\n"
|
| 372 |
+
"3. Apply the custom size multiplier only under the following conditions:\n"
|
| 373 |
+
"- The user explicitly requests a specific size.\n"
|
| 374 |
+
"- The requested size is not standard (i.e., it is custom).\n"
|
| 375 |
+
"- The vendor supports custom sizes.\n"
|
| 376 |
+
"4. Calculate the final price by:\n"
|
| 377 |
" - Finding the nearest lower quantity in the base price list.\n"
|
| 378 |
" - Multiplying by the size multiplier\n"
|
| 379 |
" - Multiplying by the user requested amount. IMPORTANT. Do not multiply by nearest lower quantity!\n"
|
| 380 |
+
"5. Do not use linear interpolation for quantities - use the nearest lower quantity pricing.\n\n"
|
| 381 |
"Example:\n"
|
| 382 |
"User: I want 25 banners in size 6x6, 2000 business cards and 5000 circle stickers in size 6x6 on matte paper\n"
|
| 383 |
"Answer:\n"
|
|
|
|
| 395 |
"- PrintMaster: amount (5000) * multiplier for circle shape (1.0) * multiplier for custom size (2.0) * price per unit for nearest pack size ($0.11). Total for 5000: $1100.00\n\n"
|
| 396 |
"Your response should display ONLY final pricing for each available option, nothing more.\n"
|
| 397 |
"At the end of your response, write summary in the following format:\n"
|
| 398 |
+
"Full quote (all products): *all items, that user's requested*\n"
|
| 399 |
"- Printer1: $price of full request\n"
|
| 400 |
"- Printer2: $price of full request\n"
|
| 401 |
"- Printer3: $price of full request\n"
|
|
|
|
| 481 |
if images_to_use is None:
|
| 482 |
return "<html><body><h3>Requested product is not available.</h3></body></html>"
|
| 483 |
|
|
|
|
|
|
|
| 484 |
html_content = """
|
| 485 |
<html>
|
| 486 |
<head>
|
|
|
|
| 510 |
.product-card button:hover {
|
| 511 |
background-color: #45a049;
|
| 512 |
}
|
| 513 |
+
.summary {
|
| 514 |
+
border-top: 2px solid #ccc;
|
| 515 |
+
padding-top: 16px;
|
| 516 |
+
margin-top: 20px;
|
| 517 |
+
font-family: Arial, sans-serif;
|
| 518 |
+
}
|
| 519 |
</style>
|
| 520 |
</head>
|
| 521 |
<body>
|
| 522 |
"""
|
| 523 |
+
|
| 524 |
processed_images = [
|
| 525 |
image for img in images_to_use for image in IMAGES[img]["images"]
|
| 526 |
]
|
| 527 |
processed_links = [link for img in images_to_use for link in IMAGES[img]["links"]]
|
|
|
|
| 528 |
processed_prices = extract_total_prices(chat_text)
|
| 529 |
+
|
|
|
|
| 530 |
for i in range(len(processed_images)):
|
|
|
|
| 531 |
image = processed_images[i]
|
| 532 |
with open(image, "rb") as img_file:
|
| 533 |
base64_image = base64.b64encode(img_file.read()).decode("utf-8")
|
|
|
|
| 535 |
html_content += f"""
|
| 536 |
<div class="product-card">
|
| 537 |
<img src="data:image/jpeg;base64,{base64_image}" alt="Product Image">
|
| 538 |
+
<p>{COMPANIES[i % 3] + ' ' + images_to_use[i // 3].lower() + ': ' + processed_prices[i]}</p>
|
| 539 |
<a href="{processed_links[i]}" target="_blank"><button>Buy Now</button></a>
|
| 540 |
+
</div>
|
| 541 |
+
"""
|
| 542 |
+
|
| 543 |
+
# Extract the summary from chat_text
|
| 544 |
+
# print(chat_text)
|
| 545 |
+
summary_start = chat_text.find("Full quote (all products):")
|
| 546 |
+
# print(summary_start)
|
| 547 |
+
if summary_start != -1:
|
| 548 |
+
summary_text = chat_text[summary_start:].strip()
|
| 549 |
+
html_content += f"""
|
| 550 |
+
<div class="summary">
|
| 551 |
+
<h3>Quote Summary</h3>
|
| 552 |
+
<pre>{summary_text}</pre>
|
| 553 |
</div>
|
| 554 |
"""
|
| 555 |
|
|
|
|
| 580 |
|
| 581 |
|
| 582 |
def auth_function(username, password):
|
| 583 |
+
valid_users = {"admin": "demo4anthony1", "123": "123"}
|
| 584 |
return username in valid_users and valid_users[username] == password
|
| 585 |
|
| 586 |
|