leadingbridge commited on
Commit
b65aa70
·
verified ·
1 Parent(s): fd0216a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -12
app.py CHANGED
@@ -6,14 +6,15 @@ def process_multiline(variable):
6
  return "\n".join(variable)
7
  return variable
8
 
9
- def generate_email(customer_name, out_of_stock, dispatched, customer_address, tracking_number, template_choice):
10
  # Process variables that may contain multiple rows.
11
  out_of_stock = process_multiline(out_of_stock) if out_of_stock else ""
12
  dispatched = process_multiline(dispatched) if dispatched else ""
13
  customer_address = process_multiline(customer_address) if customer_address else ""
14
- tracking_number = process_multiline(tracking_number) if tracking_number else ""
 
15
 
16
- # Define the three email templates with placeholders.
17
  template1 = """Dear [variable: customer name],
18
  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:
19
 
@@ -28,7 +29,7 @@ Winson Lai
28
  Trendy Sweet Shop"""
29
 
30
  template2 = """Dear [variable: customer name],
31
- Thanks for your order. We would like to update you your order status as following :
32
 
33
  Out of Stock:
34
  [variable: out of stock product]
@@ -46,15 +47,15 @@ Trendy Sweet Shop"""
46
 
47
  template3 = """Dear [variable: customer name],
48
 
49
- 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:
50
 
51
- [variable: tracking number]
52
 
53
  The package was sent to the following address:
54
 
55
  [variable: customer address]
56
 
57
- 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.
58
 
59
  If you have any additional questions or need further support, feel free to reach out to us.
60
 
@@ -78,7 +79,9 @@ Trendy Sweet Shop"""
78
  email_template = email_template.replace("[variable: out of stock product]", out_of_stock)
79
  email_template = email_template.replace("[variable: dispatched product]", dispatched)
80
  email_template = email_template.replace("[variable: customer address]", customer_address)
81
- email_template = email_template.replace("[variable: tracking number]", tracking_number)
 
 
82
 
83
  return email_template
84
 
@@ -91,10 +94,14 @@ with gr.Blocks(title="Email Generator") as demo:
91
  out_of_stock_input = gr.Textbox(label="Out of Stock Product", placeholder="Enter out-of-stock product (one per row)", lines=3)
92
  dispatched_input = gr.Textbox(label="Dispatched Product", placeholder="Enter dispatched product (if any, one per row)", lines=3)
93
 
94
- # New input fields for customer address and tracking number.
95
  with gr.Row():
96
  customer_address_input = gr.Textbox(label="Customer Address", placeholder="Enter customer address (one per row)", lines=3)
97
- tracking_number_input = gr.Textbox(label="Tracking Number", placeholder="Enter tracking number (one per row)", lines=3)
 
 
 
 
98
 
99
  # Dropdown for selecting the email template.
100
  template_choice = gr.Dropdown(
@@ -108,8 +115,17 @@ with gr.Blocks(title="Email Generator") as demo:
108
  # When the button is clicked, generate_email() is called.
109
  generate_button.click(
110
  fn=generate_email,
111
- inputs=[customer_name_input, out_of_stock_input, dispatched_input, customer_address_input, tracking_number_input, template_choice],
 
 
 
 
 
 
 
 
 
112
  outputs=email_output
113
  )
114
 
115
- demo.launch()
 
6
  return "\n".join(variable)
7
  return variable
8
 
9
+ def generate_email(customer_name, out_of_stock, dispatched, customer_address, delivered_date, tracking_link, tracking_number, template_choice):
10
  # Process variables that may contain multiple rows.
11
  out_of_stock = process_multiline(out_of_stock) if out_of_stock else ""
12
  dispatched = process_multiline(dispatched) if dispatched else ""
13
  customer_address = process_multiline(customer_address) if customer_address else ""
14
+ tracking_link = process_multiline(tracking_link) if tracking_link else ""
15
+ # delivered_date and tracking_number are single row variables, so we use them as is.
16
 
17
+ # Define the email templates with placeholders.
18
  template1 = """Dear [variable: customer name],
19
  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:
20
 
 
29
  Trendy Sweet Shop"""
30
 
31
  template2 = """Dear [variable: customer name],
32
+ Thanks for your order. We would like to update you your order status as following:
33
 
34
  Out of Stock:
35
  [variable: out of stock product]
 
47
 
48
  template3 = """Dear [variable: customer name],
49
 
50
+ 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:
51
 
52
+ [variable: tracking link]
53
 
54
  The package was sent to the following address:
55
 
56
  [variable: customer address]
57
 
58
+ 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.
59
 
60
  If you have any additional questions or need further support, feel free to reach out to us.
61
 
 
79
  email_template = email_template.replace("[variable: out of stock product]", out_of_stock)
80
  email_template = email_template.replace("[variable: dispatched product]", dispatched)
81
  email_template = email_template.replace("[variable: customer address]", customer_address)
82
+ email_template = email_template.replace("[variable: delivered date]", delivered_date if delivered_date else "")
83
+ email_template = email_template.replace("[variable: tracking link]", tracking_link)
84
+ email_template = email_template.replace("[variable: tracking number]", tracking_number if tracking_number else "")
85
 
86
  return email_template
87
 
 
94
  out_of_stock_input = gr.Textbox(label="Out of Stock Product", placeholder="Enter out-of-stock product (one per row)", lines=3)
95
  dispatched_input = gr.Textbox(label="Dispatched Product", placeholder="Enter dispatched product (if any, one per row)", lines=3)
96
 
97
+ # New input fields for customer address, delivered date, tracking link, and tracking number.
98
  with gr.Row():
99
  customer_address_input = gr.Textbox(label="Customer Address", placeholder="Enter customer address (one per row)", lines=3)
100
+ with gr.Row():
101
+ delivered_date_input = gr.Textbox(label="Delivered Date", placeholder="Enter delivered date (single row)")
102
+ tracking_number_input = gr.Textbox(label="Tracking Number", placeholder="Enter tracking number (single row)")
103
+ with gr.Row():
104
+ tracking_link_input = gr.Textbox(label="Tracking Link", placeholder="Enter tracking link (one per row)", lines=3)
105
 
106
  # Dropdown for selecting the email template.
107
  template_choice = gr.Dropdown(
 
115
  # When the button is clicked, generate_email() is called.
116
  generate_button.click(
117
  fn=generate_email,
118
+ inputs=[
119
+ customer_name_input,
120
+ out_of_stock_input,
121
+ dispatched_input,
122
+ customer_address_input,
123
+ delivered_date_input,
124
+ tracking_link_input,
125
+ tracking_number_input,
126
+ template_choice
127
+ ],
128
  outputs=email_output
129
  )
130
 
131
+ demo.launch()