-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
44 lines (32 loc) · 1.09 KB
/
Copy pathapp.py
File metadata and controls
44 lines (32 loc) · 1.09 KB
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
38
39
40
41
42
43
44
__author__ = "Adnan Karol"
__version__ = "1.0.0"
__maintainer__ = "Adnan Karol"
__email__ = "adnanmushtaq5@gmail.com"
# Import Dependencies
from flask import Flask, request, jsonify, render_template
from RagBot import Chatbot, KnowledgeBase
from flask_cors import CORS
app = Flask(__name__)
# Enable CORS for all routes
CORS(app)
# Initialize the knowledge base and chatbot
knowledge_base = KnowledgeBase(
model_name="sentence-transformers/all-MiniLM-L6-v2",
file_path="Internal_Data.txt",
)
chatbot = Chatbot(model_name="llama3", knowledge_base=knowledge_base)
# Serving the index.html when accessing the root URL
@app.route("/")
def index():
return render_template("index.html")
# Route to handle chat requests
@app.route("/chat/", methods=["POST"])
def chat():
data = request.get_json()
user_input = data.get("question")
context = data.get("context", "")
# Generate the response based on the user input
response = chatbot.handle_input(user_input)
return jsonify({"answer": response})
if __name__ == "__main__":
app.run(debug=True, host="127.0.0.1", port=8000)