コード例 #1
0
def _main():
    data = datasets.open_subtitles(download=False)
    processor = preprocessing.PreProcessing()
    # s = list(data.values())[0]

    token_vectors, dictionary = load_token_vectors(processor)

    print('[train] creating network...')
    input_dim = len(dictionary['words'])
    input_length = MAX_LENGTH
    output_length = MAX_LENGTH
    output_dim = input_dim
    n_hidden = 10
    depth = 4
    batch_size = 50
    nb_epoch = 10

    dialog = models.Dialog(input_dim=input_dim,
                           input_length=input_length,
                           hidden_dim=n_hidden,
                           output_length=output_length,
                           output_dim=output_dim,
                           depth=depth)
    model = dialog.create_model()
    print('[train] validating...')
    for vectors in token_vectors:
        print('epoch')
        x_train, x_test, y_test, y_train = dialog.get_training_batch(vectors)
        dialog.train(x_train,
                     y_train,
                     batch_size=batch_size,
                     nb_epoch=nb_epoch,
                     validation_data=(x_test, y_test),
                     save_model=True)
コード例 #2
0
 def get_or_create_Dialog(self, with_user_pk, user=None):
     if not user:
         user = self.user
     print ("GET DIALOG")
     print(with_user_pk, user.to_json())
     d = models.Dialog.objects(owner=user.owner,
                               dialog_with_user_pk=with_user_pk)
     print(d.to_json())
     print("================")
     if not d:
         with_user = models.User.objects(owner=with_user_pk)[0]
         d = models.Dialog(owner=user.owner,
                           dialog_with_user_pk=with_user_pk,
                           dialog_with_user={
                           'pk': with_user_pk,
                           'username': with_user.username,
                           },
                           last_msg_timestamp=helpers.timestamp())
         d.save()
         return d
     else:
         return d[0]
コード例 #3
0
if os.getuid() == 0:
    root = True
else:
    root = False

# define script args
parser = argparse.ArgumentParser(
    description='Universal Post Install by https://linuxhub.it')
parser.add_argument('-gtk', action='store_true', help='run in GTK mode')
args = parser.parse_args()

# start the script
if args.gtk == True:
    if gui == True:
        if root == True:
            helper.load_script(type="gtk")
        else:
            dialog = models.Dialog(
                "UPI - Error!",
                "The flag (-gtk) needs the program to run as sudo! <a href=\"https://github.com/mirkobrombin/Universal-Post-Install/blob/master/README.md\" "
                "title=\"see here\">see here</a> how to do it", True, 580, 200,
                True, False)
            dialog.run()
    else:
        helper.error(
            "It is not possible to start in GUI mode on this system. The python-gi package is not installed."
        )
else:
    helper.load_script()
コード例 #4
0
from telegram.ext import Updater, CommandHandler, CallbackQueryHandler
import constants as const
import models

if __name__ == '__main__':
    updater = Updater(token=const.TOKEN_TELEGRAM_BOT)
    dispatcher = updater.dispatcher
    dialogs = models.Dialog()

    # ------------------------------------------------------
    dispatcher.add_handler(
        CommandHandler(
            'start', callback=lambda bot, update: dialogs.start(bot, update)))
    dispatcher.add_handler(
        CallbackQueryHandler(
            pattern='ask_one',
            callback=lambda bot, update: dialogs.ask_one(bot, update)))
    dispatcher.add_handler(
        CallbackQueryHandler(
            pattern='ask_sec',
            callback=lambda bot, update: dialogs.ask_sec(bot, update)))
    dispatcher.add_handler(
        CallbackQueryHandler(
            pattern='ask_third',
            callback=lambda bot, update: dialogs.ask_third(bot, update)))
    dispatcher.add_handler(
        CallbackQueryHandler(
            pattern='thx_for',
            callback=lambda bot, update: dialogs.thx_for(bot, update)))
    dispatcher.add_handler(
        CallbackQueryHandler(