Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 41 additions & 40 deletions api/index.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,41 @@
from flask import request, jsonify
import sys
import os
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from modul import reply

AnswerList = []
AccuracyList = []
QuesionList = []

def welcome():
return jsonify({'message': 'Welcome to the API'}), 200

def chat():
try:
data = request.get_json()
message = data.get('message')

if not message:
return jsonify({"error": "No message provided"}), 400

return_message, status, dec_outputs, accuracy = reply.botReply(message)
AnswerList.append(return_message)
AccuracyList.append(float(accuracy))
QuesionList.append(message)

response = {
"isBot" : True,
"ITeung": return_message,
"status": status,
"accuracy": float(accuracy),
# 'dec_outputs': dec_outputs.tolist() if isinstance(dec_outputs, (list, np.ndarray)) else dec_outputs
}

return jsonify(response), 200

except FileNotFoundError as e:
return jsonify({"error": f"File not found: {e}"}), 500
except Exception as e:
return jsonify({"error": f"An error occurred: {e}"}), 500
from flask import request, jsonify
import sys
import os
from modul import reply

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

AnswerList = []
AccuracyList = []
QuesionList = []

def welcome():
return jsonify({'message': 'Welcome to the API'}), 200

def chat():
try:
data = request.get_json()
message = data.get('message')

if not message:
return jsonify({"error": "No message provided"}), 400

return_message, status, dec_outputs, accuracy = reply.botReply(message)
AnswerList.append(return_message)
AccuracyList.append(float(accuracy))
QuesionList.append(message)

response = {
"isBot" : True,
"ITeung": return_message,
"status": status,
"accuracy": float(accuracy),
# 'dec_outputs': dec_outputs.tolist() if isinstance(dec_outputs, (list, np.ndarray)) else dec_outputs
}

return jsonify(response), 200

except FileNotFoundError as e:
return jsonify({"error": f"File not found: {e}"}), 404
except Exception as e:
return jsonify({"error": f"An error occurred: {e}"}), 500