lokesh341 commited on
Commit
ce3f28a
·
verified ·
1 Parent(s): f7356a1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -14
app.py CHANGED
@@ -77,10 +77,6 @@ def is_silent_audio(audio_path):
77
  return len(nonsilent_parts) == 0 # If no speech detected
78
 
79
  # Routes and Views
80
- @app.route("/")
81
- def index():
82
- return render_template("index.html")
83
-
84
  @app.route("/dashboard", methods=["GET"])
85
  def dashboard():
86
  return render_template("dashboard.html") # Render the dashboard template
@@ -109,6 +105,18 @@ def menu_page():
109
  menu_data = [{"name": item['Name'], "price": item['Price__c'], "ingredients": item['Ingredients__c'], "category": item['Category__c']} for item in menu_items]
110
  return render_template("menu_page.html", menu_items=menu_data)
111
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  @app.route("/cart", methods=["GET"])
113
  def cart():
114
  # Retrieve cart items from session
@@ -128,17 +136,38 @@ def final_order():
128
  session.pop('cart_items', None)
129
  return render_template("final_order.html")
130
 
131
- @app.route("/add_to_cart", methods=["POST"])
132
- def add_to_cart():
133
- item_name = request.json.get('item_name')
134
- quantity = request.json.get('quantity')
135
-
136
- # Retrieve the current cart items from session or initialize an empty list
137
  cart_items = session.get('cart_items', [])
138
- cart_items.append({"name": item_name, "quantity": quantity, "price": 10}) # Assuming a fixed price for now
139
- session['cart_items'] = cart_items # Save the updated cart items in session
140
-
141
- return jsonify({"success": True, "message": f"Added {item_name} to cart."})
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
 
143
  @app.route("/transcribe", methods=["POST"])
144
  def transcribe():
@@ -211,6 +240,7 @@ def transcribe():
211
  print(f"Error in transcribing or processing: {str(e)}")
212
  return jsonify({"error": f"Speech recognition error: {str(e)}"}), 500
213
 
 
214
  # Start Production Server
215
  if __name__ == "__main__":
216
  serve(app, host="0.0.0.0", port=7860)
 
77
  return len(nonsilent_parts) == 0 # If no speech detected
78
 
79
  # Routes and Views
 
 
 
 
80
  @app.route("/dashboard", methods=["GET"])
81
  def dashboard():
82
  return render_template("dashboard.html") # Render the dashboard template
 
105
  menu_data = [{"name": item['Name'], "price": item['Price__c'], "ingredients": item['Ingredients__c'], "category": item['Category__c']} for item in menu_items]
106
  return render_template("menu_page.html", menu_items=menu_data)
107
 
108
+ @app.route("/add_to_cart", methods=["POST"])
109
+ def add_to_cart():
110
+ item_name = request.json.get('item_name')
111
+ quantity = request.json.get('quantity')
112
+
113
+ # Retrieve the current cart items from session or initialize an empty list
114
+ cart_items = session.get('cart_items', [])
115
+ cart_items.append({"name": item_name, "quantity": quantity, "price": 10}) # Assuming a fixed price for now
116
+ session['cart_items'] = cart_items # Save the updated cart items in session
117
+
118
+ return jsonify({"success": True, "message": f"Added {item_name} to cart."})
119
+
120
  @app.route("/cart", methods=["GET"])
121
  def cart():
122
  # Retrieve cart items from session
 
136
  session.pop('cart_items', None)
137
  return render_template("final_order.html")
138
 
139
+ @app.route("/place_order", methods=["POST"])
140
+ def place_order():
141
+ # Retrieve cart items from session
 
 
 
142
  cart_items = session.get('cart_items', [])
143
+ if not cart_items:
144
+ return jsonify({"error": "Cart is empty, please add items."}), 400
145
+
146
+ # Create an Order record in Salesforce
147
+ try:
148
+ order_data = {
149
+ 'Status': 'Draft',
150
+ 'AccountId': '0012F00000FhKzGQ', # Example Salesforce Account ID, replace with actual
151
+ 'OrderNumber': f"Order-{int(time.time())}" # Simple Order number based on time
152
+ }
153
+ order = sf.Order.create(order_data)
154
+ order_id = order['id']
155
+
156
+ # Add items to the OrderLineItem related to the created Order
157
+ for cart_item in cart_items:
158
+ order_line_item_data = {
159
+ 'OrderId': order_id,
160
+ 'Quantity': cart_item['quantity'],
161
+ 'UnitPrice': cart_item['price'],
162
+ 'Product2Id': 'a0A2F00000o6K7GQ' # Example Product ID, replace with actual Product2Id
163
+ }
164
+ sf.OrderLineItem.create(order_line_item_data)
165
+
166
+ # Clear the cart after placing the order
167
+ session.pop('cart_items', None)
168
+ return jsonify({"success": True, "message": "Order placed successfully!"})
169
+ except Exception as e:
170
+ return jsonify({"error": f"Failed to place order: {str(e)}"}), 500
171
 
172
  @app.route("/transcribe", methods=["POST"])
173
  def transcribe():
 
240
  print(f"Error in transcribing or processing: {str(e)}")
241
  return jsonify({"error": f"Speech recognition error: {str(e)}"}), 500
242
 
243
+
244
  # Start Production Server
245
  if __name__ == "__main__":
246
  serve(app, host="0.0.0.0", port=7860)