Commit a51052bb authored by Mihiranga G.L.V - IT18500790's avatar Mihiranga G.L.V - IT18500790

Merge branch 'IT18085822' into 'master'

It18085822

See merge request !16
parents 6f31ecae 4810a166
from flask import Flask
app = Flask(__name__)
import random
import json
import torch
from model import NeuralNet
from nltk_utils import bag_of_words, tokenize
@app.route('/<string:name>/')
def hello(name):
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
with open('intents.json', 'r') as json_data:
intents = json.load(json_data)
FILE = "data.pth"
data = torch.load(FILE)
input_size = data["input_size"]
hidden_size = data["hidden_size"]
output_size = data["output_size"]
all_words = data['all_words']
tags = data['tags']
model_state = data["model_state"]
model = NeuralNet(input_size, hidden_size, output_size).to(device)
model.load_state_dict(model_state)
model.eval()
bot_name = "TravellChatty"
while True:
# sentence = "do you use credit cards?"
sentence =name
if sentence == "quit":
break
sentence = tokenize(sentence)
X = bag_of_words(sentence, all_words)
X = X.reshape(1, X.shape[0])
X = torch.from_numpy(X).to(device)
output = model(X)
_, predicted = torch.max(output, dim=1)
tag = tags[predicted.item()]
probs = torch.softmax(output, dim=1)
prob = probs[0][predicted.item()]
if prob.item() > 0.75:
for intent in intents['intents']:
if tag == intent["tag"]:
return (f" {random.choice(intent['responses'])}")
#print(f"{bot_name}: {random.choice(intent['responses'])}")
else:
return (f" I do not understand...")
#print(f"{bot_name}: I do not understand...")
app.run()
...@@ -2,6 +2,7 @@ import random ...@@ -2,6 +2,7 @@ import random
import json import json
import torch import torch
#import torch library
from model import NeuralNet from model import NeuralNet
from nltk_utils import bag_of_words, tokenize from nltk_utils import bag_of_words, tokenize
...@@ -25,7 +26,7 @@ model = NeuralNet(input_size, hidden_size, output_size).to(device) ...@@ -25,7 +26,7 @@ model = NeuralNet(input_size, hidden_size, output_size).to(device)
model.load_state_dict(model_state) model.load_state_dict(model_state)
model.eval() model.eval()
bot_name = "Sam" bot_name = "TravellChatty"
print("Let's chat! (type 'quit' to exit)") print("Let's chat! (type 'quit' to exit)")
while True: while True:
# sentence = "do you use credit cards?" # sentence = "do you use credit cards?"
...@@ -38,6 +39,9 @@ while True: ...@@ -38,6 +39,9 @@ while True:
X = X.reshape(1, X.shape[0]) X = X.reshape(1, X.shape[0])
X = torch.from_numpy(X).to(device) X = torch.from_numpy(X).to(device)
output = model(X) output = model(X)
_, predicted = torch.max(output, dim=1) _, predicted = torch.max(output, dim=1)
......
No preview for this file type
...@@ -35,8 +35,9 @@ ...@@ -35,8 +35,9 @@
{ {
"tag": "anuradhapura-places", "tag": "anuradhapura-places",
"patterns": ["what are the places i can visit in anuradhapura?", "what are the places I can see in Anuradhapura?", "what are the locations I can see in Anuradhapura", "Why am i going to anuradhapuraya?","What are the tourist places in anuradhapura?"], "patterns": ["what are the places i can visit in anuradhapura?", "what are the places I can see in Anuradhapura?", "what are the locations I can see in Anuradhapura", "Why am i going to anuradhapuraya?","What are the tourist places in anuradhapura?"],
"responses": ["You can see Sigiriya, Ruwanweliseya, Thuparamaya, Isurumuniya and many other historical places in Anuradhapura"] "responses": ["You can see Ruwanweliseya, Thuparamaya, Isurumuniya and many other historical places in Anuradhapura"]
}, },
{ {
"tag": "create-sigiriya", "tag": "create-sigiriya",
"patterns": ["who made sigiriya?", "who created sigiriya?", "who built sigiriya?","who built lion rock?"], "patterns": ["who made sigiriya?", "who created sigiriya?", "who built sigiriya?","who built lion rock?"],
...@@ -79,8 +80,8 @@ ...@@ -79,8 +80,8 @@
}, },
{ {
"tag": "station-sigiriya", "tag": "station-sigiriya",
"patterns": ["what is the nearest railway station to the sigiriya", "how long so far to closest railway station from sigiriya?","where is sigiriya"], "patterns": ["what is the nearest railway station to the sigiriya"," what is the closest station to the sigiriya", "how long so far to closest railway station from sigiriya?","where is sigiriya"],
"responses": ["Habarna is the closet railway station to Sigiriya. It's 15km away from Sigiriya."] "responses": ["Habarna is the closest railway station to Sigiriya. It's 15km away from Sigiriya."]
}, },
{ {
"tag": "heigh-sigiriya", "tag": "heigh-sigiriya",
...@@ -91,12 +92,111 @@ ...@@ -91,12 +92,111 @@
"tag": "why-sigiriya", "tag": "why-sigiriya",
"patterns": ["why create sigiriya", "what is reason for make sigiriya?","what is the main purpose of sigiriya","why built sigiriya"], "patterns": ["why create sigiriya", "what is reason for make sigiriya?","what is the main purpose of sigiriya","why built sigiriya"],
"responses": ["1In India he raised an army with the intention of returning and retaking the throne of Sri Lanka, which he considered to be rightfully his. Expecting the inevitable return of Moggallana, Kashyapa is said to have built his palace on the summit of Sigiriya as a fortress as well as a pleasure palace."] "responses": ["1In India he raised an army with the intention of returning and retaking the throne of Sri Lanka, which he considered to be rightfully his. Expecting the inevitable return of Moggallana, Kashyapa is said to have built his palace on the summit of Sigiriya as a fortress as well as a pleasure palace."]
},
{
"tag": "create-ruwanweliseya",
"patterns": ["who made ruwanweliseya?", "who created ruwanweliseya?","who built ruwanweliseya?" ,"who built ruwanweliseya?"],
"responses": ["Ruwanweliseya was built by King Dutugemunu"]
},
{
"tag": "important-ruwanweliseya",
"patterns": ["what is the important of the ruwanweliseya?","why am i go to ruwanweliseya?", "tell me about ruwanweliseya?", "why people like ruwanweliseya?","why is the important of the ruwanweliseya for us?","what is the special of the ruwanweliseya?"],
"responses": ["The Ruwanwelisaya is a stupa and a hemispherical structure containing relics, in Sri Lanka, considered sacred to many Buddhists all over the world. Two quarts or one Drona of the Gothama Buddha's relics are enshrined which is the largest collection of his relics anywhere.therefore, you should visit and see it"]
},
{
"tag": "when-ruwanweliseya",
"patterns": ["when create ruwanweliseya?", "when built ruwanweliseya?", "which year made ruwanweliseya"],
"responses": ["2nd century BCE"]
},
{
"tag": "heigh-ruwanweliseya",
"patterns": ["what is the height of ruwanweliseya", "what is the peak of ruwanweliseya?","elevation of ruwanweliseya?"],
"responses": ["Its present height is about 150 feet"]
},
{
"tag": "area-ruwanweliseya",
"patterns": ["what is the area of ruwanweliseya", "what is the diameter of ruwanweliseya?","width of ruwanweliseya?", "what is the diameter of ruwanweliseya?"],
"responses": ["379 feet"]
},
{
"tag": "station-ruwanweliseya",
"patterns": ["what is the nearest railway station to the ruwanweliseya"," what is the closest station to the ruwanweliseya", "how long so far to closest railway station from ruwanweliseya?","where is ruwanweliseya"],
"responses": ["4 Km - Distance from Anuradhapura Railway Station to ruwanweliseya"]
},
{
"tag": "brought-srimahabodi",
"patterns": ["who brought sri maha bodhi"," who give sri maha bodi","who give us srimahabodi"],
"responses": ["4 Km - Distance from Anuradhapura Railway Station to ruwanweliseya"]
},
{
"tag": "important-srimahabodi",
"patterns": ["what is the important of the sri maha bodhi?","why am i go to sri maha bodi?", "tell me about srimahabodi?", "why people like srimahabodi?","why is the important of the srimahabodhi for us?","what is the special of the srimahabodi?"],
"responses": ["Jaya Sri Maha Bodhi is a sacred bo tree in the Mahamewna Gardens, Anuradhapura, Sri Lanka. It is the southern branch from the historical Sri Maha Bodhi at Buddha Gaya in India under which Buddha attained Enlightenment"]
},
{
"tag": "when-srimahabodi",
"patterns": ["when create srimahabodi?", "when built sri maha bodhi?", "which year made srimahabodhi"],
"responses": ["It was planted in 288 BC"]
},
{
"tag": "where-srimahabodi",
"patterns": ["where is srimahabodi?", "what is the location of sri maha bodhi?", "where situated srimahabodhi"],
"responses": ["In Mahamewna Gardens, Anuradhapura, Sri Lanka"]
},
{
"tag": "station-srimahabodi",
"patterns": ["what is the nearest railway station to the sri maha bodhi"," what is the closest station to the srimahabodhi", "how long so far to closest railway station from srimahabodi?","where is srimahabodhi"],
"responses": ["4 Km - Distance from Anuradhapura Railway Station to sri maha bodhi"]
},
{
"tag": "create-Isurumuniya",
"patterns": ["who made isurumuniya?", "who created isurumuniya?", "who built isurumuniya?"],
"responses": ["The temple was built by King Devanampiya Tissa"]
},
{
"tag": "see-Isurumuniya",
"patterns": ["what can i see in isurumuniya?", "why am i go to isurumuniya?", "what are the beautiful places in isurumuniya?","why am i go to isurumuniya?"],
"responses": ["You can see Isurumuni Lovers,Royal Family Carving and Elephant Pond Carving in Isurumuniya"]
},
{
"tag": "important-Isurumuniya",
"patterns": ["what is the important of the isurumuniya?", "tell me about isurumuniya?", "why people like Isurumuniya?","why is the important of the Isurumuniya for us?","what is Isurumuniya?","what is the special of the Isurumuniya?"],
"responses": ["Isurumuniya is a Buddhist temple situated near to the Tissa Wewa (Tisa tank) in Anuradhapura, Sri Lanka. There are four carvings of special interest in this Vihara. They are the Isurumuniya Lovers, Elephant Pond and The Royal Family."]
},
{
"tag": "when-Isurumuniya",
"patterns": ["when create Isurumuniya?", "when built isurumuniya?", "which year made isurumuniya"],
"responses": ["Between 307 BC - 267 BC"]
},
{
"tag": "where-Isurumuniya",
"patterns": ["where is Isurumuniya?", "what is the location of Isurumuniya?", "where situated Isurumuniya"],
"responses": ["situated near to the Tissa Wewa (Tisa tank) in Anuradhapura, Sri Lanka"]
},
{
"tag": "station-Isurumuniya",
"patterns": ["what is the nearest railway station to the Isurumuniya"," what is the closest station to the Isurumuniya", "how long so far to closest railway station from Isurumuniya?"],
"responses": ["3 Km - Distance from Anuradhapura Railway Station to Isurumuniya"]
},
{
"tag": "create-kuttampokuna",
"patterns": ["who made kuttampokuna?", "who created Twin ponds?", "who built kuttampokuna?","who built kuttampokuna"],
"responses": ["Kuttampokuna was built by the Sinhalese in the ancient kingdom of Anuradhapura."]
},
{
"tag": "important-kuttampokuna",
"patterns": ["what is the important of the kuttampokuna?", "tell me about Twin ponds?", "why people like kuttampokuna?","why is the important of the kuttampokuna for us?", "tell me about kuttampokuna?","what is kuttampokuna?","what is the special of the kuttampokuna?"],
"responses": ["One of the best specimen of bathing tanks or pools in ancient Sri Lanka is the pair of pools known as Kuttam Pokuna (Twin Ponds/Pools). The said pair of pools were built by the Sinhalese in the ancient kingdom of Anuradhapura. These are considered one of the significant achievements in the field of hydrological engineering and outstanding architectural and artistic creations of the ancient Sinhalese."]
},
{
"tag": "area-kuttampokuna",
"patterns": ["what is the area of kuttampokuna", "what is the diameter of kuttampokuna?","width of Twin ponds?", "what is the diameter of kuttampokuna?"],
"responses": ["A garden was landscaped which separates the two ponds which long is 18½ ft. The larger pool of the two is 132 ft by 51 ft, while the smaller pool is 91 ft by 51 ft. The depths of the two pools is 14 ft and 18 ft for the smaller pool and the larger pool respectively."]
} }
] ]
} }
import numpy as np import numpy as np
import nltk import nltk
#nltk.download('punkt') nltk.download('punkt')
from nltk.stem.porter import PorterStemmer from nltk.stem.porter import PorterStemmer
stemmer = PorterStemmer() stemmer = PorterStemmer()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment