File size: 4,285 Bytes
22bea9a
cd94e4f
95585ab
ee62e21
 
2fab7d3
 
 
ee62e21
95585ab
22bea9a
ee62e21
95585ab
ca0b532
22bea9a
ee62e21
 
 
 
 
 
 
 
 
 
 
 
 
e21d37e
ee62e21
e21d37e
ee62e21
 
e21d37e
ee62e21
e21d37e
 
 
 
 
ee62e21
e21d37e
 
ee62e21
 
e21d37e
ee62e21
e21d37e
ee62e21
 
 
 
 
 
 
 
 
 
e21d37e
ee62e21
c9ecf28
696d0f0
 
 
ee62e21
e21d37e
00af749
ca0b532
00af749
ee62e21
66083bc
 
ca0b532
5127047
66083bc
 
 
5127047
66083bc
 
2fab7d3
ee62e21
 
 
 
 
ca0b532
 
2fab7d3
5127047
1a545f7
ee62e21
cd94e4f
 
ee62e21
 
 
 
 
 
 
cd94e4f
ee62e21
cd94e4f
 
ca0b532
cd94e4f
ee62e21
cd94e4f
 
ca0b532
5127047
ee62e21
ca0b532
 
 
5127047
ee62e21
2fab7d3
8eee015
1
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import torch
from flask import Flask, render_template, request, jsonify, redirect
from simple_salesforce import Salesforce
from transformers import AutoConfig
from waitress import serve

app = Flask(__name__)

# Initialize the device for processing
device = "cuda" if torch.cuda.is_available() else "cpu"

# Initialize the Whisper model configuration
config = AutoConfig.from_pretrained("openai/whisper-small")
config.update({"timeout": 60})

# Connect to Salesforce
def connect_to_salesforce():
    try:
        # Salesforce login credentials
        sf = Salesforce(username='[email protected]', password='Sati@1020', security_token='sSSjyhInIsUohKpG8sHzty2q')
        print("Connected to Salesforce!")
        return sf
    except Exception as e:
        print(f"Failed to connect to Salesforce: {str(e)}")
        return None

# Initialize Salesforce connection
sf = connect_to_salesforce()

# Function to create a record in Salesforce (Customer Login)
def create_salesforce_record(sf, name, email, phone_number):
    if not sf:
        raise Exception("Salesforce connection is not established.")
    try:
        # Creating the Customer_Login__c record in Salesforce
        customer_login = sf.Customer_Login__c.create({
            'Name': name,
            'Email__c': email,
            'Phone_Number__c': phone_number
        })
        print(f"Customer record created with ID: {customer_login['id']}")
        return customer_login
    except Exception as e:
        print(f"Failed to create record in Salesforce: {str(e)}")
        raise Exception(f"Failed to create record in Salesforce: {str(e)}")

# Function to fetch menu items from Salesforce
def get_menu_items(sf):
    if not sf:
        raise Exception("Salesforce connection is not established.")
    try:
        # Querying Salesforce for menu items
        query = "SELECT Name, Price__c, Ingredients__c, Category__c FROM Menu_Item__c"
        result = sf.query(query)
        return result['records']
    except Exception as e:
        print(f"Failed to fetch menu items from Salesforce: {str(e)}")
        raise Exception(f"Failed to fetch menu items from Salesforce: {str(e)}")

# Route to the index page
@app.route("/")
def index():
    return render_template("index.html")

# Route to dashboard
@app.route("/dashboard", methods=["GET"])
def dashboard():
    return render_template("dashboard.html")

# Route for login (registration) - creates a new customer record in Salesforce
@app.route('/login', methods=['POST'])
def login():
    data = request.json
    name = data.get('name')
    email = data.get('email')
    phone_number = data.get('phone_number')

    if not name or not email or not phone_number:
        return jsonify({'error': 'Missing required fields'}), 400

    try:
        # Check if Salesforce connection is valid
        if not sf:
            return jsonify({'error': 'Salesforce connection failed, try again later.'}), 500
        
        # Create the customer record in Salesforce
        create_salesforce_record(sf, name, email, phone_number)
        return redirect("/menu")
    except Exception as e:
        return jsonify({'error': f'Failed to create record in Salesforce: {str(e)}'}), 500

# Route to the menu page - fetches menu items from Salesforce
@app.route("/menu", methods=["GET"])
def menu_page():
    try:
        # Fetch the menu items from Salesforce
        menu_items = get_menu_items(sf)
        menu_data = [{"name": item['Name'], "price": item['Price__c'], "ingredients": item['Ingredients__c'], "category": item['Category__c']} for item in menu_items]
        return render_template("menu_page.html", menu_items=menu_data)
    except Exception as e:
        return jsonify({'error': f'Failed to fetch menu items: {str(e)}'}), 500

# Route to the cart page
@app.route("/cart", methods=["GET"])
def cart():
    return render_template("cart_page.html")

# Route for the order summary page
@app.route("/order-summary", methods=["GET"])
def order_summary():
    return render_template("order_summary.html")

# Route for final order page
@app.route("/final_order", methods=["GET"])
def final_order():
    return render_template("final_order.html")

# Starting the app with Waitress server
if __name__ == "__main__":
    serve(app, host="0.0.0.0", port=7860)