Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import torch
|
2 |
-
from flask import Flask, render_template, request, jsonify, redirect
|
3 |
import json
|
4 |
import os
|
5 |
from transformers import pipeline
|
@@ -13,6 +13,7 @@ from simple_salesforce import Salesforce
|
|
13 |
import requests
|
14 |
|
15 |
app = Flask(__name__)
|
|
|
16 |
|
17 |
# Use whisper-small for faster processing and better speed
|
18 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
@@ -81,7 +82,7 @@ def index():
|
|
81 |
|
82 |
@app.route("/dashboard", methods=["GET"])
|
83 |
def dashboard():
|
84 |
-
return render_template("dashboard.html")
|
85 |
|
86 |
@app.route('/login', methods=['POST'])
|
87 |
def login():
|
@@ -96,66 +97,48 @@ def login():
|
|
96 |
|
97 |
try:
|
98 |
customer_login = create_salesforce_record(sf, name, email, phone_number)
|
|
|
99 |
return redirect("/menu") # Redirect to the menu page after successful login
|
100 |
except Exception as e:
|
101 |
return jsonify({'error': f'Failed to create record in Salesforce: {str(e)}'}), 500
|
102 |
|
103 |
-
@app.route("/submit", methods=["POST"])
|
104 |
-
def submit():
|
105 |
-
data = request.json
|
106 |
-
name = data.get('name')
|
107 |
-
email = data.get('email')
|
108 |
-
phone = data.get('phone')
|
109 |
-
|
110 |
-
if not name or not email or not phone:
|
111 |
-
return jsonify({'error': 'Missing data'}), 400
|
112 |
-
|
113 |
-
try:
|
114 |
-
# Create Salesforce record
|
115 |
-
customer_login = sf.Customer_Login__c.create({
|
116 |
-
'Name': name,
|
117 |
-
'Email__c': email,
|
118 |
-
'Phone_Number__c': phone
|
119 |
-
})
|
120 |
-
|
121 |
-
if customer_login.get('id'):
|
122 |
-
print(f"Success: Customer record created with ID: {customer_login['id']}")
|
123 |
-
return jsonify({'success': True})
|
124 |
-
else:
|
125 |
-
print("Failed: No ID returned after creating the record.")
|
126 |
-
return jsonify({'error': 'Failed to create record'}), 500
|
127 |
-
|
128 |
-
except Exception as e:
|
129 |
-
print(f"Error: {str(e)}") # Print error message if an exception occurs
|
130 |
-
return jsonify({'error': str(e)}), 500
|
131 |
-
|
132 |
-
|
133 |
@app.route("/menu", methods=["GET"])
|
134 |
def menu_page():
|
135 |
menu_items = get_menu_items(sf) # Fetch menu items from Salesforce
|
136 |
menu_data = [{"name": item['Name'], "price": item['Price__c'], "ingredients": item['Ingredients__c'], "category": item['Category__c']} for item in menu_items]
|
137 |
return render_template("menu_page.html", menu_items=menu_data)
|
138 |
|
139 |
-
# Route for handling order
|
140 |
-
@app.route("/order", methods=["POST"])
|
141 |
-
def place_order():
|
142 |
-
item_name = request.json.get('item_name')
|
143 |
-
quantity = request.json.get('quantity')
|
144 |
-
order_data = {"Item__c": item_name, "Quantity__c": quantity}
|
145 |
-
sf.Order__c.create(order_data)
|
146 |
-
return jsonify({"success": True, "message": f"Order for {item_name} placed successfully."})
|
147 |
-
|
148 |
# Route to handle the cart
|
149 |
@app.route("/cart", methods=["GET"])
|
150 |
def cart():
|
151 |
-
|
|
|
152 |
return render_template("cart_page.html", cart_items=cart_items)
|
153 |
|
154 |
# Route for the order summary page
|
155 |
@app.route("/order-summary", methods=["GET"])
|
156 |
def order_summary():
|
157 |
-
|
158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
|
160 |
@app.route("/transcribe", methods=["POST"])
|
161 |
def transcribe():
|
|
|
1 |
import torch
|
2 |
+
from flask import Flask, render_template, request, jsonify, redirect, session
|
3 |
import json
|
4 |
import os
|
5 |
from transformers import pipeline
|
|
|
13 |
import requests
|
14 |
|
15 |
app = Flask(__name__)
|
16 |
+
app.secret_key = os.urandom(24) # For session handling
|
17 |
|
18 |
# Use whisper-small for faster processing and better speed
|
19 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
82 |
|
83 |
@app.route("/dashboard", methods=["GET"])
|
84 |
def dashboard():
|
85 |
+
return render_template("dashboard.html")
|
86 |
|
87 |
@app.route('/login', methods=['POST'])
|
88 |
def login():
|
|
|
97 |
|
98 |
try:
|
99 |
customer_login = create_salesforce_record(sf, name, email, phone_number)
|
100 |
+
session['customer_id'] = customer_login['id'] # Store customer ID in session
|
101 |
return redirect("/menu") # Redirect to the menu page after successful login
|
102 |
except Exception as e:
|
103 |
return jsonify({'error': f'Failed to create record in Salesforce: {str(e)}'}), 500
|
104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
@app.route("/menu", methods=["GET"])
|
106 |
def menu_page():
|
107 |
menu_items = get_menu_items(sf) # Fetch menu items from Salesforce
|
108 |
menu_data = [{"name": item['Name'], "price": item['Price__c'], "ingredients": item['Ingredients__c'], "category": item['Category__c']} for item in menu_items]
|
109 |
return render_template("menu_page.html", menu_items=menu_data)
|
110 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
# Route to handle the cart
|
112 |
@app.route("/cart", methods=["GET"])
|
113 |
def cart():
|
114 |
+
# For now, using session to store cart items
|
115 |
+
cart_items = session.get('cart_items', [])
|
116 |
return render_template("cart_page.html", cart_items=cart_items)
|
117 |
|
118 |
# Route for the order summary page
|
119 |
@app.route("/order-summary", methods=["GET"])
|
120 |
def order_summary():
|
121 |
+
# Get the order details from the session
|
122 |
+
order_details = session.get('cart_items', [])
|
123 |
+
total_price = sum(item['price'] * item['quantity'] for item in order_details)
|
124 |
+
return render_template("order_summary.html", order_details=order_details, total_price=total_price)
|
125 |
+
|
126 |
+
@app.route("/final_order", methods=["GET"])
|
127 |
+
def final_order():
|
128 |
+
return render_template("final_order.html")
|
129 |
+
|
130 |
+
# Route for handling order placement
|
131 |
+
@app.route("/order", methods=["POST"])
|
132 |
+
def place_order():
|
133 |
+
item_name = request.json.get('item_name')
|
134 |
+
quantity = request.json.get('quantity')
|
135 |
+
|
136 |
+
# Store the item in the session cart
|
137 |
+
cart_items = session.get('cart_items', [])
|
138 |
+
cart_items.append({"name": item_name, "quantity": quantity, "price": 10}) # Assuming a fixed price for simplicity
|
139 |
+
session['cart_items'] = cart_items # Save the updated cart to the session
|
140 |
+
|
141 |
+
return jsonify({"success": True, "message": f"Order for {item_name} placed successfully."})
|
142 |
|
143 |
@app.route("/transcribe", methods=["POST"])
|
144 |
def transcribe():
|