SkillForge45 commited on
Commit
23e05b4
verified
1 Parent(s): 2f81cdc

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, request, jsonify
2
+ from hybrid_chatbot import HybridChatBot
3
+ import threading
4
+
5
+ app = Flask(__name__)
6
+
7
+ # Initialize chatbot
8
+ bot = HybridChatBot()
9
+
10
+ @app.route('/')
11
+ def home():
12
+ return render_template('index.html')
13
+
14
+ @app.route('/chat', methods=['POST'])
15
+ def chat():
16
+ user_input = request.json.get('message')
17
+ response = bot.get_response(user_input)
18
+ return jsonify({'response': response})
19
+
20
+ @app.route('/teach', methods=['POST'])
21
+ def teach():
22
+ question = request.json.get('question')
23
+ answer = request.json.get('answer')
24
+ bot.add_qa_pair(question, answer)
25
+ return jsonify({'success': True})
26
+
27
+ @app.route('/voice', methods=['POST'])
28
+ def voice():
29
+ # This would need additional frontend implementation for voice recording
30
+ user_input = bot.speech_to_text()
31
+ if user_input:
32
+ response = bot.get_response(user_input)
33
+ return jsonify({'response': response})
34
+ return jsonify({'response': "Sorry, I didn't catch that."})
35
+
36
+ if __name__ == '__main__':
37
+ app.run(debug=True)