Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,16 +10,21 @@ from gtts import gTTS
|
|
| 10 |
import time
|
| 11 |
|
| 12 |
app = Flask(__name__)
|
| 13 |
-
logging.basicConfig(level=logging.
|
| 14 |
-
|
| 15 |
-
# Salesforce connection setup
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
# Global variables
|
| 25 |
cart = [] # To store items, quantities, and prices
|
|
@@ -32,23 +37,25 @@ awaiting_quantity = False
|
|
| 32 |
# Fetching menu items dynamically from Salesforce
|
| 33 |
def get_menu_items():
|
| 34 |
menu_items = {}
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
| 52 |
MENU = get_menu_items()
|
| 53 |
|
| 54 |
# HTML Template for Frontend (for register, login, and menu pages)
|
|
@@ -157,8 +164,10 @@ def register():
|
|
| 157 |
'Email__c': email,
|
| 158 |
'Phone_Number__c': phone
|
| 159 |
})
|
|
|
|
| 160 |
return redirect(url_for('menu')) # Redirect to menu after successful registration
|
| 161 |
except Exception as e:
|
|
|
|
| 162 |
return jsonify({'error': f'Failed to create record in Salesforce: {str(e)}'}), 500
|
| 163 |
|
| 164 |
return render_template_string(html_code)
|
|
@@ -178,8 +187,10 @@ def login():
|
|
| 178 |
customer_query = sf.query(f"SELECT Id, Name FROM Customer_Login__c WHERE Email__c = '{email}' AND Phone_Number__c = '{phone}'")
|
| 179 |
if customer_query['totalSize'] == 0:
|
| 180 |
return jsonify({"error": "Customer not found."}), 404
|
|
|
|
| 181 |
return redirect(url_for('menu')) # Redirect to menu after successful login
|
| 182 |
except Exception as e:
|
|
|
|
| 183 |
return jsonify({'error': f'Failed to query Salesforce: {str(e)}'}), 500
|
| 184 |
|
| 185 |
return render_template_string(html_code)
|
|
@@ -225,6 +236,7 @@ def process_audio():
|
|
| 225 |
except BadRequest as br:
|
| 226 |
return jsonify({"response": f"Bad Request: {str(br)}"}), 400
|
| 227 |
except Exception as e:
|
|
|
|
| 228 |
return jsonify({"response": f"An error occurred: {str(e)}"}), 500
|
| 229 |
finally:
|
| 230 |
os.unlink(temp_file.name)
|
|
@@ -301,4 +313,4 @@ def process_command(command):
|
|
| 301 |
return "Sorry, I didn't understand that. Please try again."
|
| 302 |
|
| 303 |
if __name__ == "__main__":
|
| 304 |
-
app.run(host="0.0.0.0", port=7860)
|
|
|
|
| 10 |
import time
|
| 11 |
|
| 12 |
app = Flask(__name__)
|
| 13 |
+
logging.basicConfig(level=logging.DEBUG)
|
| 14 |
+
|
| 15 |
+
# Salesforce connection setup
|
| 16 |
+
try:
|
| 17 |
+
sf = Salesforce(
|
| 18 |
+
username='diggavalli98@gmail.com',
|
| 19 |
+
password='Sati@1020',
|
| 20 |
+
security_token='sSSjyhInIsUohKpG8sHzty2q',
|
| 21 |
+
consumer_key='3MVG9WVXk15qiz1JbtW1tT9a7Wnkos2RuGamw6p1lC5uPescT5NB2nPygpo6rQ87K1T.zBEn.wR.A6JdgHnIU',
|
| 22 |
+
consumer_secret='A75C6B7801D5D20BED0E46631CF58C4F7FF28E4DAF442FE667553D29C35C0451'
|
| 23 |
+
)
|
| 24 |
+
logging.info("Successfully connected to Salesforce")
|
| 25 |
+
except Exception as e:
|
| 26 |
+
logging.error(f"Error connecting to Salesforce: {str(e)}")
|
| 27 |
+
sf = None
|
| 28 |
|
| 29 |
# Global variables
|
| 30 |
cart = [] # To store items, quantities, and prices
|
|
|
|
| 37 |
# Fetching menu items dynamically from Salesforce
|
| 38 |
def get_menu_items():
|
| 39 |
menu_items = {}
|
| 40 |
+
try:
|
| 41 |
+
query = "SELECT Name, Category__c, Price__c, Ingredients__c FROM Menu_Item__c"
|
| 42 |
+
results = sf.query_all(query)
|
| 43 |
+
|
| 44 |
+
# Organizing the menu items by category
|
| 45 |
+
for record in results['records']:
|
| 46 |
+
category = record['Category__c']
|
| 47 |
+
item_name = record['Name']
|
| 48 |
+
price = record['Price__c']
|
| 49 |
+
|
| 50 |
+
if category not in menu_items:
|
| 51 |
+
menu_items[category] = {}
|
| 52 |
+
menu_items[category][item_name] = price
|
| 53 |
+
|
| 54 |
+
return menu_items
|
| 55 |
+
except Exception as e:
|
| 56 |
+
logging.error(f"Error fetching menu items from Salesforce: {str(e)}")
|
| 57 |
+
return {}
|
| 58 |
+
|
| 59 |
MENU = get_menu_items()
|
| 60 |
|
| 61 |
# HTML Template for Frontend (for register, login, and menu pages)
|
|
|
|
| 164 |
'Email__c': email,
|
| 165 |
'Phone_Number__c': phone
|
| 166 |
})
|
| 167 |
+
logging.info("Customer registered successfully")
|
| 168 |
return redirect(url_for('menu')) # Redirect to menu after successful registration
|
| 169 |
except Exception as e:
|
| 170 |
+
logging.error(f"Error during registration: {str(e)}")
|
| 171 |
return jsonify({'error': f'Failed to create record in Salesforce: {str(e)}'}), 500
|
| 172 |
|
| 173 |
return render_template_string(html_code)
|
|
|
|
| 187 |
customer_query = sf.query(f"SELECT Id, Name FROM Customer_Login__c WHERE Email__c = '{email}' AND Phone_Number__c = '{phone}'")
|
| 188 |
if customer_query['totalSize'] == 0:
|
| 189 |
return jsonify({"error": "Customer not found."}), 404
|
| 190 |
+
logging.info("Customer logged in successfully")
|
| 191 |
return redirect(url_for('menu')) # Redirect to menu after successful login
|
| 192 |
except Exception as e:
|
| 193 |
+
logging.error(f"Error during login: {str(e)}")
|
| 194 |
return jsonify({'error': f'Failed to query Salesforce: {str(e)}'}), 500
|
| 195 |
|
| 196 |
return render_template_string(html_code)
|
|
|
|
| 236 |
except BadRequest as br:
|
| 237 |
return jsonify({"response": f"Bad Request: {str(br)}"}), 400
|
| 238 |
except Exception as e:
|
| 239 |
+
logging.error(f"Error processing audio: {str(e)}")
|
| 240 |
return jsonify({"response": f"An error occurred: {str(e)}"}), 500
|
| 241 |
finally:
|
| 242 |
os.unlink(temp_file.name)
|
|
|
|
| 313 |
return "Sorry, I didn't understand that. Please try again."
|
| 314 |
|
| 315 |
if __name__ == "__main__":
|
| 316 |
+
app.run(host="0.0.0.0", port=7860)
|