def main(): # record waht been said in audio r = sr.Recognizer() """ with sr.WavFile(voice_file) as source: audio = r.record(source) """ with sr.Microphone() as source: print("Say something!") audio = r.listen(source) # recognize the message (STT) try: speech_text = r.recognize_google(audio).lower().replace("'", "") print("Darong thinks you said '" + speech_text + "'") except sr.UnknownValueError: print("Darong cound not understand audio") except sr.RequestError as e: print( "Could not request results from Google Speech Recognition service; {0}" .format(e)) # call brain and pass the speech recognized to brain for processing brain(name, speech_text, city_name, city_code, proxy_username, proxy_password)
def main(): try: if sys.argv[1] == '--text' or sys.argv[1] == '-t': text_mode = True speech_text = raw_input("Write something: ").lower().replace( "'", "") except IndexError: text_mode = False r = sr.Recognizer() with sr.Microphone() as source: print("Say something!") audio = r.listen(source) try: speech_text = r.recognize_google(audio).lower().replace("'", "") print("Melissa thinks you said '" + speech_text + "'") except sr.UnknownValueError: print("Melissa could not understand audio") except sr.RequestError as e: print( "Could not request results from Google Speech Recognition service; {0}" .format(e)) play_music.mp3gen(music_path) imgur_handler.img_list_gen(images_path) brain(name, speech_text, music_path, city_name, city_code, proxy_username, proxy_password, consumer_key, consumer_secret, access_token, access_token_secret, client_id, client_secret, images_path) if text_mode: main() else: passiveListen()
def main(): try: if sys.argv[1] == '--text' or sys.argv[1] == '-t': text_mode = True speech_text = raw_input("Write something: ").lower().replace("'", "") except IndexError: text_mode = False r = sr.Recognizer() with sr.Microphone() as source: print("Say something!") audio = r.listen(source) try: speech_text = r.recognize_google(audio).lower().replace("'", "") print("Melissa thinks you said '" + speech_text + "'") except sr.UnknownValueError: print("Melissa could not understand audio") except sr.RequestError as e: print("Could not request results from Google Speech Recognition service; {0}".format(e)) play_music.mp3gen(music_path) brain(name, speech_text, music_path, city_name, city_code, proxy_username, proxy_password) if text_mode: main() else: passiveListen()
def stt(profile_data): va_name = profile_data['va_name'] r = sr.Recognizer() if profile_data['stt'] == 'google': while True: with sr.Microphone() as source: r.adjust_for_ambient_noise(source) print("Say something!") audio = r.listen(source) try: speech_text = r.recognize_google(audio).lower().replace("'", "") print(va_name + " thinks you said '" + speech_text + "'") except sr.UnknownValueError: print(va_name + " could not understand audio") except sr.RequestError as e: print("Could not request results from Google Speech Recognition service; {0}".format(e)) except AttributeError: print('You are not connected to the internet, please enter "sphinx" in the "stt" field of your "profile.json" file to work offline.') exit() else: brain(profile_data, speech_text) elif profile_data['stt'] == 'sphinx': modeldir = profile_data['pocketsphinx']['modeldir'].encode("ascii") hmm = profile_data['pocketsphinx']['hmm'].encode("ascii") lm = profile_data['pocketsphinx']['lm'].encode("ascii") dic = profile_data['pocketsphinx']['dic'].encode("ascii") config = Decoder.default_config() config.set_string('-hmm', os.path.join(modeldir, hmm)) config.set_string('-lm', os.path.join(modeldir, lm)) config.set_string('-dict', os.path.join(modeldir, dic)) config.set_string('-logfn', '/dev/null') decoder = Decoder(config) def sphinx_stt(): stream = open('recording.wav', 'rb') stream.seek(44) # bypasses wav header data = stream.read() decoder.start_utt() decoder.process_raw(data, False, True) decoder.end_utt() speech_text = decoder.hyp().hypstr print(va_name + " thinks you said '" + speech_text + "'") return speech_text.lower().replace("'", "") while True: with sr.Microphone() as source: r.adjust_for_ambient_noise(source) print("Say something!") audio = r.listen(source) with open("recording.wav", "wb") as f: f.write(audio.get_wav_data()) brain(profile_data, sphinx_stt())
def main(): r = sr.Recognizer() while True: # obtain audio from the microphone with sr.Microphone() as source: print("Say something!") audio = None speech_text = None while audio is None: audio = r.listen(source) time.sleep(1) # recognize speech using Google Speech Recognition try: # for testing purposes, you're just using the default API key # to use another API key, use `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")` # instead of `r.recognize_google(audio)` speech_text = r.recognize_google(audio) print("Ria thinks you said " + speech_text) except sr.UnknownValueError: #print("Google Speech Recognition could not understand audio") pass except sr.RequestError as e: print("Could not request results from Google Speech Recognition service;{0}".format(e)) if speech_text is not None: brain(name, speech_text, music_path, city_name, city_zip, consumer_key, consumer_secret, access_token, access_token_secret, amigo_host_port)
def execute(self): msg = self.message try: brain("Debasish", msg) return True except: return False pass
def main(ini): #text_mode if (ini == '-t'): speech_text = input("Write an order") #voice_mode else: speech_text = recorder() brain(name, city_name, speech_text)
def main(): while True: speech_text = '' for arg in sys.argv: if arg == '-t': speech_text = raw_input("What can I help you with?\n") if speech_text is '': speech_text = strip_accents(listen()) if speech_text != '': brain(name, speech_text.lower(), profile_data)
def main(): r = sr.Recognizer() with sr.Microphone(1) as source: print('Speak') audio = r.listen(source) try: speech_text = r.recognize_google(audio).lower().replace("'", "") print("Vicky thinks you said '" + speech_text + "'") except sr.UnknownValueError: print("Vicky could not understand you") except sr.RequestError as e: print("Could not request results from Speech recognition service; {0}". format(e)) brain(name, speech_text, city_name, city_code)
def main(voice_file): r = sr.Recognizer() with sr.WavFile(voice_file) as source: audio = r.record(source) try: speech_text = r.recognize_google(audio).lower().replace("'", "") print("Melissa thinks you said '" + speech_text + "'") except sr.UnknownValueError: print("Melissa could not understand audio") except sr.RequestError as e: print("Could not request results from Google Speech Recognition service; {0}".format(e)) play_music.mp3gen(music_path) brain(name, speech_text, music_path, city_name, city_code, proxy_username, proxy_password)
def main(): r = sr.Recognizer() with sr.Microphone() as source: print("Say something!") audio = r.listen(source) try: speech_text = r.recognize_google(audio).lower().replace("'", "") print("VA thinks you said '" + speech_text + "'") except sr.UnknownValueError: print("VA could not understand audio") except sr.RequestError as e: print("Could not request results from Google Speech Recognition service; {0}".format(e)) brain(name, speech_text, music_path, city_name, city_code)
def main(): r = sr.Recognizer() with sr.Microphone() as source: print "Say Something!" audio = r.listen(source) try: key = '6MXA3KORTY67ZHD45TUFFXPWFLAETARY' speech_text = r.recognize_wit(audio, key=key).lower().replace("'", "") print "Melissa thinks you said '" + speech_text + "'" except sr.UnknownValueError: print "Melissa could not understand audio" except sr.RequestError as e: print "Could not request results from Wit Speech Recognition service; {0}".format(e) brain(name, speech_text)
def main(): r = sr.Recognizer() with sr.Microphone() as source: r.adjust_for_ambient_noise(source,duration=5) print("Say something!") audio = r.listen(source) try: speech_text = r.recognize_google(audio).lower().replace("'", "") call(["espeak",speech_text]) print("Jarvis thinks you said '" + speech_text + "'") except sr.UnknownValueError: print("Jarvis could not understand audio") except sr.RequestError as e: print("Could not request results from Google Speech Recognition service; {0}".format(e)) brain(name, speech_text, city_name, city_code, proxy_username, proxy_password) main()
def main(voice_file): r = sr.Recognizer() with sr.WavFile(voice_file) as source: audio = r.record(source) try : speech_text = r.recognize_google(audio).lower().replace("'","") print("Mercury thinks you siad'"+speech_text+"'") except sr.UnknownValueError: print("Mercury could not understand audio") except sr.RequestError as e: print("Could not request results from Google Speech Recognition service; {0}".format(e)) play_music.mp3gen(music_path) brain(name,speech_text,music_path,city_name,city_code,proxy_username, proxy_password)
def start(self): msg = self.listen_keyboard() ret = brain(name, msg) if not ret: return ret return msg
def main(): r = sr.Recognizer() with sr.Microphone() as source: print("Say something interesting if possible! ") audio = r.listen(source) try: speech_text = r.recognize_google(audio).lower().replace("'", "").strip() print("I think you said '" + speech_text + "'") brain(name, speech_text) except sr.UnknownValueError: print("Sorry I could not understand the audio message") except sr.RequestError: print( "Could not request results from Google Speech Recognition service {0}" .format(e))
def y_predict(): sentiment = request.form["Message"] err, res = str(brain(sentiment)), '' if err == '0' or err == '1' : res, err = err, res if res=='1': return render_template('sentimental analysis.html', result = 'https://i.pinimg.com/originals/6c/aa/38/6caa38a6954ef94b5d2f72da66f94335.png', err = err) if res=='0': return render_template('sentimental analysis.html', result = 'https://images-na.ssl-images-amazon.com/images/I/711NDQNFqxL.png', err = err)
def start(self): while True: recognized_audio = self.driver() ret = brain("Debasish", recognized_audio) if not ret: return ret return recognized_audio pass
def main(): # Main Function r = sr.Recognizer() with sr.Microphone() as source: #device_index=1 r.adjust_for_ambient_noise(source) # here print("Say Something!") audio = r.listen(source) try: speech_text = r.recognize_google(audio).lower().replace("'", "") print("Lucy thinks you said '" + speech_text + "'") #Calls Brain Function brain(name, speech_text, music_path, city_name, city_code, proxy_username, proxy_password) except sr.UnknownValueError: print("Lucy could not understand audio") except sr.RequestError as e: print( "Could not request results from Google Speech Recognitionservice;{0}" .format(e))
def generate(self, max_x, max_y): self.nn = brain() self.health = 200 self.spike_length = 20 self.movement_speed = 6 self.change_angle_speed = 1 self.x_pos = int(np.random.rand() * max_x) self.y_pos = int(np.random.rand() * max_y) self.angle = int(np.random.rand() * 360) self.collides = False
def Dismis_is_listening(): with sr.Microphone() as source: speech.adjust_for_ambient_noise(source) speech.energy_threshhold = 4000 print('listening.....') audio = speech.listen(source) voice_text = '' try: voice_text = speech.recognize_google(audio).lower().replace( "'", "") print("DISMIS thinks you said " + voice_text) with open('speak.txt', mode='a+') as f1: f1.write(voice_text) f1.write('/n') except sr.UnknownValueError: pass except sr.RequestError as e: print('Network error') brain(voice_text, music_path, city_name, city_code)
def main(): #Obtain audio from the microphone and record it to a wav file r = sr.Recognizer() with sr.Microphone() as source: print("I'm Listening!") audio = r.listen(source) with open("recording.wav", "wb") as f: f.write(audio.get_wav_data()) #Comment the following part if you wish to use another speech recognition module try: os.system( "deepspeech --model models/output_graph.pbmm --alphabet models/alphabet.txt --lm models/lm.binary --trie models/trie --audio recording.wav >> data.txt" ) f = open("data.txt", "r") if f.mode == "r": speech_text = f.read() print("Aida thinks you said: " + speech_text) f = open( "data.txt", "w+" ) #+w means write/create. +a means append/create. r means read f.write("") #delete contents of text file f.close() os.remove("recording.wav") #delete wav file #Uncomment this part if you intend to recognize speech using CMU Pocket Sphinx Speech Recognition instead of Deep Speech # try: # speech_text = r.recognize_sphinx(audio).lower().replace(".","") # print("Aida thinks you said : " + speech_text +"'") except sr.UnknownValueError: print("Aida couldn't understand audio") #Uncomment this part ONLY if you intend to use an online speech recognition above (for example: r.recognize_google) BUT IT'S INSECURE ! # except sr.RequestError as e: # print("Couldn't request results from the internet; {0}".format(e)) brain(speech_text, music_path)
def main(phrase): ascii_phrase = remove_tildes( phrase ) #As python only works with ascii characteres, we have to do this if we want the rest of the things to work properly print ascii_phrase result = brain.brain(phrase, ascii_phrase) if result: #Some functions doesn't return anything print result tts.talk(profile.tts, result) notification.sendNotification(result)
def main(): print("***********************************************************") print("* PLEASE IGNORE THE ERROR MESSAGES, THEY AREN'T A PROBLEM *") print("***********************************************************") r = sr.Recognizer() r.energy_threshold = 4000 while True: with sr.Microphone() as source: print("Say something!") audio = r.listen(source) try: speech_text = r.recognize_google(audio).lower().replace("'", "") print("Melissa thinks you said '" + speech_text + "'") except sr.UnknownValueError: print("Melissa could not understand audio") except sr.RequestError as e: print( "Could not request results from Google Speech Recognition service; {0}" .format(e)) brain(name, speech_text, music_path, city_name, city_code)
def main(): r = sr.Recognizer() while True: with sr.Microphone() as source: print("Say something!") audio = r.listen(source) # Things to ask Melissa: # Describe me. How am I? How do I look? # Who am I? # How are you? # What is the time? try: speech_text = r.recognize_google(audio).lower().replace("'", "") print("Melissa thinks you said '" + speech_text + "'") except sr.UnknownValueError: print("Melissa could not understand audio") except sr.RequestError as e: print( "Could not request results from Google Speech Recognition service; {0}" .format(e)) brain(name, speech_text)
def __init__(self,h,old_gen=None) : self.h=h self.x=100 self.y=int(h/2) self.alive=True self.score=[0,0,0,0] self.oscore=[0,0,0,0] self.grad=[0,0,0,0] self.laxe=0 self.surface = pygame.Surface((20, 20)) self.surface.fill(YELLOW) self.rect = self.surface.get_rect() self.rect.center= (self.x, self.y) self.brain=brain(old_gen)
def __init__(self, screen, w, h): self.blocks = [ Block(int(w / 2), int(h / 2), YELLOW), Block(int(w / 2) + 10, int(h / 2), YELLOW) ] self.size = 2 self.direction = random.randrange(0, 4) self.dx = 10 self.dy = 10 self.w = w self.h = h self.screen = screen self.is_alive = True self.score = 0 self.energy = 1000.0 self.dist = 2000.0 self.brain = brain()
def __init__(self): self.version = '1.2.0' self.brain = brain.brain() self.barf = barf.Barf self.clean = self.brain.clean self.cfg = cfg self.settings = self.cfg.set() # Load scrib config (or create with these defaults). self.settings.load('conf/scrib.cfg', { 'name': 'scrib', 'debug': 0, 'muted': 0, 'reply_rate': 100, 'nick_reply_rate': 100, 'version': self.version }) # This is where we do some ownership command voodoo. self.owner_commands = { 'alias': "alias [this] [that]", 'find': "find [word]", 'forget': "forget [word]", 'censor': "censor [word]", 'check': "(deprecated) alias for rebuild", 'context': "context [word] (outputs to console)", 'learn': "learn [word]", 'learning': "Toggles bot learning.", 'replace': "replace [current] [new]", 'replyrate': "Shows/sets the reply rate.", 'save': "Saves the brain.", 'uncensor': "uncensor [word1] [word2] [word3] ...", 'unlearn': "unlearn [word]", 'quit': "Shut the bot down." } self.general_commands = { 'date': "Shows the date.", 'help': "Shows commands.", 'known': "known [word]", 'version': "Displays bot version.", 'words': "Shows number of words and contexts." } self.plugin_commands = PluginManager.plugin_commands self.commands = self.general_commands.keys() + self.owner_commands.keys() + self.plugin_commands.keys()
def active(): """Active state""" global RECOGNIZE_ERRORS print('I am in active state') speech_text = recognize() if speech_text: standby_state = brain(speech_text, bot_name, username, location, music_path, images_path) if standby_state == 0: return True else: time.sleep(1) tts('I am listening. You can ask me again.') return False else: # tts("I couldn't understand your audio, Try to say something!") RECOGNIZE_ERRORS += 1 return False
def __init__(self): self.best_state = -1 self.best_r = -1 self.grid_x = 4 self.grid_y = 4 self.grid_length = self.grid_x * self.grid_y self.grid_dict = {} self.team_size = 3 self.no_of_teams = 3 self.pop = self.team_size * self.no_of_teams self.agent_states = [-1 for x in range(self.pop)] self.actions = { 'up': (-1 * self.grid_x), 'left': (-1), 'right': (+1), 'down': (+1 * self.grid_x), 'stay': (0) } self.agents = [ brain.brain(self.grid_dict, self.grid_length, self.team_size, self.actions, self.agent_states, self.grid_x, self.grid_y) for x in range(self.pop) ]
import brain b = brain.brain() print('start teacher') b.start('teacher', 1000) print('end teacher') print('start nishi') b.start('nishi', 1000) print('end nishi') print('start akiyama') b.start('akiyama', 1000) print('end akiyama')
def stt(profile_data): va_name = profile_data['va_name'] r = sr.Recognizer() if profile_data['stt'] == 'google': while True: with sr.Microphone() as source: r.adjust_for_ambient_noise(source) print("Say something!") audio = r.listen(source) try: speech_text = r.recognize_google(audio).lower().replace( "'", "") print(va_name + " thinks you said '" + speech_text + "'") except sr.UnknownValueError: print(va_name + " could not understand audio") except sr.RequestError as e: print( "Could not request results from Google Speech Recognition service; {0}" .format(e)) except AttributeError: print( 'You are not connected to the internet, please enter "sphinx" in the "stt" field of your "profile.json" file to work offline.' ) exit() else: brain(profile_data, speech_text) elif profile_data['stt'] == 'sphinx': modeldir = profile_data['pocketsphinx']['modeldir'].encode("ascii") hmm = profile_data['pocketsphinx']['hmm'].encode("ascii") lm = profile_data['pocketsphinx']['lm'].encode("ascii") dic = profile_data['pocketsphinx']['dic'].encode("ascii") config = Decoder.default_config() config.set_string('-hmm', os.path.join(modeldir, hmm)) config.set_string('-lm', os.path.join(modeldir, lm)) config.set_string('-dict', os.path.join(modeldir, dic)) config.set_string('-logfn', '/dev/null') decoder = Decoder(config) def sphinx_stt(): stream = open('recording.wav', 'rb') stream.seek(44) # bypasses wav header data = stream.read() decoder.start_utt() decoder.process_raw(data, False, True) decoder.end_utt() speech_text = decoder.hyp().hypstr print(va_name + " thinks you said '" + speech_text + "'") return speech_text.lower().replace("'", "") while True: with sr.Microphone() as source: r.adjust_for_ambient_noise(source) print("Say something!") audio = r.listen(source) with open("recording.wav", "wb") as f: f.write(audio.get_wav_data()) brain(profile_data, sphinx_stt())
def y_predict(): sentiment = request.form["Message"] err, res = str(brain(sentiment)), '' if err == '0' or err == '1': res, err = err, res return render_template('index.html', result=res + '.png', err=err)
def __init__(self): self.id = var._c.get_id() self.brain = brain.brain(self) self.name = [None,None] self.maiden_name = None self.born = tuple(var._c.date) self.race = None self.male = True self.age = 0 self.parents = None self.spouse = None self.children = [] self.siblings = [] self.loc = [0,0] self.room_loc = [2,2] self.birthplace = self.get_room() self.in_room = False self.in_dungeon = False self.move_ticks = 0 self.room_move_ticks = 0 self.action = None self.attacking = False self.move_lock = None self.likes = ['price','damage','defense'] self.needs = [] self.bleeding = {'head':0,'eyes':0,\ 'larm':0,'rarm':0,\ 'lhand':0,'rhand':0,\ 'chest':0,'stomach':0,\ 'torso':0,'groin':0,\ 'lleg':0,'rleg':0,\ 'lfoot':0,'rfoot':0} self.condition = {'head':10,'eyes':10,\ 'larm':10,'rarm':10,\ 'lhand':10,'rhand':10,\ 'chest':10,'stomach':10,\ 'torso':10,'groin':10,\ 'lleg':10,'rleg':10,\ 'lfoot':10,'rfoot':10} self.wearing = {'head':None,'eyes':None,\ 'larm':None,'rarm':None,\ 'lhand':None,'rhand':None,\ 'chest':None,'stomach':None,\ 'torso':None,'groin':None,\ 'lleg':None,'rleg':None,\ 'lfoot':None,'rfoot':None} self.multiplier = {'head':2.0,'eyes':2.5,\ 'larm':.40,'rarm':.40,\ 'lhand':.20,'rhand':.20,\ 'chest':1.5,'stomach':1.0,\ 'torso':1.5,'groin':2.0,\ 'lleg':1.0,'rleg':1.0,\ 'lfoot':.40,'rfoot':.40} self.accuracy = {'head':35,'eyes':45,\ 'larm':30,'rarm':30,\ 'lhand':40,'rhand':40,\ 'chest':25,'stomach':25,\ 'torso':25,'groin':25,\ 'lleg':30,'rleg':30,\ 'lfoot':40,'rfoot':40} self.wielding = {'lhand':None,'rhand':None} self.hp = 10 self.mhp = 10 self.strength = 0 self.dexterity = 0 self.intelligence = 0 self.charisma = 0 self.weight = 0 self.stamina = 10 self.max_stamina = 10 #GAHHHHHHHHHHH CHANGEEEEEEEEEEEEEE self.defense = 3 #For self.brain... self.alert = 1 self.notoriety = 0 self.lastattacked = None self.potential_strength = 0 self.potential_dexterity = 0 self.potential_intelligence = 0 self.potential_charisma = 0 #jobs self.job = None #skills self.medicine = 5 self.speech = 2 self.perception = 25 self.skills = {'smallblades':3,'handtohand':3,'defense':2} #attributes self.attributes = {'naturalbeauty':False,\ 'conartist':False} self.items = [] self.events = {'lastbirthday':False,\ 'pregnant':False,\ 'pregnanton':False,\ 'pregnantby':None,\ 'seek_partner_age':None} self.schedule = [] self.path = None self.history = [] self.room_path = None self.description = ''
from flask import Flask, request from brain import brain app = Flask(__name__) br = brain() @app.route("/weather", methods=["GET", "POST"]) def weather(): if request.method == "GET": w_stats = br.get_weather() return w_stats elif request.method == "POST": data = request.get_json() data = data["sentence"].split()[-2:] print(data) data = ",".join(data) w_stats = br.get_weather(data) return w_stats @app.route("/twitter", methods=["GET", "POST"]) def twitter(): if request.method == "POST": data = request.get_json() print(data["sentence"]) return br.twitter(data["sentence"])[0] @app.route("/yelp", methods=["GET", "POST"]) def yelp():
def main(): profile = open('profile.yaml') profile_data = yaml.safe_load(profile) profile.close() r = sr.Recognizer() tts('Welcome ' + profile_data['name'] + ', systems are now ready to run. How can I help you?') if profile_data['stt'] == 'google': while True: with sr.Microphone() as source: r.adjust_for_ambient_noise(source) print("Say something!") audio = r.listen(source) try: speech_text = r.recognize_google(audio).lower().replace("'", "") print("Melissa thinks you said '" + speech_text + "'") except sr.UnknownValueError: print("Melissa could not understand audio") except sr.RequestError as e: print("Could not request results from Google Speech Recognition service; {0}".format(e)) else: brain(profile_data, speech_text) elif profile_data['stt'] == 'sphinx': def sphinx_stt(): modeldir = profile_data['pocketsphinx']['modeldir'] hmm = profile_data['pocketsphinx']['hmm'] lm = profile_data['pocketsphinx']['lm'] dic = profile_data['pocketsphinx']['dic'] config = Decoder.default_config() config.set_string('-hmm', os.path.join(modeldir, hmm)) config.set_string('-lm', os.path.join(modeldir, lm)) config.set_string('-dict', os.path.join(modeldir, dic)) config.set_string('-logfn', '/dev/null') decoder = Decoder(config) stream = open('recording.wav', 'rb') in_speech_bf = False decoder.start_utt() while True: buf = stream.read(1024) if buf: decoder.process_raw(buf, False, False) if decoder.get_in_speech() != in_speech_bf: in_speech_bf = decoder.get_in_speech() if not in_speech_bf: decoder.end_utt() speech_text = decoder.hyp().hypstr print speech_text decoder.start_utt() else: break decoder.end_utt() return speech_text.lower().replace("'", "") while True: with sr.Microphone() as source: r.adjust_for_ambient_noise(source) print("Say something!") audio = r.listen(source) with open("recording.wav", "wb") as f: f.write(audio.get_wav_data()) brain(profile_data, sphinx_stt())
b. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. c. Neither the name of the nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """ import brain n = input('write the number of bits ') code = """++++++++++[>+++++++>++++++++++>++++++++++>++++++++++>+++++++++++>+++>++++++++>+++ ++++++++>+++++++++++>++++++++++>++++++++++>+++<<<<<<<<<<<< - ]>++.>+.>++++++++.>++++++++.>+.>++.>+++++++.>+.>++++.>++++++++.>.>+++.""" out = brain.brain(n, code) print(out) # output resalt
epsilon = 0.3 #Exploration , '0.3' is 30% number_actions = 5 direction_boundary = (number_actions - 1) / 2 number_epochs = 100 max_memory = 3000 batch_size = 512 temperature_step = 1.5 #BUILDING THE ENVIRONMENT BY SIMPLY CREATING AN OBJECT OF THE ENVIRONMENT CLASS env = environment.Environment(optimal_temperature=(18.0, 24.0), initial_month=0, initial_number_users=20, initial_rate_data=30) #BUILDING THE BRAIN BY SIMPLY CREATING AN OBJECT OF THE BRAIN CLASS brain = brain.brain(learning_rate=0.00001, number_actions=number_actions) #BUILDING THE DQN BY SIMPLY CREATING AN OBJECT OF THE DQN CLASS dqn = dqn.DQN(max_memory=max_memory, discount_factor=0.9) #CHOOSING THE MODE train = True #TRAINING THE AI env.train = train model = brain.model if (env.train == True): #Starting the loop all over epochs (1 epoch = 5 months) for epoch in range(1, number_epochs): #INITIALIAZING ALL THE VARIABLES OF BOTH THE ENVIRONMENT AND THE TRAINING LOOP total_reward = 0