Yhhxhfh commited on
Commit
35c1a65
1 Parent(s): bda1f51

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -3
app.py CHANGED
@@ -2,7 +2,7 @@ import nltk
2
  nltk.download('punkt')
3
  nltk.download('wordnet')
4
  nltk.download('omw-1.4')
5
- nltk.download('punkt_tab')
6
  from nltk.stem import WordNetLemmatizer
7
 
8
  import json
@@ -39,6 +39,10 @@ async def train_and_save_model():
39
  r = redis.Redis(host=os.getenv("REDIS_HOST"), port=int(os.getenv("REDIS_PORT")), password=redis_password)
40
 
41
  while True:
 
 
 
 
42
  for intent in intents['intents']:
43
  for pattern in intent['patterns']:
44
  w = nltk.word_tokenize(pattern)
@@ -48,6 +52,7 @@ async def train_and_save_model():
48
  classes.append(intent['tag'])
49
 
50
  words = [lemmatizer.lemmatize(w.lower()) for w in words if w not in ignore_words]
 
51
 
52
  training = []
53
  output_empty = [0] * len(classes)
@@ -63,7 +68,8 @@ async def train_and_save_model():
63
 
64
  training.append([bag, output_row])
65
 
66
- training = np.array(training)
 
67
  train_x = list(training[:, 0])
68
  train_y = list(training[:, 1])
69
 
@@ -91,7 +97,7 @@ async def train_and_save_model():
91
  @app.on_event("startup")
92
  async def startup_event():
93
  import asyncio
94
- asyncio.create_task(train_and_save_model()) # Start training in the background
95
 
96
 
97
  if __name__ == "__main__":
 
2
  nltk.download('punkt')
3
  nltk.download('wordnet')
4
  nltk.download('omw-1.4')
5
+ nltk.download('punkt_tab') # Added punkt_tab download
6
  from nltk.stem import WordNetLemmatizer
7
 
8
  import json
 
39
  r = redis.Redis(host=os.getenv("REDIS_HOST"), port=int(os.getenv("REDIS_PORT")), password=redis_password)
40
 
41
  while True:
42
+ words.clear()
43
+ classes.clear()
44
+ documents.clear()
45
+
46
  for intent in intents['intents']:
47
  for pattern in intent['patterns']:
48
  w = nltk.word_tokenize(pattern)
 
52
  classes.append(intent['tag'])
53
 
54
  words = [lemmatizer.lemmatize(w.lower()) for w in words if w not in ignore_words]
55
+ words = sorted(list(set(words)))
56
 
57
  training = []
58
  output_empty = [0] * len(classes)
 
68
 
69
  training.append([bag, output_row])
70
 
71
+ training = np.array(training, dtype=object)
72
+
73
  train_x = list(training[:, 0])
74
  train_y = list(training[:, 1])
75
 
 
97
  @app.on_event("startup")
98
  async def startup_event():
99
  import asyncio
100
+ asyncio.create_task(train_and_save_model())
101
 
102
 
103
  if __name__ == "__main__":