-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJarvis.py
More file actions
152 lines (122 loc) · 4.59 KB
/
Jarvis.py
File metadata and controls
152 lines (122 loc) · 4.59 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
from tkinter import N
from J import Ui_MainWindow
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import *
from PyQt5.QtGui import QMovie
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt, QTimer, QTime, QDate
from PyQt5.uic import loadUi
import sys
from Task import wishMe
import random
import json
import re
import torch
from Brain import NeuralNet
from NeauralNetwork import bag_of_words, tokenize
from datetime import datetime
from Listen import Suno
from Speak import Bol
from Task import NonInputExecution
from Task import InputExecution
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
with open("intents.json", "r") as json_data:
intents = json.load(json_data)
FILE = "data.pth"
data = torch.load(FILE)
input_size = data["input_size"]
hidden_size = data["hidden_size"]
output_size = data["output_size"]
all_words = data["all_words"]
tags = data["tags"]
model_state = data["model_state"]
model = NeuralNet(input_size, hidden_size, output_size).to(device)
model.load_state_dict(model_state)
model.eval()
Name = "JARVIS"
class MainThread(QThread):
def __init__(self):
super(MainThread, self).__init__()
startExe = MainThread()
class GUI_MOVIE(QMainWindow):
def __init__(self):
super().__init__()
self.gui = Ui_MainWindow()
self.gui.setupUi(self)
# self.gui.btn_start.clicked(self.startTask)
self.gui.btn_start.clicked.connect(self.startTask)
self.gui.btn_stop.clicked.connect(self.close)
def close(self):
exit()
def startTask(self):
self.gui.label1 = QtGui.QMovie("public//initial.gif")
self.gui.gif_1.setMovie(self.gui.label1)
self.gui.label1.start()
self.gui.label2 = QtGui.QMovie("public//live.gif")
self.gui.gif_2.setMovie(self.gui.label2)
self.gui.label2.start()
self.gui.label4 = QtGui.QMovie("public//ring.gif")
self.gui.gif_4.setMovie(self.gui.label4)
self.gui.label4.start()
wishMe(self)
self.gui.listener.setText("Thinking...")
timer = QTimer(self)
timer.timeout.connect(self.showTime)
timer.start(10)
startExe.start()
while True:
sentence = Suno()
result = str(sentence)
if sentence == "bye bye":
exit()
else:
self.gui.listener.setText(sentence)
sentence = tokenize(sentence)
X = bag_of_words(sentence, all_words)
X = X.reshape(1, X.shape[0])
X = torch.from_numpy(X).to(device)
output = model(X)
_, predicted = torch.max(output, dim=1)
tag = tags[predicted.item()]
probs = torch.softmax(output, dim=1)
prob = probs[0][predicted.item()]
if prob.item() > 0.75:
for intent in intents["intents"]:
if tag == intent["tag"]:
reply = random.choice(intent["responses"])
print(f"Reply:::=>{reply}")
if "time" in reply:
NonInputExecution(reply, self)
elif "date" in reply:
NonInputExecution(reply,self)
elif "day" in reply:
NonInputExecution(reply,self)
elif "wikipedia" in reply:
InputExecution(reply, sentence,self)
elif "google" in reply:
InputExecution(reply, result)
elif "youtube" in reply:
InputExecution(reply, result)
elif "joke" in reply:
NonInputExecution(reply, self)
elif "weather" in reply:
NonInputExecution(reply, self)
elif "music" in reply:
InputExecution(reply,result,self)
elif "news" in reply:
NonInputExecution(reply, self)
else:
self.gui.speaker.setText(reply)
Bol(reply)
def showTime(self):
current_time = QTime.currentTime()
current_date = QDate.currentDate()
label_time = current_time.toString("hh:mm:ss")
label_date = current_date.toString(Qt.ISODate)
self.gui.ojb_t1.setText(label_date)
self.gui.obj_t2.setText(label_time)
GUIApp = QApplication(sys.argv)
jarvis_GUI = GUI_MOVIE()
jarvis_GUI.show()
exit(GUIApp.exec_())