diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..53550da0f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/__pycache__ +/venv \ No newline at end of file diff --git a/app.py b/app.py index e69de29bb..b6fccf1b0 100644 --- a/app.py +++ b/app.py @@ -0,0 +1,22 @@ +from flask import Flask, render_template, request, jsonify +from chat import get_response + +app = Flask(__name__) + + +@app.get("/") +def index_get(): + return render_template("base.html") + + +@app.post("/predict") +def predict(): + text = request.get_json().get("message") + # TODO: check if the text is valid + response = get_response(text) + message = {"answer": response} + return jsonify(message) + + +if __name__ == "__main__": + app.run(debug=True) diff --git a/chat.py b/chat.py index 1abbbee6f..b6b213734 100644 --- a/chat.py +++ b/chat.py @@ -25,7 +25,8 @@ model.load_state_dict(model_state) model.eval() -bot_name = "Sam" +bot_name = "SDF" + def get_response(msg): sentence = tokenize(msg) @@ -44,18 +45,16 @@ def get_response(msg): for intent in intents['intents']: if tag == intent["tag"]: return random.choice(intent['responses']) - + return "I do not understand..." if __name__ == "__main__": print("Let's chat! (type 'quit' to exit)") while True: - # sentence = "do you use credit cards?" sentence = input("You: ") if sentence == "quit": break resp = get_response(sentence) print(resp) - diff --git a/data.pth b/data.pth new file mode 100644 index 000000000..b6b09a80a Binary files /dev/null and b/data.pth differ diff --git a/intents.bak b/intents.bak new file mode 100644 index 000000000..18e0891b3 --- /dev/null +++ b/intents.bak @@ -0,0 +1,84 @@ +{ + "intents": [ + { + "tag": "greeting", + "patterns": [ + "Hi", + "Hey", + "How are you", + "Is anyone there?", + "Hello", + "Good day" + ], + "responses": [ + "Hey :-)", + "Hello, thanks for visiting", + "Hi there, what can I do for you?", + "Hi there, how can I help?" + ] + }, + { + "tag": "goodbye", + "patterns": ["Bye", "See you later", "Goodbye"], + "responses": [ + "See you later, thanks for visiting", + "Have a nice day", + "Bye! Come back again soon." + ] + }, + { + "tag": "thanks", + "patterns": ["Thanks", "Thank you", "That's helpful", "Thank's a lot!"], + "responses": ["Happy to help!", "Any time!", "My pleasure"] + }, + { + "tag": "items", + "patterns": [ + "Which items do you have?", + "What kinds of items are there?", + "What do you sell?" + ], + "responses": [ + "We sell coffee and tea", + "We have coffee and tea" + ] + }, + { + "tag": "payments", + "patterns": [ + "Do you take credit cards?", + "Do you accept Mastercard?", + "Can I pay with Paypal?", + "Are you cash only?" + ], + "responses": [ + "We accept VISA, Mastercard and Paypal", + "We accept most major credit cards, and Paypal" + ] + }, + { + "tag": "delivery", + "patterns": [ + "How long does delivery take?", + "How long does shipping take?", + "When do I get my delivery?" + ], + "responses": [ + "Delivery takes 2-4 days", + "Shipping takes 2-4 days" + ] + }, + { + "tag": "funny", + "patterns": [ + "Tell me a joke!", + "Tell me something funny!", + "Do you know a joke?" + ], + "responses": [ + "Why did the hipster burn his mouth? He drank the coffee before it was cool.", + "What did the buffalo say when his son left for college? Bison." + ] + } + ] +} diff --git a/intents.json b/intents.json index 18e0891b3..d9f1d7239 100644 --- a/intents.json +++ b/intents.json @@ -1,84 +1,147 @@ { - "intents": [ - { - "tag": "greeting", - "patterns": [ - "Hi", - "Hey", - "How are you", - "Is anyone there?", - "Hello", - "Good day" - ], - "responses": [ - "Hey :-)", - "Hello, thanks for visiting", - "Hi there, what can I do for you?", - "Hi there, how can I help?" - ] - }, - { - "tag": "goodbye", - "patterns": ["Bye", "See you later", "Goodbye"], - "responses": [ - "See you later, thanks for visiting", - "Have a nice day", - "Bye! Come back again soon." - ] - }, - { - "tag": "thanks", - "patterns": ["Thanks", "Thank you", "That's helpful", "Thank's a lot!"], - "responses": ["Happy to help!", "Any time!", "My pleasure"] - }, - { - "tag": "items", - "patterns": [ - "Which items do you have?", - "What kinds of items are there?", - "What do you sell?" - ], - "responses": [ - "We sell coffee and tea", - "We have coffee and tea" - ] - }, - { - "tag": "payments", - "patterns": [ - "Do you take credit cards?", - "Do you accept Mastercard?", - "Can I pay with Paypal?", - "Are you cash only?" - ], - "responses": [ - "We accept VISA, Mastercard and Paypal", - "We accept most major credit cards, and Paypal" - ] - }, - { - "tag": "delivery", - "patterns": [ - "How long does delivery take?", - "How long does shipping take?", - "When do I get my delivery?" - ], - "responses": [ - "Delivery takes 2-4 days", - "Shipping takes 2-4 days" - ] - }, - { - "tag": "funny", - "patterns": [ - "Tell me a joke!", - "Tell me something funny!", - "Do you know a joke?" - ], - "responses": [ - "Why did the hipster burn his mouth? He drank the coffee before it was cool.", - "What did the buffalo say when his son left for college? Bison." - ] - } - ] -} + "intents": [ + { + "tag": "greetings", + "patterns": [ + "Hi", + "Hey", + "How are you", + "Is anyone there?", + "Hello", + "Good day", + "Hi there" + ], + "responses": [ + "Hello thanks for checking in", + "Hi there, how can i help you", + "Hi there, what can I do for you?", + "Hi there, how can I help?" + ] + }, + { + "tag": "goodbye", + "patterns": [ + "bye", + "good bye", + "see you later" + ], + "responses": [ + "have a nice time, welcome back again", + "bye bye" + ] + }, + { + "tag": "thanks", + "patterns": [ + "Thanks", + "okay", + "Thank you", + "thankyou", + "That's helpful", + "Awesome, thanks", + "Thanks for helping me", + "wow", + "great" + ], + "responses": [ + "Happy to help!", + "Any time!", + "you're welcome", + "My pleasure" + ] + }, + { + "tag": "noanswer", + "patterns": [ + "" + ], + "responses": [ + "Sorry, I didn't understand you", + "Please give me more info", + "Not sure I understand that" + ] + }, + { + "tag": "name1", + "patterns": [ + "what's your name?", + "who are you?" + ], + "responses": [ + "I'm just an SDF virtual agent. I only exist in the world of DoFPD", + "I'm a SDF virtual chat agent" + ] + }, + { + "tag": "name", + "patterns": [ + "my name is ", + "I'm ", + "I am" + ], + "responses": [ + "Oooh great to meet you ! How may I assist you ", + "Oh, I'll keep that in mind" + ] + }, + { + "tag": "charge", + "patterns": [ + "Whether charge lower than the SDF charge be ceded?", + "what is the charge of SDF, lower than the SDF charge be ceded?", + "May I know the Charge", + "may i know the charge" + ], + "responses": [ + "Oh Yes, it can be ceded", + "It is ceded", + "it can be ceded" + ] + }, + { + "tag": "nodal", + "patterns": [ + "which nodal agency for cooperative factories?", + "Who will be the nodal agency for processing NOC request?", + "can you help me, which nodal agency for co-operative sugar factories for processing NOC requests?", + "who will process NOC request for co-operative sugar factories?" + ], + "responses": [ + "IFCI for private sugar factories and NCDC for co-operative sugar factories." + ] + }, + { + "tag": "private", + "patterns": [ + "Which is the nodal agency for private sugar factories for processing NOC requests?", + "private nodal agency", + "nodal agency for private sugar factories", + "Please tell me the nodal agency for private factories", + "Will you help me as a prive sugar factory ownere, which agency will facilitate in this?", + "private agency", + "private organization", + "private organisation" + ], + "responses": [ + "Yes, here is the link https://www.ifciltd.com/", + "yes IFCL", + "Hey! you can visit https://www.ifciltd.com/", + "I am sure it's Industrial Finance Corporation of India (IFCI)" + ] + }, + { + "tag": "loan application ", + "patterns": [ + "SDF Loan", + "sdf loan", + "loan link", + "loan form" + ], + "responses": [ + "https://sdfportal.in/Login", + "https://dfpd.gov.in/SDF-Main.htm" + ] + + } + ] +} \ No newline at end of file diff --git a/standalone-frontend/app.js b/standalone-frontend/app.js deleted file mode 100644 index 6bdf287d1..000000000 --- a/standalone-frontend/app.js +++ /dev/null @@ -1,91 +0,0 @@ -class Chatbox { - constructor() { - this.args = { - openButton: document.querySelector('.chatbox__button'), - chatBox: document.querySelector('.chatbox__support'), - sendButton: document.querySelector('.send__button') - } - - this.state = false; - this.messages = []; - } - - display() { - const {openButton, chatBox, sendButton} = this.args; - - openButton.addEventListener('click', () => this.toggleState(chatBox)) - - sendButton.addEventListener('click', () => this.onSendButton(chatBox)) - - const node = chatBox.querySelector('input'); - node.addEventListener("keyup", ({key}) => { - if (key === "Enter") { - this.onSendButton(chatBox) - } - }) - } - - toggleState(chatbox) { - this.state = !this.state; - - // show or hides the box - if(this.state) { - chatbox.classList.add('chatbox--active') - } else { - chatbox.classList.remove('chatbox--active') - } - } - - onSendButton(chatbox) { - var textField = chatbox.querySelector('input'); - let text1 = textField.value - if (text1 === "") { - return; - } - - let msg1 = { name: "User", message: text1 } - this.messages.push(msg1); - - fetch('http://127.0.0.1:5000/predict', { - method: 'POST', - body: JSON.stringify({ message: text1 }), - mode: 'cors', - headers: { - 'Content-Type': 'application/json' - }, - }) - .then(r => r.json()) - .then(r => { - let msg2 = { name: "Sam", message: r.answer }; - this.messages.push(msg2); - this.updateChatText(chatbox) - textField.value = '' - - }).catch((error) => { - console.error('Error:', error); - this.updateChatText(chatbox) - textField.value = '' - }); - } - - updateChatText(chatbox) { - var html = ''; - this.messages.slice().reverse().forEach(function(item, index) { - if (item.name === "Sam") - { - html += '
' - } - else - { - html += '' - } - }); - - const chatmessage = chatbox.querySelector('.chatbox__messages'); - chatmessage.innerHTML = html; - } -} - - -const chatbox = new Chatbox(); -chatbox.display(); \ No newline at end of file diff --git a/standalone-frontend/base.html b/standalone-frontend/base.html deleted file mode 100644 index c2c3b5c39..000000000 --- a/standalone-frontend/base.html +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - -Hi. My name is Sam. How can I help you?
-Hi. My name is Sam. How can I help you?
+Hi. I'm SDF Virtual Agent. How can I help you?