leadingbridge commited on
Commit
07184f5
·
verified ·
1 Parent(s): 7e36be2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -8
app.py CHANGED
@@ -1,6 +1,18 @@
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:
@@ -63,10 +75,10 @@ Trendy Sweet Shop"""
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
 
@@ -76,13 +88,13 @@ with gr.Blocks(title="Email Generator") as demo:
76
  # Input fields for the variables.
77
  with gr.Row():
78
  customer_name_input = gr.Textbox(label="Customer Name", placeholder="Enter customer name")
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(
 
1
  import gradio as gr
2
 
3
+ def process_multiline(variable):
4
+ # If variable is a list (multiple rows), join them with newlines.
5
+ if isinstance(variable, list):
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:
 
75
 
76
  # Replace the placeholders with the input values.
77
  email_template = email_template.replace("[variable: customer name]", customer_name if customer_name else "")
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
 
 
88
  # Input fields for the variables.
89
  with gr.Row():
90
  customer_name_input = gr.Textbox(label="Customer Name", placeholder="Enter customer name")
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(