Yaswanth56 commited on
Commit
ea3b616
·
verified ·
1 Parent(s): 00fb1c3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -10
app.py CHANGED
@@ -22,21 +22,21 @@ except Exception as e:
22
  # Function to handle user authentication and Salesforce login
23
  def authenticate_user(email, password):
24
  if not sf:
25
- return "Salesforce connection failed. Please check credentials and try again.", None, None
26
 
27
  try:
28
  query = f"SELECT Id, Reward_Points__c FROM Customer_Login__c WHERE Email__c = '{email}' AND Password__c = '{password}'"
29
  result = sf.query(query)
30
 
31
  if result['totalSize'] == 0:
32
- return "Invalid Login Details", None, None
33
 
34
  customer = result['records'][0]
35
  reward_points = customer['Reward_Points__c']
36
 
37
- return f"Welcome, you have {reward_points} points. Proceed to rewards.", customer['Id'], reward_points
38
  except Exception as e:
39
- return f"Error during authentication: {e}", None, None
40
 
41
  # Function to handle reward points logic
42
  def handle_rewards(customer_id, bill_amount, apply_rewards):
@@ -76,11 +76,9 @@ def create_interface():
76
  customer_id_output = gr.Textbox(label="Customer ID", visible=False) # Hidden
77
  reward_points_output = gr.Textbox(label="Available Reward Points", visible=False) # Hidden
78
 
79
- # Action for login button
80
- login_button.click(authenticate_user, inputs=[email_input, password_input], outputs=[login_output, customer_id_output, reward_points_output])
81
-
82
- # Reward points section - no customer ID input
83
- gr.Markdown("### Reward Points Section")
84
  bill_amount_input = gr.Number(label="Enter Bill Amount", value=0)
85
  apply_rewards_checkbox = gr.Checkbox(label="Apply Reward Points", value=True)
86
  rewards_button = gr.Button("Calculate Bill")
@@ -88,6 +86,9 @@ def create_interface():
88
  final_bill_output = gr.Textbox(label="Final Bill Amount")
89
  remaining_points_output = gr.Textbox(label="Remaining Points")
90
 
 
 
 
91
  # Action for rewards calculation
92
  rewards_button.click(handle_rewards,
93
  inputs=[customer_id_output, bill_amount_input, apply_rewards_checkbox],
@@ -99,4 +100,3 @@ def create_interface():
99
  if __name__ == "__main__":
100
  demo = create_interface()
101
  demo.launch()
102
-
 
22
  # Function to handle user authentication and Salesforce login
23
  def authenticate_user(email, password):
24
  if not sf:
25
+ return "Salesforce connection failed. Please check credentials and try again.", None, None, gr.update(visible=False), gr.update(visible=False)
26
 
27
  try:
28
  query = f"SELECT Id, Reward_Points__c FROM Customer_Login__c WHERE Email__c = '{email}' AND Password__c = '{password}'"
29
  result = sf.query(query)
30
 
31
  if result['totalSize'] == 0:
32
+ return "Invalid Login Details", None, None, gr.update(visible=False), gr.update(visible=False)
33
 
34
  customer = result['records'][0]
35
  reward_points = customer['Reward_Points__c']
36
 
37
+ return f"Welcome, you have {reward_points} points. Proceed to rewards.", customer['Id'], reward_points, gr.update(visible=True), gr.update(visible=True)
38
  except Exception as e:
39
+ return f"Error during authentication: {e}", None, None, gr.update(visible=False), gr.update(visible=False)
40
 
41
  # Function to handle reward points logic
42
  def handle_rewards(customer_id, bill_amount, apply_rewards):
 
76
  customer_id_output = gr.Textbox(label="Customer ID", visible=False) # Hidden
77
  reward_points_output = gr.Textbox(label="Available Reward Points", visible=False) # Hidden
78
 
79
+ # Reward points section (Initially hidden)
80
+ reward_section = gr.Column(visible=False)
81
+ gr.Markdown("### Reward Points Section", elem_id="reward_section")
 
 
82
  bill_amount_input = gr.Number(label="Enter Bill Amount", value=0)
83
  apply_rewards_checkbox = gr.Checkbox(label="Apply Reward Points", value=True)
84
  rewards_button = gr.Button("Calculate Bill")
 
86
  final_bill_output = gr.Textbox(label="Final Bill Amount")
87
  remaining_points_output = gr.Textbox(label="Remaining Points")
88
 
89
+ # Action for login button
90
+ login_button.click(authenticate_user, inputs=[email_input, password_input], outputs=[login_output, customer_id_output, reward_points_output, reward_section, bill_amount_input])
91
+
92
  # Action for rewards calculation
93
  rewards_button.click(handle_rewards,
94
  inputs=[customer_id_output, bill_amount_input, apply_rewards_checkbox],
 
100
  if __name__ == "__main__":
101
  demo = create_interface()
102
  demo.launch()