datasciencedojo commited on
Commit
030b429
1 Parent(s): c8cd4ed

revert to old code

Browse files
Files changed (1) hide show
  1. app.py +21 -10
app.py CHANGED
@@ -1,10 +1,9 @@
1
  import nltk
2
  nltk.download('punkt')
3
-
4
  from nltk.stem.lancaster import LancasterStemmer
5
  import numpy as np
6
- import tensorflow as tf
7
- from tensorflow.keras.models import load_model
8
  import random
9
  import json
10
  import pandas as pd
@@ -17,9 +16,18 @@ with open("intents.json") as file:
17
  data = json.load(file)
18
 
19
  with open("data.pickle", "rb") as f:
20
- words, labels, training, output = pickle.load(f)
 
 
 
 
 
 
 
 
 
 
21
 
22
- model = load_model("MentalHealthChatBotmodel.tflearn")
23
 
24
  def bag_of_words(s, words):
25
  bag = [0 for _ in range(len(words))]
@@ -34,22 +42,25 @@ def bag_of_words(s, words):
34
 
35
  return np.array(bag)
36
 
 
37
  def chat(message, history):
38
  history = history or []
39
  message = message.lower()
40
- results = model.predict(np.array([bag_of_words(message, words)]))
41
  results_index = np.argmax(results)
42
  tag = labels[results_index]
43
 
44
  for tg in data["intents"]:
45
- if tg['tag'] == tag:
46
- responses = tg['responses']
47
- response = random.choice(responses)
48
 
 
 
 
49
  history.append((message, response))
50
  return history, history
51
 
52
- chatbot = gr.Chatbot(chat)
53
  css = """
54
  footer {display:none !important}
55
  .output-markdown{display:none !important}
 
1
  import nltk
2
  nltk.download('punkt')
 
3
  from nltk.stem.lancaster import LancasterStemmer
4
  import numpy as np
5
+ import tflearn
6
+ import tensorflow
7
  import random
8
  import json
9
  import pandas as pd
 
16
  data = json.load(file)
17
 
18
  with open("data.pickle", "rb") as f:
19
+ words, labels, training, output = pickle.load(f)
20
+
21
+ net = tflearn.input_data(shape=[None, len(training[0])])
22
+ net = tflearn.fully_connected(net, 8)
23
+ net = tflearn.fully_connected(net, 8)
24
+ net = tflearn.fully_connected(net, len(output[0]), activation="softmax")
25
+ net = tflearn.regression(net)
26
+
27
+ model = tflearn.DNN(net)
28
+ model.load("MentalHealthChatBotmodel.tflearn")
29
+ # print('model loaded successfully')
30
 
 
31
 
32
  def bag_of_words(s, words):
33
  bag = [0 for _ in range(len(words))]
 
42
 
43
  return np.array(bag)
44
 
45
+
46
  def chat(message, history):
47
  history = history or []
48
  message = message.lower()
49
+ results = model.predict([bag_of_words(message, words)])
50
  results_index = np.argmax(results)
51
  tag = labels[results_index]
52
 
53
  for tg in data["intents"]:
54
+ if tg['tag'] == tag:
55
+ responses = tg['responses']
 
56
 
57
+ # print(random.choice(responses))
58
+ response = random.choice(responses)
59
+
60
  history.append((message, response))
61
  return history, history
62
 
63
+ chatbot = gr.Chatbot(label="Chat")
64
  css = """
65
  footer {display:none !important}
66
  .output-markdown{display:none !important}