-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchatTrain.py
49 lines (35 loc) · 1021 Bytes
/
chatTrain.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#coding : utf-8
from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
import os
import pickle
import sqlite3
from datetime import datetime
bdd = sqlite3.connect('db/trainingSet.db')
sql = bdd.cursor()
chatbot = ChatBot(
"@ti-asa",
database_uri='sqlite:///db/ti-asa.db',
)
trainer = ListTrainer(chatbot)
res = os.popen('ls dataset')
res = res.read().split('\n')
try:
res.remove('')
except ValueError:
pass
i = 1
for fic in res:
try:
sql.execute("INSERT INTO TrainSET VALUES (?)", (fic,))
with open('dataset/' + fic, 'rb') as trainSet:
ds = pickle.load(trainSet)
trainer.train(ds)
print(f" {i} nouveau fichier d'entrainement trouvé(s)...")
os.popen(f"echo '{datetime.today()}: {fic} nouveau fichier d'entrainement trouvé(s)...'>>train.log")
i += 1
except sqlite3.IntegrityError:
os.popen(f"echo '{datetime.today()}: {fic} deja entrainer'>>train.log")
else:
bdd.commit()
bdd.close()