Update app.py
Browse files
app.py
CHANGED
|
@@ -1,102 +1,47 @@
|
|
| 1 |
-
import
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
)
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
if points >= 500 and apply_rewards:
|
| 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
|
| 66 |
-
|
| 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 |
-
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")
|
| 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 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],
|
| 95 |
-
outputs=[rewards_message, final_bill_output, remaining_points_output])
|
| 96 |
-
|
| 97 |
-
return demo
|
| 98 |
-
|
| 99 |
-
# Run the Gradio interface
|
| 100 |
-
if __name__ == "__main__":
|
| 101 |
-
demo = create_interface()
|
| 102 |
-
demo.launch()
|
|
|
|
| 1 |
+
from flask import Flask, render_template, request, redirect, url_for, session
|
| 2 |
+
import constants
|
| 3 |
+
|
| 4 |
+
app = Flask(__name__)
|
| 5 |
+
app.secret_key = 'your_secret_key_here'
|
| 6 |
+
|
| 7 |
+
# Route for the login page
|
| 8 |
+
@app.route('/')
|
| 9 |
+
def login():
|
| 10 |
+
return render_template('login.html', style=constants.LOGIN_STYLE)
|
| 11 |
+
|
| 12 |
+
# Handle login logic
|
| 13 |
+
@app.route('/login', methods=['POST'])
|
| 14 |
+
def handle_login():
|
| 15 |
+
email = request.form.get('email')
|
| 16 |
+
password = request.form.get('password')
|
| 17 |
+
|
| 18 |
+
# Authenticate user (this part will be based on Salesforce or any authentication method)
|
| 19 |
+
if email == "user@example.com" and password == "password123": # Example check
|
| 20 |
+
session['user'] = email
|
| 21 |
+
return redirect(url_for('next_phase')) # Move to the next phase after successful login
|
| 22 |
+
else:
|
| 23 |
+
return render_template('login.html', style=constants.LOGIN_STYLE, error="Invalid credentials!")
|
| 24 |
+
|
| 25 |
+
# Route for the next phase (e.g., entering details)
|
| 26 |
+
@app.route('/next_phase', methods=['GET', 'POST'])
|
| 27 |
+
def next_phase():
|
| 28 |
+
if 'user' not in session:
|
| 29 |
+
return redirect(url_for('login'))
|
| 30 |
+
|
| 31 |
+
if request.method == 'POST':
|
| 32 |
+
# Save details (can be integrated with Salesforce or any DB)
|
| 33 |
+
# Redirect to reward points or next page
|
| 34 |
+
return redirect(url_for('reward_points'))
|
| 35 |
+
|
| 36 |
+
return render_template('next_phase.html', style=constants.PHASE_STYLE)
|
| 37 |
+
|
| 38 |
+
# Route for the reward points page
|
| 39 |
+
@app.route('/reward_points')
|
| 40 |
+
def reward_points():
|
| 41 |
+
if 'user' not in session:
|
| 42 |
+
return redirect(url_for('login'))
|
| 43 |
+
|
| 44 |
+
return render_template('reward_points.html', style=constants.REWARD_STYLE)
|
| 45 |
+
|
| 46 |
+
if __name__ == '__main__':
|
| 47 |
+
app.run(debug=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|