├── Advanced-Wikipedia.py ├── Combining-Wolfram-and-Wikipedia.py ├── Example-Wikipedia-App.py ├── Making-GUI-Dynamic.py ├── PyDa-Complete.py ├── README.md ├── Speech-Recognition.py ├── Wolfram-Alpha.py └── WxPython.py /Advanced-Wikipedia.py: -------------------------------------------------------------------------------- 1 | import wikipedia 2 | 3 | while True: 4 | input = raw_input("Q: ") 5 | wikipedia.set_lang("es") 6 | print wikipedia.summary(input, sentences=2) 7 | -------------------------------------------------------------------------------- /Combining-Wolfram-and-Wikipedia.py: -------------------------------------------------------------------------------- 1 | import wikipedia 2 | import wolframalpha 3 | 4 | while True: 5 | input = raw_input("Q: ") 6 | 7 | try: 8 | #wolframalpha 9 | app_id = "YOUR APP ID" 10 | client = wolframalpha.Client(app_id) 11 | res = client.query(input) 12 | answer = next(res.results).text 13 | print answer 14 | except: 15 | #wikipedia 16 | print wikipedia.summary(input) 17 | -------------------------------------------------------------------------------- /Example-Wikipedia-App.py: -------------------------------------------------------------------------------- 1 | import wikipedia 2 | 3 | while True: 4 | input = raw_input("Q: ") 5 | print wikipedia.summary(input) 6 | -------------------------------------------------------------------------------- /Making-GUI-Dynamic.py: -------------------------------------------------------------------------------- 1 | import wx 2 | import wikipedia 3 | import wolframalpha 4 | 5 | class MyFrame(wx.Frame): 6 | def __init__(self): 7 | wx.Frame.__init__(self, None, 8 | pos=wx.DefaultPosition, size=wx.Size(450, 100), 9 | style=wx.MINIMIZE_BOX | wx.SYSTEM_MENU | wx.CAPTION | 10 | wx.CLOSE_BOX | wx.CLIP_CHILDREN, 11 | title="PyDa") 12 | panel = wx.Panel(self) 13 | my_sizer = wx.BoxSizer(wx.VERTICAL) 14 | lbl = wx.StaticText(panel, 15 | label="Hello I am Pyda the Python Digital Assistant. How can I help you?") 16 | my_sizer.Add(lbl, 0, wx.ALL, 5) 17 | self.txt = wx.TextCtrl(panel, style=wx.TE_PROCESS_ENTER,size=(400,30)) 18 | self.txt.SetFocus() 19 | self.txt.Bind(wx.EVT_TEXT_ENTER, self.OnEnter) 20 | my_sizer.Add(self.txt, 0, wx.ALL, 5) 21 | panel.SetSizer(my_sizer) 22 | self.Show() 23 | 24 | def OnEnter(self, event): 25 | input = self.txt.GetValue() 26 | input = input.lower() 27 | try: 28 | #wolframalpha 29 | app_id = "YOUR APP ID" 30 | client = wolframalpha.Client(app_id) 31 | res = client.query(input) 32 | answer = next(res.results).text 33 | print answer 34 | except: 35 | #wikipedia 36 | print wikipedia.summary(input) 37 | 38 | 39 | if __name__ == "__main__": 40 | app = wx.App(True) 41 | frame = MyFrame() 42 | app.MainLoop() 43 | -------------------------------------------------------------------------------- /PyDa-Complete.py: -------------------------------------------------------------------------------- 1 | import wx 2 | from espeak import espeak 3 | import wikipedia 4 | import wolframalpha 5 | from espeak import espeak 6 | import wolframalpha 7 | 8 | app_id = "YOUR APP ID" 9 | client = wolframalpha.Client(app_id) 10 | 11 | class MyFrame(wx.Frame): 12 | def __init__(self): 13 | wx.Frame.__init__(self, None, 14 | pos=wx.DefaultPosition, size=wx.Size(450, 100), 15 | style=wx.MINIMIZE_BOX | wx.SYSTEM_MENU | wx.CAPTION | 16 | wx.CLOSE_BOX | wx.CLIP_CHILDREN, 17 | title="PyDa") 18 | panel = wx.Panel(self) 19 | my_sizer = wx.BoxSizer(wx.VERTICAL) 20 | lbl = wx.StaticText(panel, 21 | label="Hello I am Pyda the Python Digital Assistant. How can I help you?") 22 | my_sizer.Add(lbl, 0, wx.ALL, 5) 23 | self.txt = wx.TextCtrl(panel, style=wx.TE_PROCESS_ENTER,size=(400,30)) 24 | self.txt.SetFocus() 25 | self.txt.Bind(wx.EVT_TEXT_ENTER, self.OnEnter) 26 | my_sizer.Add(self.txt, 0, wx.ALL, 5) 27 | panel.SetSizer(my_sizer) 28 | self.Show() 29 | 30 | def OnEnter(self, event): 31 | 32 | input = self.txt.GetValue() 33 | input = input.lower() 34 | try: 35 | res = client.query(input) 36 | answer = next(res.results).text 37 | print answer 38 | espeak.synth("The answer is "+str(answer)) 39 | except: 40 | try: 41 | input = input.split(' ') 42 | input = ' '.join(input[2:]) 43 | print wikipedia.summary(input) 44 | except: 45 | print "I don't know" 46 | 47 | 48 | if __name__ == "__main__": 49 | app = wx.App(True) 50 | frame = MyFrame() 51 | app.MainLoop() 52 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PyDa-Course-Code 2 | 3 | This is all of the code that we will write in my course "Build A Virtual Assistant In Python" 4 | 5 | If you want to see the code from the updated youtube video, click here: 6 | https://gist.github.com/KhanradCoder/7886acf1a51d8635ec2ab09f81de6268 7 | -------------------------------------------------------------------------------- /Speech-Recognition.py: -------------------------------------------------------------------------------- 1 | import speech_recognition as sr 2 | r = sr.Recognizer() 3 | with sr.Microphone() as source: 4 | audio = r.listen(source) 5 | try: 6 | self.txt.SetValue(r.recognize_google(audio)) 7 | except sr.UnknownValueError: 8 | print("Google Speech Recognition could not understand audio") 9 | except sr.RequestError as e: 10 | print("Could not request results from Google Speech Recognition service; {0}".format(e)) 11 | -------------------------------------------------------------------------------- /Wolfram-Alpha.py: -------------------------------------------------------------------------------- 1 | import wolframalpha 2 | 3 | input = raw_input("Q: ") 4 | app_id = "YOUR APP ID" 5 | client = wolframalpha.Client(app_id) 6 | 7 | res = client.query(input) 8 | answer = next(res.results).text 9 | 10 | print answer 11 | -------------------------------------------------------------------------------- /WxPython.py: -------------------------------------------------------------------------------- 1 | import wx 2 | class MyFrame(wx.Frame): 3 | def __init__(self): 4 | wx.Frame.__init__(self, None, 5 | pos=wx.DefaultPosition, size=wx.Size(450, 100), 6 | style=wx.MINIMIZE_BOX | wx.SYSTEM_MENU | wx.CAPTION | 7 | wx.CLOSE_BOX | wx.CLIP_CHILDREN, 8 | title="PyDa") 9 | panel = wx.Panel(self) 10 | my_sizer = wx.BoxSizer(wx.VERTICAL) 11 | lbl = wx.StaticText(panel, 12 | label="Hello I am Pyda the Python Digital Assistant. How can I help you?") 13 | my_sizer.Add(lbl, 0, wx.ALL, 5) 14 | self.txt = wx.TextCtrl(panel, style=wx.TE_PROCESS_ENTER,size=(400,30)) 15 | self.txt.SetFocus() 16 | self.txt.Bind(wx.EVT_TEXT_ENTER, self.OnEnter) 17 | my_sizer.Add(self.txt, 0, wx.ALL, 5) 18 | panel.SetSizer(my_sizer) 19 | self.Show() 20 | 21 | def OnEnter(self, event): 22 | input = self.txt.GetValue() 23 | input = input.lower() 24 | 25 | 26 | if __name__ == "__main__": 27 | app = wx.App(True) 28 | frame = MyFrame() 29 | app.MainLoop() 30 | 31 | --------------------------------------------------------------------------------