-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathLisa.py
142 lines (126 loc) · 5.29 KB
/
Lisa.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
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
import random
import json
import torch
from Brain import NeuralNetwork
from NeuralNetworks import BagOfWords,Tokenize
import Features
Device=torch.device('cuda' if torch.cuda.is_available() else 'cpu')
with open('Intents.json','r',encoding='utf8') as JSONData:
Intents=json.load(JSONData)
Data=torch.load('DataTrain.pth')
ModelState=Data['ModelState']
InputSize=Data['InputSize']
OutputSize=Data['OutputSize']
HiddenSize=Data['HiddenSize']
AllWords=Data['AllWords']
Tags=Data['Tags']
Model=NeuralNetwork(InputSize,HiddenSize,OutputSize).to(Device)
Model.load_state_dict(ModelState)
Model.eval()
from Listen import Listen
from Speak import Speak
def Main():
Sentence=Listen("Listening")
Original=Sentence
print(Sentence)
Sentence=Tokenize(Sentence)
X=BagOfWords(Sentence,AllWords)
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()]
print(Prob.item())
if Prob.item()>0.75:
for Intent in Intents['intents']:
if Tag==Intent['tag']:
Reply=random.choice(Intent['responses'])
if Reply=="youtubesearch" or "youtube search" in Original:
Tokenized = Original.replace("youtube search", "")
Features.YoutubeSearch(Tokenized)
elif Reply=="googlesearch" or "google search" in Original:
Tokenized = Original.replace("google search", "")
Features.GoogleSearch(Tokenized)
elif Reply=="download" :
Features.DownloadVideo();
elif Reply=="testinternetspeed":
Features.SpeedTest();
elif Reply=="whatsappmessage":
Speak("Tell The Recipient Name");
Name=Listen("Recording");
print(f"--> User Name Is : {Name}")
Speak("Record Your Message")
Message=Listen("Recording");
print(f"--> Message Is : {Message}")
Features.WhatsappMessage(Name,Message)
elif Reply=="open":
Tokenized=Original.replace("open","");
Features.RunProgramme(Tokenized)
elif Reply=="respond":
Speak(Reply)
elif Reply=="calculate":
Tokenized = Original.replace("calculate", "")
Tokenized=Tokenized.replace("divided by","/")
Tokenized=Tokenized.replace("divide","/")
Tokenized=Tokenized.replace("x","*")
NewExp = "".join(i for i in Tokenized if i in "0123456789+*/-()")
Features.Calculator(NewExp)
elif Reply=="show" :
# Tokenize=Results.replace("show window","");
Tokenized=Original.split();
Features.ShowWindow(Tokenized[-1])
elif Reply=="close":
Features.CloseWindow()
elif Reply=="minimize":
Features.MinimizeWindow()
elif Reply=="maximize":
Features.MaximizeWindow()
# ==============Volume Control=================
elif Reply=="mute" :
Features.MuteAudio()
elif Reply=="increase":
Features.IncreaseAudio(Original)
elif Reply=="decrease":
Features.DecreaseAudio(Original)
# ==============Wi-Fi Control=================
elif Reply=="onwifi":
Features.TurnOnWiFi()
elif Reply=="offwifi":
Features.TurnOffWiFi()
# ==============Jokes API=================
elif Reply=="joke" :
Features.TellJoke()
# ===========Functionalities==============
elif Reply=="screenshot":
Features.ScreenShot()
elif Reply=="time" :
Features.CurrentTime()
elif Reply=="note":
Speak("Record Your Note, Go Ahead");
Note = Listen("Recording")
Features.WriteNote(Note)
elif Reply=="weather":
Features.Weather()
elif Reply=="question":
Speak("What Is Your Question ? ")
Que=Listen("Question");
print(f"--> Question : {Que.capitalize()}")
Features.QuestionAnswer(Que)
# ===========Game Tic Tac Toe============
elif Reply=="playgame":
Speak("Okaaay , Lets Play Tic Tac Toe. This is One of My Favourite")
Features.Games()
else:
if(len(Original)>0):
Speak(Reply)
else:
if "youtube search" in Original:
Tokenized = Original.replace("youtube search", "")
Features.YoutubeSearch(Tokenized)
elif "google search" in Original:
Tokenized = Original.replace("google search", "")
Features.GoogleSearch(Tokenized)
while True:
Main()