Yaswanth56 commited on
Commit
10c6cb9
·
verified ·
1 Parent(s): 68d60c1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -12
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, 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):
@@ -64,11 +64,11 @@ def handle_rewards(customer_id, bill_amount, apply_rewards):
64
  except Exception as e:
65
  return f"Error applying rewards: {e}", 0, 0
66
 
67
- # Define the Gradio interface with automatic page transitions
68
  def create_interface():
69
- with gr.Page() as demo:
70
  # Login page
71
- with gr.Column(visible=True) as login_page:
72
  gr.Markdown("### Login to your account")
73
  email_input = gr.Textbox(label="Email", placeholder="Enter your email")
74
  password_input = gr.Textbox(label="Password", placeholder="Enter your password", type="password")
@@ -78,10 +78,10 @@ def create_interface():
78
  reward_points_output = gr.Textbox(label="Available Reward Points", visible=False) # Hidden
79
 
80
  # Action for login button
81
- login_button.click(authenticate_user, inputs=[email_input, password_input], outputs=[login_output, customer_id_output, reward_points_output, gr.update(visible=False), gr.update(visible=True)])
82
 
83
- # Reward points section (Next page after login)
84
- with gr.Column(visible=False) as reward_page:
85
  gr.Markdown("### Reward Points Section")
86
  bill_amount_input = gr.Number(label="Enter Bill Amount", value=0)
87
  apply_rewards_checkbox = gr.Checkbox(label="Apply Reward Points", value=True)
@@ -95,8 +95,8 @@ def create_interface():
95
  inputs=[customer_id_output, bill_amount_input, apply_rewards_checkbox],
96
  outputs=[rewards_message, final_bill_output, remaining_points_output])
97
 
98
- # Final summary page (After calculation)
99
- with gr.Column(visible=False) as summary_page:
100
  gr.Markdown("### Bill Summary")
101
  summary_message = gr.Textbox(label="Summary Message")
102
  final_amount_output = gr.Textbox(label="Final Amount")
 
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):
 
64
  except Exception as e:
65
  return f"Error applying rewards: {e}", 0, 0
66
 
67
+ # Define the Gradio interface
68
  def create_interface():
69
+ with gr.Blocks() as demo:
70
  # Login page
71
+ with gr.Tab("Login"):
72
  gr.Markdown("### Login to your account")
73
  email_input = gr.Textbox(label="Email", placeholder="Enter your email")
74
  password_input = gr.Textbox(label="Password", placeholder="Enter your password", type="password")
 
78
  reward_points_output = gr.Textbox(label="Available Reward Points", visible=False) # Hidden
79
 
80
  # Action for login button
81
+ login_button.click(authenticate_user, inputs=[email_input, password_input], outputs=[login_output, customer_id_output, reward_points_output])
82
 
83
+ # Reward points section (in next tab after login)
84
+ with gr.Tab("Reward Points"):
85
  gr.Markdown("### Reward Points Section")
86
  bill_amount_input = gr.Number(label="Enter Bill Amount", value=0)
87
  apply_rewards_checkbox = gr.Checkbox(label="Apply Reward Points", value=True)
 
95
  inputs=[customer_id_output, bill_amount_input, apply_rewards_checkbox],
96
  outputs=[rewards_message, final_bill_output, remaining_points_output])
97
 
98
+ # Final summary page (after calculation)
99
+ with gr.Tab("Bill Summary"):
100
  gr.Markdown("### Bill Summary")
101
  summary_message = gr.Textbox(label="Summary Message")
102
  final_amount_output = gr.Textbox(label="Final Amount")