File size: 1,047 Bytes
23e05b4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from flask import Flask, render_template, request, jsonify
from hybrid_chatbot import HybridChatBot
import threading

app = Flask(__name__)

# Initialize chatbot
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():
    # This would need additional frontend implementation for voice recording
    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)