-
Notifications
You must be signed in to change notification settings - Fork 0
/
jarvis.py
109 lines (76 loc) · 3.63 KB
/
jarvis.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import nltk
from nltk.stem.lancaster import LancasterStemmer
stemmer = LancasterStemmer()
import os
import argparse
import time
import dateutil.parser
import numpy
import tflearn
import tensorflow
import random
import json
import pickle
import google.getEvents as gc
import chatbot as chatbot
import google.getEvents as gc
import glob
def main():
tag = ""
while tag != "greeting":
inp = chatbot.get_audio()
results = glob.model.predict([chatbot.bag_of_words(inp, glob.words)])[0]
results_index = numpy.argmax(results)
tag = glob.labels[results_index]
print(" /\ \ /\ \ /\ \ /\__\ ___ /\ \ ")
print(" \:\ \ /::\ \ /::\ \ /:/ / /\ \ /::\ \ ")
print(" ___ /::\__\ /:/\:\ \ /:/\:\ \ /:/ / \:\ \ /:/\ \ \ ")
print(" /\ /:/\/__/ /::\~\:\ \ /::\~\:\ \ /:/__/ ___ /::\__\ _\:\~\ \ \ ")
print(" \:\/:/ / /:/\:\ \:\__\ /:/\:\ \:\__\ |:| | /\__\ __/:/\/__/ /\ \:\ \ \__\ ")
print(" \::/ / \/__\:\/:/ / \/_|::\/:/ / |:| |/:/ / /\/:/ / \:\ \:\ \/__/ ")
print(" \/__/ \::/ / |:|::/ / |:|__/:/ / \::/__/ \:\ \:\__\ ")
print(" /:/ / |:|\/__/ \::::/__/ \:\__\ \:\/:/ / ")
print(" /:/ / |:| | ~~~~ \/__/ \::/ / ")
print(" \/__/ \|__| \/__/ ")
for intent in glob.data['intents']:
if intent['tag'] == tag:
responses = intent['responses']
chatbot.speak(random.choice(responses))
chat()
def chat():
while True:
print("Contexto antigo: " + str(glob.context))
print("Contexto novo: " + str(glob.new_context))
if glob.context != glob.new_context:
glob.context = glob.new_context
glob.words, glob.labels, glob.training, glob.output, glob.model, glob.data = load_model(glob.context, glob.lang)
inp = chatbot.get_audio()
chatbot.chat(inp)
if glob.new_context == "goodbye":
break
parser = argparse.ArgumentParser(
description="Inspired by MCU J.A.R.V.I.S, a simple chatbot with voice"
)
parser.add_argument('--credentials_path', metavar='', help='Path for the google calendar credential\'s file', default='credentials.json')
parser.add_argument('--language', metavar='', help='Initial language used by Jarvis', default='en')
credentials_path = parser.parse_args().credentials_path
glob.lang = parser.parse_args().language
def load_model(m, language):
with open("model/" + language + "/" + m + "/data.pickle", "rb") as f:
words, labels, training, output = pickle.load(f)
tensorflow.reset_default_graph()
net = tflearn.input_data(shape=[None, len(training[0])])
net = tflearn.fully_connected(net, 8)
net = tflearn.fully_connected(net, 8)
net = tflearn.fully_connected(net, len(output[0]), activation='softmax')
net = tflearn.regression(net)
model = tflearn.DNN(net)
model.load("model/" + language + "/" + m + "/model.tflearn")
with open("intents/" + language + "/" + m + ".json") as file:
data = json.load(file)
return words, labels, training, output, model, data
# Definição de variável global para autenticação de Google Calendar
glob.service = gc.authenticate_google(credentials_path)
# Load de arquivo de controle de controle de conversa
glob.words, glob.labels, glob.training, glob.output, glob.model, glob.data = load_model('intents', glob.lang)
main()