Update app.py
Browse files
app.py
CHANGED
|
@@ -31,9 +31,8 @@ def authenticate_user(email, password):
|
|
| 31 |
if result['totalSize'] == 0:
|
| 32 |
return "Invalid Login Details", None, None, gr.update(visible=False), gr.update(visible=False)
|
| 33 |
|
| 34 |
-
# Ensure we get the correct record
|
| 35 |
customer = result['records'][0]
|
| 36 |
-
reward_points = customer
|
| 37 |
|
| 38 |
return f"Welcome, you have {reward_points} points. Proceed to rewards.", customer['Id'], reward_points, gr.update(visible=True), gr.update(visible=True)
|
| 39 |
except Exception as e:
|
|
@@ -42,9 +41,8 @@ def authenticate_user(email, password):
|
|
| 42 |
# Function to handle reward points logic
|
| 43 |
def handle_rewards(customer_id, bill_amount, apply_rewards):
|
| 44 |
try:
|
| 45 |
-
# Ensure the customer exists in Salesforce
|
| 46 |
customer = sf.Customer_Login__c.get(customer_id)
|
| 47 |
-
points = customer
|
| 48 |
gst = 0.18 * bill_amount
|
| 49 |
|
| 50 |
if points >= 500 and apply_rewards:
|
|
@@ -66,9 +64,9 @@ def handle_rewards(customer_id, bill_amount, apply_rewards):
|
|
| 66 |
except Exception as e:
|
| 67 |
return f"Error applying rewards: {e}", 0, 0
|
| 68 |
|
| 69 |
-
# Define the Gradio interface with page
|
| 70 |
def create_interface():
|
| 71 |
-
with gr.
|
| 72 |
# Login page
|
| 73 |
with gr.Column(visible=True) as login_page:
|
| 74 |
gr.Markdown("### Login to your account")
|
|
@@ -97,6 +95,18 @@ def create_interface():
|
|
| 97 |
inputs=[customer_id_output, bill_amount_input, apply_rewards_checkbox],
|
| 98 |
outputs=[rewards_message, final_bill_output, remaining_points_output])
|
| 99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
return demo
|
| 101 |
|
| 102 |
# Run the Gradio interface
|
|
|
|
| 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:
|
|
|
|
| 41 |
# Function to handle reward points logic
|
| 42 |
def handle_rewards(customer_id, bill_amount, apply_rewards):
|
| 43 |
try:
|
|
|
|
| 44 |
customer = sf.Customer_Login__c.get(customer_id)
|
| 45 |
+
points = customer['Reward_Points__c']
|
| 46 |
gst = 0.18 * bill_amount
|
| 47 |
|
| 48 |
if points >= 500 and 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")
|
|
|
|
| 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")
|
| 103 |
+
remaining_points = gr.Textbox(label="Remaining Points")
|
| 104 |
+
|
| 105 |
+
# This page will show the message and final bill when handled in rewards calculation
|
| 106 |
+
rewards_button.click(handle_rewards,
|
| 107 |
+
inputs=[customer_id_output, bill_amount_input, apply_rewards_checkbox],
|
| 108 |
+
outputs=[summary_message, final_amount_output, remaining_points])
|
| 109 |
+
|
| 110 |
return demo
|
| 111 |
|
| 112 |
# Run the Gradio interface
|