Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,11 +3,13 @@ import random
|
|
| 3 |
import pickle
|
| 4 |
import numpy as np
|
| 5 |
import re
|
|
|
|
| 6 |
import time # Import modul time untuk delay
|
| 7 |
from flask import Flask, request, jsonify
|
| 8 |
from sentence_transformers import SentenceTransformer
|
| 9 |
from sklearn.metrics.pairwise import cosine_similarity
|
| 10 |
|
|
|
|
| 11 |
class ImprovedBPJSChatbot:
|
| 12 |
def __init__(self):
|
| 13 |
self.load_models()
|
|
@@ -161,15 +163,21 @@ app = Flask(__name__)
|
|
| 161 |
def chat():
|
| 162 |
try:
|
| 163 |
msg = request.json.get("message", "").strip()
|
| 164 |
-
|
| 165 |
-
# Tambahkan delay 1 detik sebelum memproses pesan
|
| 166 |
time.sleep(1)
|
| 167 |
-
|
| 168 |
response = chatbot.generate_response(msg)
|
| 169 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
except Exception as e:
|
| 171 |
-
|
| 172 |
-
|
|
|
|
|
|
|
|
|
|
| 173 |
|
| 174 |
@app.route('/health', methods=['GET'])
|
| 175 |
def health():
|
|
|
|
| 3 |
import pickle
|
| 4 |
import numpy as np
|
| 5 |
import re
|
| 6 |
+
import datetime
|
| 7 |
import time # Import modul time untuk delay
|
| 8 |
from flask import Flask, request, jsonify
|
| 9 |
from sentence_transformers import SentenceTransformer
|
| 10 |
from sklearn.metrics.pairwise import cosine_similarity
|
| 11 |
|
| 12 |
+
|
| 13 |
class ImprovedBPJSChatbot:
|
| 14 |
def __init__(self):
|
| 15 |
self.load_models()
|
|
|
|
| 163 |
def chat():
|
| 164 |
try:
|
| 165 |
msg = request.json.get("message", "").strip()
|
|
|
|
|
|
|
| 166 |
time.sleep(1)
|
| 167 |
+
|
| 168 |
response = chatbot.generate_response(msg)
|
| 169 |
+
|
| 170 |
+
# Log untuk respons sukses
|
| 171 |
+
print(f"[{datetime.datetime.now()}] 200 OK - Pesan masuk: '{msg}' -> Balasan: '{response}'")
|
| 172 |
+
|
| 173 |
+
return jsonify({"reply": response}), 200
|
| 174 |
+
|
| 175 |
except Exception as e:
|
| 176 |
+
# Log untuk error
|
| 177 |
+
print(f"[{datetime.datetime.now()}] 500 ERROR - Pesan masuk: '{request.json}' -> Kesalahan: {e}")
|
| 178 |
+
|
| 179 |
+
return jsonify({"reply": "Maaf, terjadi kesalahan sistem. Silakan coba lagi."}), 500
|
| 180 |
+
|
| 181 |
|
| 182 |
@app.route('/health', methods=['GET'])
|
| 183 |
def health():
|