DSatishchandra commited on
Commit
cd94e4f
·
verified ·
1 Parent(s): 8994919

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -1
app.py CHANGED
@@ -1,5 +1,5 @@
1
  import torch
2
- from flask import Flask, render_template, request, jsonify
3
  import json
4
  import os
5
  from transformers import pipeline
@@ -82,6 +82,12 @@ try:
82
  except Exception as e:
83
  print(f"Failed to connect to Salesforce: {str(e)}")
84
 
 
 
 
 
 
 
85
  # Function to create Salesforce record
86
  # API endpoint to receive data from voice bot
87
  @app.route('/login', methods=['POST'])
@@ -104,6 +110,8 @@ def login():
104
  'Phone_Number__c': phone_number
105
  })
106
  return jsonify({'success': True, 'id': customer_login['id']}), 200
 
 
107
  except Exception as e:
108
  return jsonify({'error': f'Failed to create record in Salesforce: {str(e)}'}), 500
109
 
@@ -138,6 +146,56 @@ def submit():
138
  def index():
139
  return render_template("index.html")
140
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  @app.route("/transcribe", methods=["POST"])
142
  def transcribe():
143
  if "audio" not in request.files:
 
1
  import torch
2
+ from flask import Flask, render_template, request, jsonify, redirect
3
  import json
4
  import os
5
  from transformers import pipeline
 
82
  except Exception as e:
83
  print(f"Failed to connect to Salesforce: {str(e)}")
84
 
85
+ # Function to fetch menu items from Salesforce
86
+ def get_menu_items():
87
+ query = "SELECT Name, Price__c, Ingredients__c, Category__c FROM Menu_Item__c"
88
+ result = sf.query(query)
89
+ return result['records']
90
+
91
  # Function to create Salesforce record
92
  # API endpoint to receive data from voice bot
93
  @app.route('/login', methods=['POST'])
 
110
  'Phone_Number__c': phone_number
111
  })
112
  return jsonify({'success': True, 'id': customer_login['id']}), 200
113
+ return redirect("/menu") # Redirect to the menu page after successful login
114
+ return render_template("login.html") # Render the login page for GET requests
115
  except Exception as e:
116
  return jsonify({'error': f'Failed to create record in Salesforce: {str(e)}'}), 500
117
 
 
146
  def index():
147
  return render_template("index.html")
148
 
149
+ # Route for the menu page
150
+ @app.route("/menu", methods=["GET"])
151
+ def menu_page():
152
+ menu_items = get_menu_items() # Fetch menu items from Salesforce
153
+ menu_data = []
154
+ for item in menu_items:
155
+ menu_data.append({
156
+ "name": item['Name'],
157
+ "price": item['Price__c'],
158
+ "ingredients": item['Ingredients__c'],
159
+ "category": item['Category__c'],
160
+ })
161
+
162
+ # Render the menu page template and pass the menu data to it
163
+ return render_template("menu_page.html", menu_items=menu_data)
164
+
165
+ # Route for handling order (you'll save the order to Salesforce here)
166
+ @app.route("/order", methods=["POST"])
167
+ def place_order():
168
+ # Getting the item name from the POST request (you can customize this to get more data)
169
+ item_name = request.json.get('item_name')
170
+ quantity = request.json.get('quantity')
171
+
172
+ # Logic to save the order details to Salesforce
173
+ order_data = {
174
+ "Item__c": item_name, # Assuming 'Item__c' is the field in your Order object
175
+ "Quantity__c": quantity, # Assuming 'Quantity__c' is a field for the quantity
176
+ # Add any other fields you need to capture, like customer, price, etc.
177
+ }
178
+
179
+ # Create the order record in Salesforce
180
+ sf.Order__c.create(order_data)
181
+
182
+ # Return a success response
183
+ return jsonify({"success": True, "message": f"Order for {item_name} placed successfully."})
184
+
185
+ # Route to handle the cart (this can be expanded later)
186
+ @app.route("/cart", methods=["GET"])
187
+ def cart():
188
+ # Logic to fetch cart items (this could be from a session or database)
189
+ cart_items = [] # Placeholder for cart items
190
+ return render_template("cart_page.html", cart_items=cart_items)
191
+
192
+ # Route for the order summary page (this can be expanded later)
193
+ @app.route("/order-summary", methods=["GET"])
194
+ def order_summary():
195
+ # Logic to fetch order summary (this could be from a session or database)
196
+ order_details = [] # Placeholder for order details
197
+ return render_template("order_summary.html", order_details=order_details)
198
+
199
  @app.route("/transcribe", methods=["POST"])
200
  def transcribe():
201
  if "audio" not in request.files: