Skip to content

Commit abdf618

Browse files
Add files via upload
1 parent 57d108b commit abdf618

23 files changed

+264
-0
lines changed

__pycache__/chatbot.cpython-310.pyc

1.44 KB
Binary file not shown.
1.21 KB
Binary file not shown.

bot_label_encoder.npy

425 Bytes
Binary file not shown.

bot_replies/all_products.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Here's our complete catalogue:
2+
MARK I: For arm amputees. Our simple and light weight model of arm prosthesis. Suitable for simple tasks.
3+
MARK II: For arm amputees. An advanced and dextrous arm. Involves softroboric for best grip and individual finger control.
4+
EXO 0: For hand injury rehabilitation and hand paralysis. Comfortable, light-weight and simple.
5+
EXO I: For hand injury rehabilitation and hand paralysis. Dextrous movements and powerful gripping action.

bot_replies/buy_request.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Prosthesis is a very personalized solution, differening from user to user.
2+
Kindly provide your details here and we will contact you:
3+
https://forms.gle/C6Em8mSkH5zgbS576

bot_replies/company_info.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Handyman Prosthetics create hand prosthesis and exoskeleton support for people who lost their arms or the ability to control it.
2+
Our perosonalized solutions enable them to carry out simple day to day tasks without having to rely on others.

bot_replies/demo_request.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Sure! Here's a video demo:
2+
https://youtube.com/playlist?list=PLsE-jsMAf6MONnhrq0_Z4-rIY8xSVyArC

bot_replies/end_convo.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Thank you for contacting us. Have a nice day!

bot_replies/exoskeleton_product.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Here are our exoskeleton support solutions:
2+
EXO 0: For hand injury rehabilitation and hand paralysis. Comfortable, light-weight and simple.
3+
EXO I: For hand injury rehabilitation and hand paralysis. Dextrous movements and powerful gripping action.

bot_replies/prosthesis_products.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Here are our arm prosthesis solutions:
2+
MARK I: For arm amputees. Our simple and light weight model of arm prosthesis. Suitable for simple tasks.
3+
MARK II: For arm amputees. An advanced and dextrous arm. Involves softroboric for best grip and individual finger control.

bot_replies/start_convo.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hi! I am Handy, AI chatbot of Handyman Prosthetics. How may I help you?

bot_vectorizer.p

2.85 KB
Binary file not shown.

chatbot.py

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
from sklearn import preprocessing
2+
import numpy as np
3+
import pickle
4+
from tensorflow import keras
5+
6+
7+
8+
class chatbot:
9+
def __init__(self):
10+
11+
#Loading a Model
12+
self.loaded_model = keras.models.load_model("chatbot_model");
13+
14+
#Print Model Summary
15+
# self.loaded_model.summary()
16+
17+
#Convert input into IF-IDF vector using the same vectorizer model
18+
self.vectorizer = pickle.load( open( "bot_vectorizer.p", "rb" ) );
19+
20+
self.encoder = preprocessing.LabelEncoder();
21+
self.encoder.classes_ = np.load('bot_label_encoder.npy',allow_pickle=True);
22+
23+
24+
self.start_state = 'start_convo'
25+
self.end_state = 'end_convo'
26+
27+
#Loading Bot Replies
28+
bot_reply_classes = [self.start_state]+list(self.encoder.classes_)
29+
self.bot_replies = {}
30+
for reply_class in bot_reply_classes:
31+
with open('bot_replies/'+reply_class+'.txt') as f:
32+
self.bot_replies[reply_class] = f.readlines()
33+
34+
def respond(self,user_reply):
35+
if user_reply==None or len(user_reply)<=3:
36+
state = self.start_state
37+
print("\n\n")
38+
else:
39+
predict_tfidf=self.vectorizer.transform([user_reply]).toarray();
40+
prediction=np.argmax( self.loaded_model.predict(predict_tfidf), axis=1 );
41+
state = self.encoder.inverse_transform(prediction)[0]
42+
convo = True
43+
if state == self.end_state:
44+
convo = False
45+
46+
return self.bot_replies[state], convo
47+
48+
49+
50+
51+
52+
# state = start_state
53+
# while state!=end_state:
54+
# for line in bot_replies[state]:
55+
# print('Handy: '+line.strip())
56+
57+
# user_reply = input('user: ')
58+
59+
# predict_tfidf=vectorizer.transform([user_reply]).toarray();
60+
# prediction=np.argmax( loaded_model.predict(predict_tfidf), axis=1 );
61+
62+
# state = encoder.inverse_transform(prediction)[0]
63+
# for line in bot_replies[state]:
64+
# print('Handy: '+line.strip())

chatbot_model/keras_metadata.pb

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
�.root"_tf_keras_sequential*�-{"name": "sequential_1", "trainable": true, "expects_training_arg": true, "dtype": "float32", "batch_input_shape": null, "must_restore_from_config": false, "class_name": "Sequential", "config": {"name": "sequential_1", "layers": [{"class_name": "InputLayer", "config": {"batch_input_shape": {"class_name": "__tuple__", "items": [null, 73]}, "dtype": "float32", "sparse": false, "ragged": false, "name": "Hidden-Layer-1_input"}}, {"class_name": "Dense", "config": {"name": "Hidden-Layer-1", "trainable": true, "batch_input_shape": {"class_name": "__tuple__", "items": [null, 73]}, "dtype": "float32", "units": 32, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}}, {"class_name": "Dense", "config": {"name": "Hidden-Layer-2", "trainable": true, "dtype": "float32", "units": 32, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}}, {"class_name": "Dense", "config": {"name": "Hidden-Layer-3", "trainable": true, "dtype": "float32", "units": 32, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}}, {"class_name": "Dense", "config": {"name": "Output-Layer", "trainable": true, "dtype": "float32", "units": 7, "activation": "softmax", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}}]}, "shared_object_id": 13, "input_spec": [{"class_name": "InputSpec", "config": {"dtype": null, "shape": {"class_name": "__tuple__", "items": [null, 73]}, "ndim": 2, "max_ndim": null, "min_ndim": null, "axes": {}}}], "build_input_shape": {"class_name": "TensorShape", "items": [null, 73]}, "is_graph_network": true, "full_save_spec": {"class_name": "__tuple__", "items": [[{"class_name": "TypeSpec", "type_spec": "tf.TensorSpec", "serialized": [{"class_name": "TensorShape", "items": [null, 73]}, "float32", "Hidden-Layer-1_input"]}], {}]}, "save_spec": {"class_name": "TypeSpec", "type_spec": "tf.TensorSpec", "serialized": [{"class_name": "TensorShape", "items": [null, 73]}, "float32", "Hidden-Layer-1_input"]}, "keras_version": "2.9.0", "backend": "tensorflow", "model_config": {"class_name": "Sequential", "config": {"name": "sequential_1", "layers": [{"class_name": "InputLayer", "config": {"batch_input_shape": {"class_name": "__tuple__", "items": [null, 73]}, "dtype": "float32", "sparse": false, "ragged": false, "name": "Hidden-Layer-1_input"}, "shared_object_id": 0}, {"class_name": "Dense", "config": {"name": "Hidden-Layer-1", "trainable": true, "batch_input_shape": {"class_name": "__tuple__", "items": [null, 73]}, "dtype": "float32", "units": 32, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}, "shared_object_id": 1}, "bias_initializer": {"class_name": "Zeros", "config": {}, "shared_object_id": 2}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "shared_object_id": 3}, {"class_name": "Dense", "config": {"name": "Hidden-Layer-2", "trainable": true, "dtype": "float32", "units": 32, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}, "shared_object_id": 4}, "bias_initializer": {"class_name": "Zeros", "config": {}, "shared_object_id": 5}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "shared_object_id": 6}, {"class_name": "Dense", "config": {"name": "Hidden-Layer-3", "trainable": true, "dtype": "float32", "units": 32, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}, "shared_object_id": 7}, "bias_initializer": {"class_name": "Zeros", "config": {}, "shared_object_id": 8}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "shared_object_id": 9}, {"class_name": "Dense", "config": {"name": "Output-Layer", "trainable": true, "dtype": "float32", "units": 7, "activation": "softmax", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}, "shared_object_id": 10}, "bias_initializer": {"class_name": "Zeros", "config": {}, "shared_object_id": 11}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "shared_object_id": 12}]}}, "training_config": {"loss": "categorical_crossentropy", "metrics": [[{"class_name": "MeanMetricWrapper", "config": {"name": "accuracy", "dtype": "float32", "fn": "categorical_accuracy"}, "shared_object_id": 15}]], "weighted_metrics": null, "loss_weights": null, "optimizer_config": {"class_name": "RMSprop", "config": {"name": "RMSprop", "learning_rate": 0.0010000000474974513, "decay": 0.0, "rho": 0.8999999761581421, "momentum": 0.0, "epsilon": 1e-07, "centered": false}}}}2
3+
�root.layer_with_weights-0"_tf_keras_layer*�{"name": "Hidden-Layer-1", "trainable": true, "expects_training_arg": false, "dtype": "float32", "batch_input_shape": {"class_name": "__tuple__", "items": [null, 73]}, "stateful": false, "must_restore_from_config": false, "class_name": "Dense", "config": {"name": "Hidden-Layer-1", "trainable": true, "batch_input_shape": {"class_name": "__tuple__", "items": [null, 73]}, "dtype": "float32", "units": 32, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}, "shared_object_id": 1}, "bias_initializer": {"class_name": "Zeros", "config": {}, "shared_object_id": 2}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "shared_object_id": 3, "input_spec": {"class_name": "InputSpec", "config": {"dtype": null, "shape": null, "ndim": null, "max_ndim": null, "min_ndim": 2, "axes": {"-1": 73}}, "shared_object_id": 16}, "build_input_shape": {"class_name": "TensorShape", "items": [null, 73]}}2
4+
�root.layer_with_weights-1"_tf_keras_layer*�{"name": "Hidden-Layer-2", "trainable": true, "expects_training_arg": false, "dtype": "float32", "batch_input_shape": null, "stateful": false, "must_restore_from_config": false, "class_name": "Dense", "config": {"name": "Hidden-Layer-2", "trainable": true, "dtype": "float32", "units": 32, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}, "shared_object_id": 4}, "bias_initializer": {"class_name": "Zeros", "config": {}, "shared_object_id": 5}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "shared_object_id": 6, "input_spec": {"class_name": "InputSpec", "config": {"dtype": null, "shape": null, "ndim": null, "max_ndim": null, "min_ndim": 2, "axes": {"-1": 32}}, "shared_object_id": 17}, "build_input_shape": {"class_name": "TensorShape", "items": [null, 32]}}2
5+
�root.layer_with_weights-2"_tf_keras_layer*�{"name": "Hidden-Layer-3", "trainable": true, "expects_training_arg": false, "dtype": "float32", "batch_input_shape": null, "stateful": false, "must_restore_from_config": false, "class_name": "Dense", "config": {"name": "Hidden-Layer-3", "trainable": true, "dtype": "float32", "units": 32, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}, "shared_object_id": 7}, "bias_initializer": {"class_name": "Zeros", "config": {}, "shared_object_id": 8}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "shared_object_id": 9, "input_spec": {"class_name": "InputSpec", "config": {"dtype": null, "shape": null, "ndim": null, "max_ndim": null, "min_ndim": 2, "axes": {"-1": 32}}, "shared_object_id": 18}, "build_input_shape": {"class_name": "TensorShape", "items": [null, 32]}}2
6+
�root.layer_with_weights-3"_tf_keras_layer*�{"name": "Output-Layer", "trainable": true, "expects_training_arg": false, "dtype": "float32", "batch_input_shape": null, "stateful": false, "must_restore_from_config": false, "class_name": "Dense", "config": {"name": "Output-Layer", "trainable": true, "dtype": "float32", "units": 7, "activation": "softmax", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}, "shared_object_id": 10}, "bias_initializer": {"class_name": "Zeros", "config": {}, "shared_object_id": 11}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "shared_object_id": 12, "input_spec": {"class_name": "InputSpec", "config": {"dtype": null, "shape": null, "ndim": null, "max_ndim": null, "min_ndim": 2, "axes": {"-1": 32}}, "shared_object_id": 19}, "build_input_shape": {"class_name": "TensorShape", "items": [null, 32]}}2
7+
�]root.keras_api.metrics.0"_tf_keras_metric*�{"class_name": "Mean", "name": "loss", "dtype": "float32", "config": {"name": "loss", "dtype": "float32"}, "shared_object_id": 20}2
8+
�^root.keras_api.metrics.1"_tf_keras_metric*�{"class_name": "MeanMetricWrapper", "name": "accuracy", "dtype": "float32", "config": {"name": "accuracy", "dtype": "float32", "fn": "categorical_accuracy"}, "shared_object_id": 15}2

chatbot_model/saved_model.pb

102 KB
Binary file not shown.
Binary file not shown.
1.74 KB
Binary file not shown.

customeVectorizor.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import nltk
2+
from nltk.stem import WordNetLemmatizer
3+
from nltk.corpus import stopwords
4+
from sklearn import preprocessing
5+
import numpy as np
6+
7+
8+
9+
from sklearn.feature_extraction.text import TfidfVectorizer
10+
11+
#Build a TF-IDF Vectorizer model
12+
13+
#Custom tokenizer to remove stopwords and use lemmatization
14+
lemmatizer = WordNetLemmatizer()
15+
def customtokenize(str):
16+
#Split string as tokens
17+
tokens=nltk.word_tokenize(str)
18+
#Filter for stopwords
19+
nostop = list(filter(lambda token: token not in stopwords.words('english'), tokens))
20+
#Perform lemmatization
21+
22+
lemmatized=[lemmatizer.lemmatize(word) for word in nostop ]
23+
return lemmatized
24+
25+
# vectorizer = TfidfVectorizer(tokenizer=customtokenize)
26+
27+
class customVect(TfidfVectorizer):
28+
def __init__():
29+
customVect.tokenizer = customtokenize;

handy_chatbot.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
import chatbot
3+
from nltk.stem import WordNetLemmatizer
4+
from nltk.corpus import stopwords
5+
import nltk
6+
7+
lemmatizer = WordNetLemmatizer()
8+
def customtokenize(str):
9+
#Split string as tokens
10+
tokens=nltk.word_tokenize(str)
11+
#Filter for stopwords
12+
nostop = list(filter(lambda token: token not in stopwords.words('english'), tokens))
13+
#Perform lemmatization
14+
lemmatized=[lemmatizer.lemmatize(word) for word in nostop ]
15+
return lemmatized
16+
17+
18+
import sys
19+
if __name__ == '__main__':
20+
21+
try:
22+
23+
user_reply = " ".join(sys.argv[1:])
24+
print("User: "+user_reply)
25+
except:
26+
user_reply = None
27+
chatbot = chatbot.chatbot()
28+
bot_reply, convo = chatbot.respond(user_reply)
29+
print(convo)
30+
for line in bot_reply:
31+
print('Handy: '+line.strip())
32+
33+
34+

hello.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
print('hellow')
2+
print('mellow')

java_chatbot.iml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
<orderEntry type="library" name="jython-standalone-2.7.2" level="project" />
11+
</component>
12+
</module>
1.94 KB
Binary file not shown.

0 commit comments

Comments
 (0)