-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
42 lines (29 loc) · 1005 Bytes
/
Copy pathapp.py
File metadata and controls
42 lines (29 loc) · 1005 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""
app.py
Versi web dari FAQ Chatbot menggunakan Flask.
Cara pakai:
python app.py
Lalu buka http://127.0.0.1:5000 di browser.
"""
from flask import Flask, render_template, request, jsonify
from matcher import FAQMatcher
app = Flask(__name__)
matcher = FAQMatcher(data_path="faq_data.json", threshold=0.3)
FALLBACK_MESSAGE = (
"Maaf, saya belum menemukan jawaban yang cocok untuk pertanyaan itu. "
"Coba gunakan kata kunci lain, atau hubungi customer service kami."
)
@app.route("/")
def index():
return render_template("index.html")
@app.route("/api/ask", methods=["POST"])
def ask():
data = request.get_json(silent=True) or {}
user_message = data.get("message", "").strip()
if not user_message:
return jsonify({"reply": "Silakan tulis pertanyaan Anda."})
result = matcher.get_answer(user_message)
reply = result["answer"] if result else FALLBACK_MESSAGE
return jsonify({"reply": reply})
if __name__ == "__main__":
app.run(debug=True)