Spaces:
Sleeping
Sleeping
File size: 7,876 Bytes
13eab12 07184f5 b65aa70 07184f5 b65aa70 07184f5 b65aa70 337e19c 13eab12 1bc9da9 13eab12 1bc9da9 13eab12 1bc9da9 13eab12 1bc9da9 13eab12 b65aa70 1bc9da9 13eab12 1bc9da9 13eab12 1bc9da9 7e36be2 13eab12 1bc9da9 13eab12 1bc9da9 7e36be2 b65aa70 7e36be2 b65aa70 7e36be2 b65aa70 7e36be2 337e19c 13eab12 7e36be2 337e19c 13eab12 07184f5 b65aa70 13eab12 07184f5 13eab12 b65aa70 7e36be2 07184f5 b65aa70 7e36be2 13eab12 337e19c 13eab12 b65aa70 13eab12 a9b40df b65aa70 a9b40df |
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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
import gradio as gr
def process_multiline(variable):
# If variable is a list (multiple rows), join them with newlines.
if isinstance(variable, list):
return "\n".join(variable)
return variable
def generate_email(customer_name, out_of_stock, dispatched, customer_address, delivered_date, tracking_link, tracking_number, template_choice):
# Process variables that may contain multiple rows.
out_of_stock = process_multiline(out_of_stock) if out_of_stock else ""
dispatched = process_multiline(dispatched) if dispatched else ""
customer_address = process_multiline(customer_address) if customer_address else ""
tracking_link = process_multiline(tracking_link) if tracking_link else ""
# delivered_date and tracking_number are single row variables, so we use them as is.
# Define the email templates with placeholders.
template1 = """Dear [variable: customer name],
Thank you for your recent order. We regret to inform you that, according to our vendor, the below product you have ordered are currently out of stock:
[variable: out of stock product]
Since we do not have an estimated time of when it will be back in stock at this moment, as a solution, we would like to offer you either a refund or an exchange for an alternative model. We understand that this situation may have caused inconvenience and we sincerely apologize for that.
Please let us know your preference by replying to this email and we will take care of the rest. If you have any further questions or concerns, please do not hesitate to reach out to us.
Sincerely,
Winson Lai
Trendy Sweet Shop"""
template2 = """Dear [variable: customer name],
Thanks for your order. We would like to update you your order status as following:
Out of Stock:
[variable: out of stock product]
Dispatched:
[variable: dispatched product]
Since we do not have an estimated time of when the outstanding item will be back in stock at this moment, as a solution, we would like to offer you either a refund or an exchange for an alternative model. We understand that this situation may have caused inconvenience and we sincerely apologize for that.
Please let us know your preference by replying to this email and we will take care of the rest. If you have any further questions or concerns, please do not hesitate to reach out to us.
Sincerely,
Winson Lai
Trendy Sweet Shop"""
template3 = """Dear [variable: customer name],
Thank you for your recent order. According to tracking information from both DHL and USPS, your package was successfully delivered on [variable: delivered date]. You can verify the delivery status using the following tracking links:
[variable: tracking link]
The package was sent to the following address:
[variable: customer address]
Since the tracking details indicate a successful delivery, we recommend checking the usual delivery locations at your residence. If you're unable to locate the package, please contact USPS directly with the tracking number [variable: tracking number] for further assistance.
If you have any additional questions or need further support, feel free to reach out to us.
Best regards,
Winson Lai
Trendy Sweet Shop"""
# New "Order Status" template
template4 = """Dear [variable: customer name],
Thanks for your order. The tracking number of your package is [variable: tracking number] and below is the tracking link:
[variable: tracking link]
Should you have any further question, please feel free to contact us again. Thanks.
Regards,
Winson Lai
Trendy Sweet Shop"""
# Choose the email template based on the dropdown selection.
if template_choice == "Standard out of stock":
email_template = template1
elif template_choice == "Partial Out of Stock":
email_template = template2
elif template_choice == "US not received":
email_template = template3
elif template_choice == "Order Status":
email_template = template4
else:
email_template = ""
# Replace the placeholders with the input values.
email_template = email_template.replace("[variable: customer name]", customer_name if customer_name else "")
email_template = email_template.replace("[variable: out of stock product]", out_of_stock)
email_template = email_template.replace("[variable: dispatched product]", dispatched)
email_template = email_template.replace("[variable: customer address]", customer_address)
email_template = email_template.replace("[variable: delivered date]", delivered_date if delivered_date else "")
email_template = email_template.replace("[variable: tracking link]", tracking_link)
email_template = email_template.replace("[variable: tracking number]", tracking_number if tracking_number else "")
return email_template
with gr.Blocks(title="Email Generator") as demo:
gr.Markdown("# Email Generator")
# Input fields for the variables.
with gr.Row():
customer_name_input = gr.Textbox(label="Customer Name", placeholder="Enter customer name")
out_of_stock_input = gr.Textbox(label="Out of Stock Product", placeholder="Enter out-of-stock product (one per row)", lines=3)
dispatched_input = gr.Textbox(label="Dispatched Product", placeholder="Enter dispatched product (if any, one per row)", lines=3)
# New input fields for customer address, delivered date, tracking link, and tracking number.
with gr.Row():
customer_address_input = gr.Textbox(label="Customer Address", placeholder="Enter customer address (one per row)", lines=3)
with gr.Row():
delivered_date_input = gr.Textbox(label="Delivered Date", placeholder="Enter delivered date (single row)")
tracking_number_input = gr.Textbox(label="Tracking Number", placeholder="Enter tracking number (single row)")
with gr.Row():
tracking_link_input = gr.Textbox(label="Tracking Link", placeholder="Enter tracking link (one per row)", lines=3)
# Dropdown for selecting the email template.
template_choice = gr.Dropdown(
choices=["Standard out of stock", "Partial Out of Stock", "US not received", "Order Status"],
label="Select Email Template"
)
generate_button = gr.Button("Generate Email")
email_output = gr.Textbox(label="Generated Email", lines=15)
# When the button is clicked, generate_email() is called.
generate_button.click(
fn=generate_email,
inputs=[
customer_name_input,
out_of_stock_input,
dispatched_input,
customer_address_input,
delivered_date_input,
tracking_link_input,
tracking_number_input,
template_choice
],
outputs=email_output
)
# Added hyperlink block with separate sections for Shipping Tools and Administration Tools.
gr.HTML(
"""
<div style="text-align: center; font-size: 16px; margin-top: 20px;">
<h3>Shipping Tools</h3>
<a href="https://huggingface.co/spaces/leadingbridge/shipping-dhl-e-commerce">DHL</a> |
<a href="https://huggingface.co/spaces/leadingbridge/shipping-ec-ship">EC-Ship</a> |
<a href="https://huggingface.co/spaces/leadingbridge/shipping-fedex">Fedex</a> |
<a href="https://huggingface.co/spaces/leadingbridge/shipping-UPS">UPS</a>
</div>
<div style="text-align: center; font-size: 16px; margin-top: 20px;">
<h3>Administration Tools</h3>
<a href="https://huggingface.co/spaces/leadingbridge/email-template">Email Template</a> |
<a href="https://huggingface.co/spaces/leadingbridge/product-feed">Google Merchant</a> |
<a href="https://huggingface.co/spaces/leadingbridge/tss-order">Order Processing</a>
</div>
"""
)
demo.launch()
|