cmc
Browse files- app.py +22 -9
- requirements.txt +18 -5
app.py
CHANGED
|
@@ -1,23 +1,36 @@
|
|
| 1 |
-
#
|
|
|
|
|
|
|
|
|
|
| 2 |
from rag import ask_question
|
| 3 |
|
|
|
|
| 4 |
app = Flask(__name__)
|
| 5 |
|
| 6 |
@app.route("/webhook", methods=["POST"])
|
| 7 |
def webhook():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
try:
|
| 9 |
-
|
| 10 |
-
phone =
|
| 11 |
-
question =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
answer, docs = ask_question(phone, question)
|
| 13 |
return jsonify({"answer": answer, "docs": len(docs)})
|
|
|
|
| 14 |
except Exception as e:
|
| 15 |
print(f"❌ Webhook error: {e}")
|
| 16 |
-
return jsonify({"
|
| 17 |
|
| 18 |
-
@app.route("/healthcheck")
|
| 19 |
-
def healthcheck():
|
| 20 |
-
return jsonify({"status": "ok", "message": "Amina bot running!"})
|
| 21 |
|
|
|
|
| 22 |
if __name__ == "__main__":
|
| 23 |
-
|
|
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
import os
|
| 4 |
+
from flask import Flask, request, jsonify
|
| 5 |
from rag import ask_question
|
| 6 |
|
| 7 |
+
# ------------------------------------------------------------------ APP INIT
|
| 8 |
app = Flask(__name__)
|
| 9 |
|
| 10 |
@app.route("/webhook", methods=["POST"])
|
| 11 |
def webhook():
|
| 12 |
+
"""
|
| 13 |
+
Handles POST requests from WhatsApp or frontend chat clients.
|
| 14 |
+
Expects JSON payload:
|
| 15 |
+
{ "phone": "<number>", "question": "<message>" }
|
| 16 |
+
"""
|
| 17 |
try:
|
| 18 |
+
payload = request.get_json(force=True)
|
| 19 |
+
phone = payload.get("phone", "").strip()
|
| 20 |
+
question = payload.get("question", "").strip()
|
| 21 |
+
|
| 22 |
+
if not phone or not question:
|
| 23 |
+
return jsonify({"error": "Missing 'phone' or 'question' field"}), 400
|
| 24 |
+
|
| 25 |
answer, docs = ask_question(phone, question)
|
| 26 |
return jsonify({"answer": answer, "docs": len(docs)})
|
| 27 |
+
|
| 28 |
except Exception as e:
|
| 29 |
print(f"❌ Webhook error: {e}")
|
| 30 |
+
return jsonify({"error": str(e)}), 500
|
| 31 |
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
# ------------------------------------------------------------------ ENTRY POINT
|
| 34 |
if __name__ == "__main__":
|
| 35 |
+
port = int(os.getenv("PORT", 7860))
|
| 36 |
+
app.run(host="0.0.0.0", port=port)
|
requirements.txt
CHANGED
|
@@ -1,17 +1,30 @@
|
|
| 1 |
-
# ------- Web -------
|
| 2 |
flask==3.0.3
|
| 3 |
gunicorn==23.0.0
|
| 4 |
python-dotenv==1.0.1
|
|
|
|
| 5 |
|
| 6 |
-
# ------- LangChain -------
|
| 7 |
langchain==0.3.7
|
| 8 |
langchain-community==0.3.7
|
| 9 |
langchain-huggingface==0.1.2
|
|
|
|
| 10 |
|
| 11 |
-
# -------
|
| 12 |
sentence-transformers==3.0.1
|
| 13 |
faiss-cpu==1.9.0
|
| 14 |
datasets==3.0.1
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
# ------- Database -------
|
| 17 |
-
supabase==2.22.4
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ------- Web Framework -------
|
| 2 |
flask==3.0.3
|
| 3 |
gunicorn==23.0.0
|
| 4 |
python-dotenv==1.0.1
|
| 5 |
+
requests==2.32.3
|
| 6 |
|
| 7 |
+
# ------- LangChain Core -------
|
| 8 |
langchain==0.3.7
|
| 9 |
langchain-community==0.3.7
|
| 10 |
langchain-huggingface==0.1.2
|
| 11 |
+
langchain-core==0.3.15
|
| 12 |
|
| 13 |
+
# ------- Machine Learning / Embeddings -------
|
| 14 |
sentence-transformers==3.0.1
|
| 15 |
faiss-cpu==1.9.0
|
| 16 |
datasets==3.0.1
|
| 17 |
+
transformers==4.44.2
|
| 18 |
+
torch>=2.3.0
|
| 19 |
+
numpy>=1.26.4
|
| 20 |
|
| 21 |
+
# ------- Database / Backend -------
|
| 22 |
+
supabase==2.22.4
|
| 23 |
+
postgrest==0.16.6
|
| 24 |
+
storage3==0.7.7
|
| 25 |
+
gotrue==2.8.1
|
| 26 |
+
|
| 27 |
+
# ------- Utilities -------
|
| 28 |
+
tqdm==4.66.5
|
| 29 |
+
joblib==1.4.2
|
| 30 |
+
# ← latest stable; 2.6.0.post1 never existed
|