Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -49,13 +49,16 @@ except Exception as e:
|
|
49 |
def index():
|
50 |
return render_template("index.html")
|
51 |
|
52 |
-
@app.route("/dashboard")
|
53 |
-
def dashboard():
|
54 |
-
return render_template("dashboard.html")
|
55 |
-
|
56 |
@app.route("/menu")
|
57 |
def menu():
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
@app.route("/cart")
|
61 |
def cart():
|
@@ -94,51 +97,5 @@ def submit():
|
|
94 |
except Exception as e:
|
95 |
return jsonify({'error': str(e)}), 500
|
96 |
|
97 |
-
@app.route("/login", methods=["POST"])
|
98 |
-
def login():
|
99 |
-
data = request.json
|
100 |
-
name = data.get('name')
|
101 |
-
email = data.get('email')
|
102 |
-
phone_number = data.get('phone_number')
|
103 |
-
|
104 |
-
if not name or not email or not phone_number:
|
105 |
-
return jsonify({'error': 'Missing required fields'}), 400
|
106 |
-
|
107 |
-
try:
|
108 |
-
customer_login = sf.Customer_Login__c.create({
|
109 |
-
'Name': name,
|
110 |
-
'Email__c': email,
|
111 |
-
'Phone_Number__c': phone_number
|
112 |
-
})
|
113 |
-
return jsonify({'success': True, 'id': customer_login['id']}), 200
|
114 |
-
except Exception as e:
|
115 |
-
return jsonify({'error': f'Failed to create record in Salesforce: {str(e)}'}), 500
|
116 |
-
|
117 |
-
@app.route("/transcribe", methods=["POST"])
|
118 |
-
def transcribe():
|
119 |
-
if "audio" not in request.files:
|
120 |
-
return jsonify({"error": "No audio file provided"}), 400
|
121 |
-
|
122 |
-
audio_file = request.files["audio"]
|
123 |
-
input_audio_path = os.path.join("static", "temp_input.wav")
|
124 |
-
output_audio_path = os.path.join("static", "temp.wav")
|
125 |
-
audio_file.save(input_audio_path)
|
126 |
-
|
127 |
-
try:
|
128 |
-
audio = AudioSegment.from_file(input_audio_path)
|
129 |
-
audio = audio.set_frame_rate(16000).set_channels(1)
|
130 |
-
audio.export(output_audio_path, format="wav")
|
131 |
-
|
132 |
-
nonsilent_parts = detect_nonsilent(audio, min_silence_len=500, silence_thresh=audio.dBFS-16)
|
133 |
-
if len(nonsilent_parts) == 0:
|
134 |
-
return jsonify({"error": "No speech detected. Please try again."}), 400
|
135 |
-
|
136 |
-
result = pipeline("automatic-speech-recognition", model="openai/whisper-small", device=0 if torch.cuda.is_available() else -1, config=config)
|
137 |
-
transcribed_text = result["text"].strip().capitalize()
|
138 |
-
|
139 |
-
return jsonify({"text": transcribed_text})
|
140 |
-
except Exception as e:
|
141 |
-
return jsonify({"error": f"Speech recognition error: {str(e)}"}), 500
|
142 |
-
|
143 |
if __name__ == "__main__":
|
144 |
serve(app, host="0.0.0.0", port=7860)
|
|
|
49 |
def index():
|
50 |
return render_template("index.html")
|
51 |
|
|
|
|
|
|
|
|
|
52 |
@app.route("/menu")
|
53 |
def menu():
|
54 |
+
menu_items = [
|
55 |
+
{"id": 1, "name": "Chicken Biryani", "price": 250},
|
56 |
+
{"id": 2, "name": "Mutton Biryani", "price": 350},
|
57 |
+
{"id": 3, "name": "Veg Biryani", "price": 200},
|
58 |
+
{"id": 4, "name": "Paneer Butter Masala", "price": 180},
|
59 |
+
{"id": 5, "name": "Butter Naan", "price": 50}
|
60 |
+
]
|
61 |
+
return render_template("menu_page.html", menu_items=menu_items)
|
62 |
|
63 |
@app.route("/cart")
|
64 |
def cart():
|
|
|
97 |
except Exception as e:
|
98 |
return jsonify({'error': str(e)}), 500
|
99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
if __name__ == "__main__":
|
101 |
serve(app, host="0.0.0.0", port=7860)
|