Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
def generate_email(customer_name, out_of_stock, dispatched, template_choice):
|
4 |
-
# Define the
|
5 |
template1 = """Dear [variable: customer name],
|
6 |
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:
|
7 |
|
@@ -24,11 +24,30 @@ Out of Stock:
|
|
24 |
Dispatched:
|
25 |
[variable: dispatched product]
|
26 |
|
27 |
-
Since we do not have an estimated time of when the outstanding item will be back in stock at this moment,
|
28 |
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.
|
29 |
|
30 |
Sincerely,
|
31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
Winson Lai
|
33 |
Trendy Sweet Shop"""
|
34 |
|
@@ -37,14 +56,17 @@ Trendy Sweet Shop"""
|
|
37 |
email_template = template1
|
38 |
elif template_choice == "Partial Out of Stock":
|
39 |
email_template = template2
|
|
|
|
|
40 |
else:
|
41 |
email_template = ""
|
42 |
|
43 |
# Replace the placeholders with the input values.
|
44 |
-
# If no value is provided, the placeholder will be replaced with an empty string.
|
45 |
email_template = email_template.replace("[variable: customer name]", customer_name if customer_name else "")
|
46 |
email_template = email_template.replace("[variable: out of stock product]", out_of_stock if out_of_stock else "")
|
47 |
email_template = email_template.replace("[variable: dispatched product]", dispatched if dispatched else "")
|
|
|
|
|
48 |
|
49 |
return email_template
|
50 |
|
@@ -57,9 +79,14 @@ with gr.Blocks(title="Email Generator") as demo:
|
|
57 |
out_of_stock_input = gr.Textbox(label="Out of Stock Product", placeholder="Enter out-of-stock product")
|
58 |
dispatched_input = gr.Textbox(label="Dispatched Product", placeholder="Enter dispatched product (if any)")
|
59 |
|
|
|
|
|
|
|
|
|
|
|
60 |
# Dropdown for selecting the email template.
|
61 |
template_choice = gr.Dropdown(
|
62 |
-
choices=["Standard out of stock", "Partial Out of Stock"],
|
63 |
label="Select Email Template"
|
64 |
)
|
65 |
|
@@ -69,8 +96,8 @@ with gr.Blocks(title="Email Generator") as demo:
|
|
69 |
# When the button is clicked, generate_email() is called.
|
70 |
generate_button.click(
|
71 |
fn=generate_email,
|
72 |
-
inputs=[customer_name_input, out_of_stock_input, dispatched_input, template_choice],
|
73 |
outputs=email_output
|
74 |
)
|
75 |
|
76 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
+
def generate_email(customer_name, out_of_stock, dispatched, customer_address, tracking_number, template_choice):
|
4 |
+
# Define the three email templates with placeholders.
|
5 |
template1 = """Dear [variable: customer name],
|
6 |
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:
|
7 |
|
|
|
24 |
Dispatched:
|
25 |
[variable: dispatched product]
|
26 |
|
27 |
+
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.
|
28 |
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.
|
29 |
|
30 |
Sincerely,
|
31 |
|
32 |
+
Winson Lai
|
33 |
+
Trendy Sweet Shop"""
|
34 |
+
|
35 |
+
template3 = """Dear [variable: customer name],
|
36 |
+
|
37 |
+
Thank you for your recent order. According to tracking information from both DHL and USPS, your package was successfully delivered on February 20. You can verify the delivery status using the following tracking links:
|
38 |
+
|
39 |
+
[variable: tracking number]
|
40 |
+
|
41 |
+
The package was sent to the following address:
|
42 |
+
|
43 |
+
[variable: customer address]
|
44 |
+
|
45 |
+
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 9261290339726603626251 for further assistance.
|
46 |
+
|
47 |
+
If you have any additional questions or need further support, feel free to reach out to us.
|
48 |
+
|
49 |
+
Best regards,
|
50 |
+
|
51 |
Winson Lai
|
52 |
Trendy Sweet Shop"""
|
53 |
|
|
|
56 |
email_template = template1
|
57 |
elif template_choice == "Partial Out of Stock":
|
58 |
email_template = template2
|
59 |
+
elif template_choice == "US not received":
|
60 |
+
email_template = template3
|
61 |
else:
|
62 |
email_template = ""
|
63 |
|
64 |
# Replace the placeholders with the input values.
|
|
|
65 |
email_template = email_template.replace("[variable: customer name]", customer_name if customer_name else "")
|
66 |
email_template = email_template.replace("[variable: out of stock product]", out_of_stock if out_of_stock else "")
|
67 |
email_template = email_template.replace("[variable: dispatched product]", dispatched if dispatched else "")
|
68 |
+
email_template = email_template.replace("[variable: customer address]", customer_address if customer_address else "")
|
69 |
+
email_template = email_template.replace("[variable: tracking number]", tracking_number if tracking_number else "")
|
70 |
|
71 |
return email_template
|
72 |
|
|
|
79 |
out_of_stock_input = gr.Textbox(label="Out of Stock Product", placeholder="Enter out-of-stock product")
|
80 |
dispatched_input = gr.Textbox(label="Dispatched Product", placeholder="Enter dispatched product (if any)")
|
81 |
|
82 |
+
# New input fields for customer address and tracking number.
|
83 |
+
with gr.Row():
|
84 |
+
customer_address_input = gr.Textbox(label="Customer Address", placeholder="Enter customer address", lines=2)
|
85 |
+
tracking_number_input = gr.Textbox(label="Tracking Number", placeholder="Enter tracking number", lines=1)
|
86 |
+
|
87 |
# Dropdown for selecting the email template.
|
88 |
template_choice = gr.Dropdown(
|
89 |
+
choices=["Standard out of stock", "Partial Out of Stock", "US not received"],
|
90 |
label="Select Email Template"
|
91 |
)
|
92 |
|
|
|
96 |
# When the button is clicked, generate_email() is called.
|
97 |
generate_button.click(
|
98 |
fn=generate_email,
|
99 |
+
inputs=[customer_name_input, out_of_stock_input, dispatched_input, customer_address_input, tracking_number_input, template_choice],
|
100 |
outputs=email_output
|
101 |
)
|
102 |
|
103 |
+
demo.launch()
|