| from flask import Flask, render_template, request, jsonify |
| from hybrid_chatbot import HybridChatBot |
| import threading |
|
|
| app = Flask(__name__) |
|
|
| |
| bot = HybridChatBot() |
|
|
| @app.route('/') |
| def home(): |
| return render_template('index.html') |
|
|
| @app.route('/chat', methods=['POST']) |
| def chat(): |
| user_input = request.json.get('message') |
| response = bot.get_response(user_input) |
| return jsonify({'response': response}) |
|
|
| @app.route('/teach', methods=['POST']) |
| def teach(): |
| question = request.json.get('question') |
| answer = request.json.get('answer') |
| bot.add_qa_pair(question, answer) |
| return jsonify({'success': True}) |
|
|
| @app.route('/voice', methods=['POST']) |
| def voice(): |
| |
| user_input = bot.speech_to_text() |
| if user_input: |
| response = bot.get_response(user_input) |
| return jsonify({'response': response}) |
| return jsonify({'response': "Sorry, I didn't catch that."}) |
|
|
| if __name__ == '__main__': |
| app.run(debug=True) |