Update app.py
Browse files
app.py
CHANGED
@@ -189,6 +189,27 @@ def chat():
|
|
189 |
logger.exception("Chat endpoint failed")
|
190 |
return jsonify({"error": str(e)}), 500
|
191 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
192 |
|
193 |
# -------------------- Serve Audio --------------------
|
194 |
@app.route("/static/audio/<filename>")
|
|
|
189 |
logger.exception("Chat endpoint failed")
|
190 |
return jsonify({"error": str(e)}), 500
|
191 |
|
192 |
+
# -------------------- Realtime Chat Route --------------------
|
193 |
+
@app.route("/realtime", methods=["POST"])
|
194 |
+
def chat():
|
195 |
+
try:
|
196 |
+
data = request.get_json(force=True)
|
197 |
+
prompt = str(data.get("prompt", "")).strip()
|
198 |
+
if not prompt:
|
199 |
+
logger.warning("Missing prompt in request")
|
200 |
+
return jsonify({"error": "Missing prompt"}), 400
|
201 |
+
|
202 |
+
logger.info(f"Received prompt: {prompt[:60]}...")
|
203 |
+
|
204 |
+
response = BASE_MODEL.chat(prompt=prompt, stream=False)
|
205 |
+
print(f"Response: {response}")
|
206 |
+
audio_url = generate_tts(response)
|
207 |
+
print(f"Audio URL: {audio_url}")
|
208 |
+
return jsonify(f"data: {json.dumps({'done': True, 'full_response': response, 'audio_url': audio_url})}\n\n")
|
209 |
+
|
210 |
+
except Exception as e:
|
211 |
+
logger.exception("Chat endpoint failed")
|
212 |
+
return jsonify({"error": str(e)}), 500
|
213 |
|
214 |
# -------------------- Serve Audio --------------------
|
215 |
@app.route("/static/audio/<filename>")
|