Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -34,7 +34,7 @@ def authenticate_user(email, password):
|
|
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."
|
38 |
except Exception as e:
|
39 |
return f"Error during authentication: {e}"
|
40 |
|
@@ -49,18 +49,17 @@ def handle_rewards(customer_id, bill_amount, apply_rewards):
|
|
49 |
discount = 0.1 * bill_amount
|
50 |
final_bill = bill_amount - discount + gst
|
51 |
updated_points = points - 500
|
52 |
-
|
53 |
-
sf.Customer_Login__c.update(customer_id, {'Reward_Points__c': updated_points})
|
54 |
message = "You saved 10% on your total bill!"
|
55 |
else:
|
56 |
discount = 0
|
57 |
earned_points = 0.1 * bill_amount
|
58 |
final_bill = bill_amount + gst
|
59 |
updated_points = points + earned_points
|
60 |
-
|
61 |
-
sf.Customer_Login__c.update(customer_id, {'Reward_Points__c': updated_points})
|
62 |
message = f"You earned {earned_points:.2f} reward points!"
|
63 |
|
|
|
|
|
|
|
64 |
return message, final_bill, updated_points
|
65 |
except Exception as e:
|
66 |
return f"Error applying rewards: {e}", 0, 0
|
@@ -68,28 +67,28 @@ def handle_rewards(customer_id, bill_amount, apply_rewards):
|
|
68 |
# Define the Gradio interface
|
69 |
def create_interface():
|
70 |
with gr.Blocks() as demo:
|
|
|
71 |
gr.Markdown("### Login to your account")
|
72 |
email_input = gr.Textbox(label="Email", placeholder="Enter your email")
|
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)
|
79 |
-
|
80 |
-
# Reward points section
|
81 |
gr.Markdown("### Reward Points Section")
|
82 |
-
|
83 |
-
bill_amount_input = gr.Number(label="Enter Bill Amount", minimum=0) # Use `minimum` instead of `min`
|
84 |
apply_rewards_checkbox = gr.Checkbox(label="Apply Reward Points", value=True)
|
85 |
rewards_button = gr.Button("Calculate Bill")
|
86 |
rewards_message = gr.Textbox(label="Message")
|
87 |
final_bill_output = gr.Textbox(label="Final Bill Amount")
|
88 |
remaining_points_output = gr.Textbox(label="Remaining Points")
|
89 |
-
|
90 |
# Action for rewards calculation
|
91 |
rewards_button.click(handle_rewards,
|
92 |
-
inputs=[
|
93 |
outputs=[rewards_message, final_bill_output, remaining_points_output])
|
94 |
|
95 |
return demo
|
|
|
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 |
|
|
|
49 |
discount = 0.1 * bill_amount
|
50 |
final_bill = bill_amount - discount + gst
|
51 |
updated_points = points - 500
|
|
|
|
|
52 |
message = "You saved 10% on your total bill!"
|
53 |
else:
|
54 |
discount = 0
|
55 |
earned_points = 0.1 * bill_amount
|
56 |
final_bill = bill_amount + gst
|
57 |
updated_points = points + earned_points
|
|
|
|
|
58 |
message = f"You earned {earned_points:.2f} reward points!"
|
59 |
|
60 |
+
# Update the customer's reward points in Salesforce
|
61 |
+
sf.Customer_Login__c.update(customer_id, {'Reward_Points__c': updated_points})
|
62 |
+
|
63 |
return message, final_bill, updated_points
|
64 |
except Exception as e:
|
65 |
return f"Error applying rewards: {e}", 0, 0
|
|
|
67 |
# Define the Gradio interface
|
68 |
def create_interface():
|
69 |
with gr.Blocks() as demo:
|
70 |
+
# Login section
|
71 |
gr.Markdown("### Login to your account")
|
72 |
email_input = gr.Textbox(label="Email", placeholder="Enter your email")
|
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)
|
|
|
83 |
apply_rewards_checkbox = gr.Checkbox(label="Apply Reward Points", value=True)
|
84 |
rewards_button = gr.Button("Calculate Bill")
|
85 |
rewards_message = gr.Textbox(label="Message")
|
86 |
final_bill_output = gr.Textbox(label="Final Bill Amount")
|
87 |
remaining_points_output = gr.Textbox(label="Remaining Points")
|
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
|