Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,6 +15,7 @@ def generate_email(
|
|
| 15 |
template_choice,
|
| 16 |
available_date,
|
| 17 |
solution_choice,
|
|
|
|
| 18 |
):
|
| 19 |
# Process variables that may contain multiple rows.
|
| 20 |
out_of_stock = process_multiline(out_of_stock) if out_of_stock else ""
|
|
@@ -130,14 +131,42 @@ Sincerely,
|
|
| 130 |
Winson Lai
|
| 131 |
Trendy Sweet Shop"""
|
| 132 |
|
| 133 |
-
# --- Order Status
|
| 134 |
-
|
| 135 |
-
template_status = """Dear [variable: customer name],
|
| 136 |
|
|
|
|
|
|
|
|
|
|
| 137 |
Thanks for your order. The tracking number of your package is [variable: tracking number] and below is the tracking link:
|
| 138 |
|
| 139 |
[variable: tracking link]
|
| 140 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
Should you have any further question, please feel free to contact us again. Thanks.
|
| 142 |
|
| 143 |
Regards,
|
|
@@ -157,6 +186,7 @@ Trendy Sweet Shop"""
|
|
| 157 |
email_template = template_std_3
|
| 158 |
else:
|
| 159 |
email_template = template_std_1 # fallback
|
|
|
|
| 160 |
elif template_choice == "Partial Out of Stock":
|
| 161 |
if solution_choice == "Refund or exchange":
|
| 162 |
email_template = template_partial_1
|
|
@@ -166,8 +196,16 @@ Trendy Sweet Shop"""
|
|
| 166 |
email_template = template_partial_3
|
| 167 |
else:
|
| 168 |
email_template = template_partial_1 # fallback
|
|
|
|
| 169 |
elif template_choice == "Order Status":
|
| 170 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
|
| 172 |
# ===== REPLACE PLACEHOLDERS =====
|
| 173 |
email_template = email_template.replace(
|
|
@@ -203,7 +241,7 @@ def update_visibility(template_choice):
|
|
| 203 |
Customer Name, Out of Stock Product, Dispatched Product, Available Date, Solutions dropdown
|
| 204 |
|
| 205 |
- Order Status:
|
| 206 |
-
Customer Name, Tracking Number, Tracking Link
|
| 207 |
"""
|
| 208 |
if template_choice == "Standard out of stock":
|
| 209 |
return (
|
|
@@ -214,6 +252,7 @@ def update_visibility(template_choice):
|
|
| 214 |
gr.update(visible=False), # tracking_link_input
|
| 215 |
gr.update(visible=True), # available_date_input
|
| 216 |
gr.update(visible=True), # solutions_dropdown
|
|
|
|
| 217 |
)
|
| 218 |
elif template_choice == "Partial Out of Stock":
|
| 219 |
return (
|
|
@@ -224,6 +263,7 @@ def update_visibility(template_choice):
|
|
| 224 |
gr.update(visible=False), # tracking_link_input
|
| 225 |
gr.update(visible=True), # available_date_input
|
| 226 |
gr.update(visible=True), # solutions_dropdown
|
|
|
|
| 227 |
)
|
| 228 |
elif template_choice == "Order Status":
|
| 229 |
return (
|
|
@@ -234,6 +274,7 @@ def update_visibility(template_choice):
|
|
| 234 |
gr.update(visible=True), # tracking_link_input
|
| 235 |
gr.update(visible=False), # available_date_input
|
| 236 |
gr.update(visible=False), # solutions_dropdown
|
|
|
|
| 237 |
)
|
| 238 |
else:
|
| 239 |
# Blank / default: hide everything
|
|
@@ -245,6 +286,7 @@ def update_visibility(template_choice):
|
|
| 245 |
gr.update(visible=False),
|
| 246 |
gr.update(visible=False),
|
| 247 |
gr.update(visible=False),
|
|
|
|
| 248 |
)
|
| 249 |
|
| 250 |
|
|
@@ -313,6 +355,18 @@ with gr.Blocks(title="Email Generator") as demo:
|
|
| 313 |
visible=False,
|
| 314 |
)
|
| 315 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 316 |
generate_button = gr.Button("Generate Email")
|
| 317 |
email_output = gr.Textbox(label="Generated Email", lines=15)
|
| 318 |
|
|
@@ -328,6 +382,7 @@ with gr.Blocks(title="Email Generator") as demo:
|
|
| 328 |
tracking_link_input,
|
| 329 |
available_date_input,
|
| 330 |
solutions_dropdown,
|
|
|
|
| 331 |
]
|
| 332 |
)
|
| 333 |
|
|
@@ -343,6 +398,7 @@ with gr.Blocks(title="Email Generator") as demo:
|
|
| 343 |
template_choice,
|
| 344 |
available_date_input,
|
| 345 |
solutions_dropdown,
|
|
|
|
| 346 |
],
|
| 347 |
outputs=email_output
|
| 348 |
)
|
|
|
|
| 15 |
template_choice,
|
| 16 |
available_date,
|
| 17 |
solution_choice,
|
| 18 |
+
status_choice,
|
| 19 |
):
|
| 20 |
# Process variables that may contain multiple rows.
|
| 21 |
out_of_stock = process_multiline(out_of_stock) if out_of_stock else ""
|
|
|
|
| 131 |
Winson Lai
|
| 132 |
Trendy Sweet Shop"""
|
| 133 |
|
| 134 |
+
# --- Order Status templates with "status" dropdown ---
|
|
|
|
|
|
|
| 135 |
|
| 136 |
+
# Status – Option 1: Sent with tracking provided
|
| 137 |
+
template_status_1 = """Dear [variable: customer name],
|
| 138 |
+
|
| 139 |
Thanks for your order. The tracking number of your package is [variable: tracking number] and below is the tracking link:
|
| 140 |
|
| 141 |
[variable: tracking link]
|
| 142 |
|
| 143 |
+
Your package is on its way, and you can monitor the delivery status from the tracking link above.
|
| 144 |
+
|
| 145 |
+
Should you have any further question, please feel free to contact us again. Thanks.
|
| 146 |
+
|
| 147 |
+
Regards,
|
| 148 |
+
|
| 149 |
+
Winson Lai
|
| 150 |
+
Trendy Sweet Shop"""
|
| 151 |
+
|
| 152 |
+
# Status – Option 2: Sent without tracking provided
|
| 153 |
+
template_status_2 = """Dear [variable: customer name],
|
| 154 |
+
|
| 155 |
+
Thank you for your order. We confirm that your package has been dispatched, and the tracking link has been sent to you via our system. If you cannot locate the email, please check your junk or spam folder.
|
| 156 |
+
You can monitor its delivery status using the tracking link provided.
|
| 157 |
+
|
| 158 |
+
Should you have any further question, please feel free to contact us again. Thanks.
|
| 159 |
+
|
| 160 |
+
Regards,
|
| 161 |
+
|
| 162 |
+
Winson Lai
|
| 163 |
+
Trendy Sweet Shop"""
|
| 164 |
+
|
| 165 |
+
# Status – Option 3: To be sent
|
| 166 |
+
template_status_3 = """Dear [variable: customer name],
|
| 167 |
+
|
| 168 |
+
Thanks for your order. Your order is still under processing and we will release the tracking code once available.
|
| 169 |
+
|
| 170 |
Should you have any further question, please feel free to contact us again. Thanks.
|
| 171 |
|
| 172 |
Regards,
|
|
|
|
| 186 |
email_template = template_std_3
|
| 187 |
else:
|
| 188 |
email_template = template_std_1 # fallback
|
| 189 |
+
|
| 190 |
elif template_choice == "Partial Out of Stock":
|
| 191 |
if solution_choice == "Refund or exchange":
|
| 192 |
email_template = template_partial_1
|
|
|
|
| 196 |
email_template = template_partial_3
|
| 197 |
else:
|
| 198 |
email_template = template_partial_1 # fallback
|
| 199 |
+
|
| 200 |
elif template_choice == "Order Status":
|
| 201 |
+
if status_choice == "Sent with tracking provided":
|
| 202 |
+
email_template = template_status_1
|
| 203 |
+
elif status_choice == "Sent without tracking provided":
|
| 204 |
+
email_template = template_status_2
|
| 205 |
+
elif status_choice == "To be sent":
|
| 206 |
+
email_template = template_status_3
|
| 207 |
+
else:
|
| 208 |
+
email_template = template_status_1 # fallback
|
| 209 |
|
| 210 |
# ===== REPLACE PLACEHOLDERS =====
|
| 211 |
email_template = email_template.replace(
|
|
|
|
| 241 |
Customer Name, Out of Stock Product, Dispatched Product, Available Date, Solutions dropdown
|
| 242 |
|
| 243 |
- Order Status:
|
| 244 |
+
Customer Name, Tracking Number, Tracking Link, Status dropdown
|
| 245 |
"""
|
| 246 |
if template_choice == "Standard out of stock":
|
| 247 |
return (
|
|
|
|
| 252 |
gr.update(visible=False), # tracking_link_input
|
| 253 |
gr.update(visible=True), # available_date_input
|
| 254 |
gr.update(visible=True), # solutions_dropdown
|
| 255 |
+
gr.update(visible=False), # status_dropdown
|
| 256 |
)
|
| 257 |
elif template_choice == "Partial Out of Stock":
|
| 258 |
return (
|
|
|
|
| 263 |
gr.update(visible=False), # tracking_link_input
|
| 264 |
gr.update(visible=True), # available_date_input
|
| 265 |
gr.update(visible=True), # solutions_dropdown
|
| 266 |
+
gr.update(visible=False), # status_dropdown
|
| 267 |
)
|
| 268 |
elif template_choice == "Order Status":
|
| 269 |
return (
|
|
|
|
| 274 |
gr.update(visible=True), # tracking_link_input
|
| 275 |
gr.update(visible=False), # available_date_input
|
| 276 |
gr.update(visible=False), # solutions_dropdown
|
| 277 |
+
gr.update(visible=True), # status_dropdown
|
| 278 |
)
|
| 279 |
else:
|
| 280 |
# Blank / default: hide everything
|
|
|
|
| 286 |
gr.update(visible=False),
|
| 287 |
gr.update(visible=False),
|
| 288 |
gr.update(visible=False),
|
| 289 |
+
gr.update(visible=False),
|
| 290 |
)
|
| 291 |
|
| 292 |
|
|
|
|
| 355 |
visible=False,
|
| 356 |
)
|
| 357 |
|
| 358 |
+
# Status dropdown (Order Status)
|
| 359 |
+
status_dropdown = gr.Dropdown(
|
| 360 |
+
choices=[
|
| 361 |
+
"Sent with tracking provided",
|
| 362 |
+
"Sent without tracking provided",
|
| 363 |
+
"To be sent",
|
| 364 |
+
],
|
| 365 |
+
value="Sent with tracking provided",
|
| 366 |
+
label="Status",
|
| 367 |
+
visible=False,
|
| 368 |
+
)
|
| 369 |
+
|
| 370 |
generate_button = gr.Button("Generate Email")
|
| 371 |
email_output = gr.Textbox(label="Generated Email", lines=15)
|
| 372 |
|
|
|
|
| 382 |
tracking_link_input,
|
| 383 |
available_date_input,
|
| 384 |
solutions_dropdown,
|
| 385 |
+
status_dropdown,
|
| 386 |
]
|
| 387 |
)
|
| 388 |
|
|
|
|
| 398 |
template_choice,
|
| 399 |
available_date_input,
|
| 400 |
solutions_dropdown,
|
| 401 |
+
status_dropdown,
|
| 402 |
],
|
| 403 |
outputs=email_output
|
| 404 |
)
|