Yaswanth56 commited on
Commit
5076acb
·
verified ·
1 Parent(s): 6d50503

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
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."
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"
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}"
40
 
41
  # Function to handle reward points logic
42
  def handle_rewards(customer_id, bill_amount, apply_rewards):
@@ -73,10 +73,12 @@ def create_interface():
73
  password_input = gr.Textbox(label="Password", placeholder="Enter your password", type="password")
74
  login_button = gr.Button("Login")
75
  login_output = gr.Textbox(label="Status")
76
-
 
 
77
  # Action for login button
78
- login_button.click(authenticate_user, inputs=[email_input, password_input], outputs=[login_output, "customer_id", "points"])
79
-
80
  # Reward points section - no customer ID input
81
  gr.Markdown("### Reward Points Section")
82
  bill_amount_input = gr.Number(label="Enter Bill Amount", min=0)
@@ -88,7 +90,7 @@ def create_interface():
88
 
89
  # Action for rewards calculation
90
  rewards_button.click(handle_rewards,
91
- inputs=["customer_id", bill_amount_input, apply_rewards_checkbox],
92
  outputs=[rewards_message, final_bill_output, remaining_points_output])
93
 
94
  return demo
@@ -96,4 +98,4 @@ def create_interface():
96
  # Run the Gradio interface
97
  if __name__ == "__main__":
98
  demo = create_interface()
99
- demo.launch()
 
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.", "", 0
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", "", 0
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}", "", 0
40
 
41
  # Function to handle reward points logic
42
  def handle_rewards(customer_id, bill_amount, apply_rewards):
 
73
  password_input = gr.Textbox(label="Password", placeholder="Enter your password", type="password")
74
  login_button = gr.Button("Login")
75
  login_output = gr.Textbox(label="Status")
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", min=0)
 
90
 
91
  # Action for rewards calculation
92
  rewards_button.click(handle_rewards,
93
+ inputs=[customer_id_output, bill_amount_input, apply_rewards_checkbox],
94
  outputs=[rewards_message, final_bill_output, remaining_points_output])
95
 
96
  return demo
 
98
  # Run the Gradio interface
99
  if __name__ == "__main__":
100
  demo = create_interface()
101
+ demo.launch()