DSatishchandra commited on
Commit
bcde189
·
verified ·
1 Parent(s): fd2f5b6

Update templates/menu_page.html

Browse files
Files changed (1) hide show
  1. templates/menu_page.html +80 -102
templates/menu_page.html CHANGED
@@ -3,126 +3,104 @@
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Menu - Biryani Hub</title>
7
- <style>
8
- /* General Body Styling */
9
- body {
10
- font-family: Arial, sans-serif;
11
- background-color: #f8f8f8;
12
- margin: 0;
13
- padding: 0;
14
- }
15
-
16
- /* Container for the menu */
17
- .menu-container {
18
- max-width: 1200px;
19
- margin: 0 auto;
20
- padding: 20px;
21
- background-color: #fff;
22
- box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
23
- border-radius: 8px;
24
- margin-top: 50px;
25
- }
26
-
27
- h1 {
28
- text-align: center;
29
- font-size: 2.5rem;
30
- color: #333;
31
- margin-bottom: 30px;
32
- }
33
-
34
- .menu-item {
35
- border-bottom: 1px solid #eee;
36
- padding: 15px 0;
37
- display: flex;
38
- justify-content: space-between;
39
- align-items: center;
40
- }
41
-
42
- .order-btn {
43
- padding: 10px 20px;
44
- background-color: #4CAF50;
45
- color: white;
46
- border: none;
47
- border-radius: 5px;
48
- cursor: pointer;
49
- }
50
-
51
- .order-btn:hover {
52
- background-color: #45a049;
53
- }
54
-
55
- #listen-btn {
56
- padding: 10px 20px;
57
- background-color: #4CAF50;
58
- color: white;
59
- border: none;
60
- border-radius: 5px;
61
- cursor: pointer;
62
- font-size: 1.2rem;
63
- display: block;
64
- margin: 30px auto;
65
- }
66
-
67
- #listen-btn:hover {
68
- background-color: #45a049;
69
- }
70
- </style>
71
  </head>
72
  <body>
73
-
74
- <div class="menu-container">
75
  <h1>Welcome to the Menu</h1>
76
-
77
- {% for item in menu_items %}
78
- <div class="menu-item">
79
- <div class="details">
80
  <h3>{{ item.name }}</h3>
81
- <p><strong>Ingredients:</strong> {{ item.ingredients }}</p>
82
- <p><strong>Category:</strong> {{ item.category }}</p>
83
- <p class="price">Price: ${{ item.price }}</p>
 
84
  </div>
85
- <button class="order-btn">Order</button>
86
  </div>
87
- {% endfor %}
88
 
89
- <!-- Button for triggering voice recognition -->
90
- <button id="listen-btn">Say "Order" to order an item</button>
 
 
91
  </div>
92
 
93
  <script>
94
- const listenButton = document.getElementById("listen-btn");
95
- const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
 
96
 
97
- recognition.lang = "en-US";
98
- recognition.interimResults = false;
 
 
99
 
100
- function speak(text) {
101
- const msg = new SpeechSynthesisUtterance(text);
102
- window.speechSynthesis.speak(msg);
 
 
 
 
 
 
 
 
 
 
 
103
  }
104
 
105
- listenButton.addEventListener("click", () => {
106
- speak("Please say the item you want to order.");
107
- recognition.start();
 
108
  });
109
 
110
- recognition.onresult = (event) => {
111
- const command = event.results[0][0].transcript.toLowerCase();
112
- console.log("User said:", command);
 
 
 
 
113
 
114
- // Add logic to recognize specific items or trigger actions based on the command
115
- if (command.includes("order")) {
116
- // For example, navigate or process an order (customize as needed)
117
- speak("Your order has been placed.");
118
- }
119
- };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
 
121
- recognition.onerror = (event) => {
122
- console.error("Speech recognition error:", event.error);
123
- speak("Sorry, I couldn't understand that. Please try again.");
124
- };
 
 
 
 
 
 
125
  </script>
126
-
127
  </body>
128
  </html>
 
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Menu Page</title>
7
+ <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
8
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/annyang/2.6.1/annyang.min.js"></script> <!-- for voice commands -->
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  </head>
10
  <body>
11
+ <div class="container">
 
12
  <h1>Welcome to the Menu</h1>
13
+ <div id="menu-items">
14
+ {% for item in menu_items %}
15
+ <div class="menu-item">
 
16
  <h3>{{ item.name }}</h3>
17
+ <p>Price: ${{ item.price }}</p>
18
+ <p>Ingredients: {{ item.ingredients }}</p>
19
+ <p>Category: {{ item.category }}</p>
20
+ <button class="order-btn" data-item="{{ item.name }}">Order</button>
21
  </div>
22
+ {% endfor %}
23
  </div>
 
24
 
25
+ <div id="mic-container">
26
+ <button id="mic-btn">🎤</button>
27
+ <p id="mic-status">Press the mic button to start...</p>
28
+ </div>
29
  </div>
30
 
31
  <script>
32
+ let menuItems = [];
33
+ let selectedItem = "";
34
+ let quantity = 0;
35
 
36
+ // Fetch menu items from the backend
37
+ {% for item in menu_items %}
38
+ menuItems.push("{{ item.name }}");
39
+ {% endfor %}
40
 
41
+ // Setup voice interaction
42
+ if (annyang) {
43
+ // Add a voice command to handle menu items ordering
44
+ var commands = {};
45
+ menuItems.forEach(item => {
46
+ commands[item.toLowerCase()] = function() {
47
+ selectedItem = item;
48
+ document.getElementById("mic-status").innerText = "You chose " + item + ". Please say the quantity.";
49
+ };
50
+ });
51
+
52
+ // Start voice recognition
53
+ annyang.addCommands(commands);
54
+ annyang.start();
55
  }
56
 
57
+ // Handle mic button click to start voice recognition
58
+ document.getElementById("mic-btn").addEventListener("click", function() {
59
+ document.getElementById("mic-status").innerText = "Listening...";
60
+ annyang.start();
61
  });
62
 
63
+ // Handle order button click
64
+ document.querySelectorAll('.order-btn').forEach(button => {
65
+ button.addEventListener('click', function() {
66
+ selectedItem = button.getAttribute('data-item');
67
+ document.getElementById("mic-status").innerText = `You chose ${selectedItem}. Please say the quantity.`;
68
+ });
69
+ });
70
 
71
+ // Wait for quantity confirmation via voice and then submit
72
+ function placeOrder() {
73
+ let orderDetails = {
74
+ item: selectedItem,
75
+ quantity: quantity
76
+ };
77
+ fetch('/order', {
78
+ method: 'POST',
79
+ headers: {
80
+ 'Content-Type': 'application/json',
81
+ },
82
+ body: JSON.stringify(orderDetails),
83
+ })
84
+ .then(response => response.json())
85
+ .then(data => {
86
+ if (data.success) {
87
+ document.getElementById("mic-status").innerText = "Order placed successfully!";
88
+ } else {
89
+ document.getElementById("mic-status").innerText = "Error placing order.";
90
+ }
91
+ });
92
+ }
93
 
94
+ // Listen for quantity after food item selection
95
+ if (annyang) {
96
+ annyang.addCommands({
97
+ 'quantity *number': function(number) {
98
+ quantity = parseInt(number);
99
+ document.getElementById("mic-status").innerText = `You want ${quantity} of ${selectedItem}. Please confirm your order.`;
100
+ placeOrder();
101
+ }
102
+ });
103
+ }
104
  </script>
 
105
  </body>
106
  </html>