Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,38 @@
|
|
| 1 |
import os
|
| 2 |
-
from flask import Flask, render_template
|
| 3 |
|
| 4 |
app = Flask(__name__)
|
| 5 |
|
| 6 |
-
# Get Hugging Face assigned port
|
| 7 |
PORT = int(os.getenv("PORT", 7860))
|
| 8 |
|
| 9 |
@app.route('/')
|
| 10 |
-
def
|
| 11 |
"""Serve the main page with voice recognition."""
|
| 12 |
-
return render_template('
|
| 13 |
|
| 14 |
@app.route('/landing')
|
| 15 |
def landing():
|
| 16 |
"""Landing page that loads after wake-word detection."""
|
| 17 |
return render_template('landing.html')
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
if __name__ == '__main__':
|
| 20 |
app.run(host="0.0.0.0", port=PORT, debug=True)
|
|
|
|
| 1 |
import os
|
| 2 |
+
from flask import Flask, request, jsonify, render_template
|
| 3 |
|
| 4 |
app = Flask(__name__)
|
| 5 |
|
| 6 |
+
# Get Hugging Face assigned port or use local port 7860
|
| 7 |
PORT = int(os.getenv("PORT", 7860))
|
| 8 |
|
| 9 |
@app.route('/')
|
| 10 |
+
def index():
|
| 11 |
"""Serve the main page with voice recognition."""
|
| 12 |
+
return render_template('index.html')
|
| 13 |
|
| 14 |
@app.route('/landing')
|
| 15 |
def landing():
|
| 16 |
"""Landing page that loads after wake-word detection."""
|
| 17 |
return render_template('landing.html')
|
| 18 |
|
| 19 |
+
@app.route('/process_command', methods=['POST'])
|
| 20 |
+
def process_command():
|
| 21 |
+
"""Receives a voice command from the frontend, processes it, and returns a response."""
|
| 22 |
+
data = request.json
|
| 23 |
+
user_command = data.get("command", "").lower()
|
| 24 |
+
|
| 25 |
+
# Simple command responses
|
| 26 |
+
if "menu" in user_command:
|
| 27 |
+
response = "Here is the menu: Biryani, Kebab, Chicken Curry."
|
| 28 |
+
elif "order" in user_command:
|
| 29 |
+
response = "Please specify what you want to order."
|
| 30 |
+
elif "location" in user_command:
|
| 31 |
+
response = "Our restaurant is located at XYZ street, City."
|
| 32 |
+
else:
|
| 33 |
+
response = "Sorry, I didn't understand that command."
|
| 34 |
+
|
| 35 |
+
return jsonify({"response": response})
|
| 36 |
+
|
| 37 |
if __name__ == '__main__':
|
| 38 |
app.run(host="0.0.0.0", port=PORT, debug=True)
|