def view_stream_image_callback(update, CallbackContext): username = CallbackContext.match.string.replace("view_stream_image_callback_", "") chatid = update.callback_query.message.chat_id messageid = update.callback_query.message.message_id if Utils.is_chatid_temp_banned(chatid): return model_instance = Model(username) keyboard = [[InlineKeyboardButton("Watch the live", url=f'http://chaturbate.com/{username}'), InlineKeyboardButton("Update stream image", callback_data='view_stream_image_callback_' + username)]] markup = InlineKeyboardMarkup(keyboard) try: bot.edit_message_media(chat_id=chatid, message_id=messageid, media=telegram.InputMediaPhoto(model_instance.model_image,caption=f"{username} is now <b>online</b>!",parse_mode=telegram.ParseMode.HTML), reply_markup=markup) except Exceptions.ModelPrivate: send_message(chatid, f"The model {username} is in private now, try again later", bot) logging.warning(f'{chatid} could not view {username} image update because is private') except Exceptions.ModelAway: send_message(chatid, f"The model {username} is away, try again later", bot) logging.warning(f'{chatid} could not view {username} image update because is away') except Exceptions.ModelPassword: send_message(chatid, f"The model {username} cannot be seen because is password protected", bot) logging.warning(f'{chatid} could not view {username} image update because is password protected') except (Exceptions.ModelDeleted, Exceptions.ModelBanned, Exceptions.ModelGeoblocked, Exceptions.ModelCanceled, Exceptions.ModelOffline): keyboard = [[InlineKeyboardButton("Watch the live", url=f'http://chaturbate.com/{username}')]] markup = InlineKeyboardMarkup(keyboard) bot.edit_message_reply_markup(chat_id=chatid, message_id=messageid, reply_markup=markup) #remove update image button send_message(chatid, f"The model {username} cannot be seen because is {model_instance.status}", bot) logging.warning(f'{chatid} could not view {username} image update because is {model_instance.status}') except Exceptions.ModelNotViewable: send_message(chatid, f"The model {username} is not visible", bot) logging.warning(f'{chatid} could not view {username} image update') except ConnectionError: send_message(chatid, f"The model {username} cannot be seen because of connection issues, try again later", bot) logging.warning(f'{chatid} could not view {username} image update because of connection issues') except Exception as e: if hasattr(e, 'message'): if "Message is not modified" in e.message: send_message(chatid, f"This is the latest update of {username}", bot) if not Utils.admin_check(chatid): if Utils.get_last_spam_date(chatid)==None: Utils.set_last_spam_date(chatid, datetime.datetime.now()) elif (datetime.datetime.now()-Utils.get_last_spam_date(chatid)).total_seconds() <= 3: Utils.temp_ban_chatid(chatid, 25) send_message(chatid, "You have been temporarily banned for spamming, try again later", bot) logging.warning(f"Soft banned {chatid} for 25 seconds for spamming image updates") else: Utils.set_last_spam_date(chatid, datetime.datetime.now())
def stream_image(update, CallbackContext) -> None: global bot args = CallbackContext.args chatid = update.message.chat_id if len(args) < 1: send_message(chatid, "You didn't specify a model to get the stream image of\nUse the command like this: /stream_image <b>username</b>", bot, html=True) return username = Utils.sanitize_username(args[0]) model_instance = Model(username) if not Utils.admin_check(chatid): if Utils.is_chatid_temp_banned(chatid): return if Utils.get_last_spam_date(chatid) == None: Utils.set_last_spam_date(chatid, datetime.datetime.now()) elif (datetime.datetime.now() - Utils.get_last_spam_date(chatid)).total_seconds() <= 3: Utils.temp_ban_chatid(chatid, 10) send_message(chatid,"You have been temporarily banned for spamming, try again later", bot) logging.warning(f"Soft banned {chatid} for 10 seconds for spamming image updates") else: Utils.set_last_spam_date(chatid, datetime.datetime.now()) try: send_image(chatid, model_instance.model_image, bot) logging.info(f'{chatid} viewed {username} stream image') except Exceptions.ModelPrivate: send_message(chatid, f"The model {username} is in private now, try again later", bot) logging.warning(f'{chatid} could not view {username} stream image because is private') except Exceptions.ModelAway: send_message(chatid, f"The model {username} is away, try again later", bot) logging.warning(f'{chatid} could not view {username} stream image because is away') except Exceptions.ModelPassword: send_message(chatid, f"The model {username} cannot be seen because is password protected", bot) logging.warning(f'{chatid} could not view {username} stream image because is password protected') except (Exceptions.ModelDeleted, Exceptions.ModelBanned, Exceptions.ModelGeoblocked, Exceptions.ModelCanceled, Exceptions.ModelOffline): send_message(chatid, f"The model {username} cannot be seen because is {model_instance.status}", bot) logging.warning(f'{chatid} could not view {username} image update because is {model_instance.status}') except Exceptions.ModelNotViewable: send_message(chatid, f"The model {username} is not visible", bot) logging.warning(f'{chatid} could not view {username} stream image') except ConnectionError: send_message(chatid, f"The model {username} cannot be seen because of connection issues, try again later", bot) logging.warning(f'{chatid} could not view {username} stream image because of connection issues')
def crawl(q, model_instances_dict): while not q.empty(): username = Utils.sanitize_username(q.get()[1].username) model_instance = Model(username, autoupdate=False) model_instance.update_model_status() try: model_instance.update_model_image() except Exception: model_instance.model_image = None # set to None just to be secure Todo: this may be extra model_instances_dict[username] = model_instance # signal to the queue that task has been processed q.task_done() return True
def add(update, context) -> None: global bot args = context.args chatid = update.message.chat_id username_message_list = [] if len(args) < 1: send_message( chatid, "You need to specify an username to follow, use the command like /add <b>username</b>\n You can also add multiple users at the same time by separating them using a comma, like /add <b>username1</b>,<b>username2</b>", bot, html=True) return # not lowercase usernames bug the api calls if len(args) > 1: for username in args: if username != "": username_message_list.append( Utils.sanitize_username(username).replace(",", "")) # len(args)==0 -> only one username or all in one line elif "," in args[0].lower(): for splitted_username in args[0].lower().replace( " ", "").rstrip().split(","): if splitted_username != "": username_message_list.append( Utils.sanitize_username(splitted_username)) else: username_message_list.append(Utils.sanitize_username(args[0])) username_message_list = list( dict.fromkeys(username_message_list)) # remove duplicate usernames usernames_in_database = Utils.alchemy_instance.session.query( ChaturbateUser).filter_by(chat_id=str(chatid)).all() # 0 is unlimited usernames if len(usernames_in_database) + len( username_message_list) > user_limit and ( Utils.admin_check(chatid) == False != user_limit != 0): send_message( chatid, "You are trying to add more usernames than your limit permits, which is " + str(user_limit), bot) logging.info( f'{chatid} tried to add more usernames than his limit permits') return for username in username_message_list: model_instance = Model(username) if model_instance.status not in ('deleted', 'banned', 'geoblocked', 'canceled', 'error'): if username not in usernames_in_database: Utils.alchemy_instance.session.add( ChaturbateUser(username=username, chat_id=chatid, online=False)) Utils.alchemy_instance.session.commit() send_message(chatid, f"{username} has been added", bot) logging.info(f'{chatid} added {username}') else: send_message(chatid, f"{username} has already been added", bot) elif model_instance.status == 'deleted': send_message(chatid, f"{username} has not been added because is deleted", bot) logging.info( f"{chatid} could not add {username} because is deleted") elif model_instance.status == 'banned': send_message(chatid, f"{username} has not been added because is banned", bot) logging.info( f"{chatid} could not add {username} because is banned") elif model_instance.status == 'geoblocked': send_message( chatid, f"{username} has not been added because is geoblocked", bot) logging.info( f"{chatid} could not add {username} because is geoblocked") elif model_instance.status == 'canceled': send_message(chatid, f"{username} was not added because it doesn't exist", bot) logging.info( f'{chatid} tried to add {username}, which does not exist') elif model_instance.status == 'error': send_message( chatid, f"{username} was not added because an error happened", bot) logging.info( f'{chatid} could not add {username} because an error happened')
from modules.Agent import Agent from modules.Game import Game from modules.PlayABunchOfGames import PlayABunchOfGames from modules.Model import Model # Make players agent_1 = Agent(player_id=1) agent_1.set_randomness(0.3) agent_2 = Agent(player_id=2) agent_2.set_randomness(0.3) players = [agent_1, agent_2] simulation = PlayABunchOfGames(players=players, loop=20) simulation.start() top_moves = simulation.get_top_moves() # Make a Model model = Model() model.train(top_moves)
simulation.start() # Get the best moves print('Getting the best moves...') top_percentage = 0.1 top_moves = simulation.get_top_moves(top_percentage=top_percentage) while len(top_moves) < 20 and top_percentage <= 1.0: top_percentage += 0.1 top_moves = simulation.get_top_moves(top_percentage=top_percentage) print('Top moves percentage:', top_percentage) if len(top_moves) > 0: # Make a Model print('Training model...') model = Model( pretrained_model='models/model_{}.h5'.format(current_generation) if current_generation > 1 else None ) model.train( moves=top_moves, epochs=10 ) model.save('models/model_{}.h5'.format(current_generation + 1)) # Write metadata print('Training finished. Writing metadata...') metadata['latest_generation_trained'] = current_generation + 1 with open('metadata.json', 'w') as f: f.write(json.dumps(metadata, indent=2)) current_generation += 1 else: print('Skipping training because no top_moves where returned')
is_train=True, repeat=False, pool_factor=8192) data = list(train_iter) filtered_data = [] max_length = 0 for x in data: if not ((x.src[0].squeeze() == config.src_unk).any() or (x.tgt.squeeze() == config.tgt_unk).any()): max_length = max(max_length,max(x.src[0].size(0), x.tgt.size(0))) filtered_data.append(x) config.max_sequence_length = max_length - 2 # bos, eos config.PRELOADING_SIZE = len(filtered_data) model = Model(config, DQN) if config.criterion == "mse": criterion = nn.MSELoss(reduction="none") elif config.criterion == "huber": criterion = nn.SmoothL1Loss(reduction="none") loss = MSELoss( criterion, model.current_model.generator ) config.rewards = ['BLEU'] config.rewards_weights = [1] reward = Reward(config)
from modules.Model import Model from modules.Screen import Screen from modules.Controller import Controller import tkinter as tk if __name__ == "__main__": root = tk.Tk() root.resizable(False, False) root.title('Generate Notes') root.geometry('900x800') model = Model() view = Screen(root) ctrl = Controller(model, view) root.mainloop()
def add(update, CallbackContext) -> None: global bot args = CallbackContext.args chatid = update.message.chat_id username_message_list = [] if len(args) < 1: send_message( chatid, "You need to specify an username to follow, use the command like /add <b>username</b>\n You can also add multiple users at the same time by separating them using a comma, like /add <b>username1</b>,<b>username2</b>", bot, html=True ) return # not lowercase usernames bug the api calls if len(args) > 1: for username in args: if username != "": username_message_list.append(Utils.sanitize_username(username).replace(",", "")) # len(args)==0 -> only one username or all in one line elif "," in args[0].lower(): for splitted_username in args[0].lower().replace(" ", "").rstrip().split(","): if splitted_username != "": username_message_list.append(Utils.sanitize_username(splitted_username)) else: username_message_list.append(Utils.sanitize_username(args[0])) username_message_list = list(dict.fromkeys(username_message_list)) # remove duplicate usernames usernames_in_database = [] # obtain present usernames results = Utils.retrieve_query_results(f"SELECT USERNAME FROM CHATURBATE WHERE CHAT_ID='{chatid}'") for row in results: usernames_in_database.append(row[0]) # 0 is unlimited usernames if len(usernames_in_database) + len(username_message_list) > user_limit and ( Utils.admin_check(chatid) == False != user_limit != 0): send_message(chatid, "You are trying to add more usernames than your limit permits, which is " + str(user_limit), bot) logging.info(f'{chatid} tried to add more usernames than his limit permits') return for username in username_message_list: model_instance=Model(username) if model_instance.status not in ('deleted', 'banned', 'geoblocked', 'canceled', 'error'): if username not in usernames_in_database: Utils.exec_query(f"INSERT INTO CHATURBATE VALUES ('{username}', '{chatid}', 'F')") send_message(chatid, f"{username} has been added", bot) logging.info(f'{chatid} added {username}') else: send_message(chatid,f"{username} has already been added",bot) elif model_instance.status=='deleted': send_message(chatid, f"{username} has not been added because is deleted", bot) logging.info(f"{chatid} could not add {username} because is deleted") elif model_instance.status=='banned': send_message(chatid, f"{username} has not been added because is banned", bot) logging.info(f"{chatid} could not add {username} because is banned") elif model_instance.status=='geoblocked': send_message(chatid, f"{username} has not been added because is geoblocked", bot) logging.info(f"{chatid} could not add {username} because is geoblocked") elif model_instance.status=='canceled': send_message(chatid, f"{username} was not added because it doesn't exist", bot) logging.info(f'{chatid} tried to add {username}, which does not exist') elif model_instance.status=='error': send_message(chatid, f"{username} was not added because an error happened", bot) logging.info(f'{chatid} could not add {username} because an error happened')