Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/__pycache__
/venv
22 changes: 22 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 3 additions & 4 deletions chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Binary file added data.pth
Binary file not shown.
84 changes: 84 additions & 0 deletions intents.bak
Original file line number Diff line number Diff line change
@@ -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."
]
}
]
}
229 changes: 146 additions & 83 deletions intents.json
Original file line number Diff line number Diff line change
@@ -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"
]

}
]
}
Loading