Beispiel #1
0
    def send_post(self, destination):
        try:
            # Отправляем текст, нарезая при необходимости
            for text in cut_long_text(self.final_text):
                my_bot.send_message(
                    destination,
                    text,
                    parse_mode="HTML",
                    disable_web_page_preview=self.web_preview_url == '')

            # Отправляем отображаемые приложения к посту
            for url in self.gif_links:
                my_bot.send_document(destination, url)
            if len(self.image_links) > 0:
                my_bot.send_media_group(
                    destination,
                    [InputMediaPhoto(url) for url in self.image_links])
            if len(self.video_links) > 0:
                my_bot.send_media_group(
                    destination,
                    [InputMediaVideo(url) for url in self.video_links])
            for url in self.audio_links:
                my_bot.send_audio(destination, url)
        except apihelper.ApiException:
            action_log("VK Error: api exception")
Beispiel #2
0
    def send_post(self, destination):
        try:
            # Отправляем текст, нарезая при необходимости
            for text in cut_long_text(self.final_text):
                my_bot.send_message(destination, text, parse_mode="HTML",
                                    disable_web_page_preview=self.web_preview_url == '')

            # Отправляем отображаемые приложения к посту
            for url in self.gif_links:
                my_bot.send_document(destination, url)
            if len(self.image_links) > 0:
                my_bot.send_media_group(destination, [InputMediaPhoto(url) for url in self.image_links])
            if len(self.video_links) > 0:
                my_bot.send_media_group(destination, [InputMediaVideo(url) for url in self.video_links])
            for url in self.audio_links:
                my_bot.send_audio(destination, url)
        except apihelper.ApiException:
            action_log("VK Error: api exception")
Beispiel #3
0
    def send_post(self, destination):
        # Отправляем текст, нарезая при необходимости
        for text in cut_long_text(self.final_text):
            my_bot.send_message(
                destination,
                text,
                parse_mode="HTML",
                disable_web_page_preview=self.web_preview_url == '')

        # Отправляем отображаемые приложения к посту
        for url in self.video_links:
            my_bot.send_message(destination, url)
        for url in self.gif_links:
            my_bot.send_document(destination, url)
        for url in self.image_links:
            my_bot.send_photo(destination, url)
        for url in self.audio_links:
            my_bot.send_audio(destination, url)
Beispiel #4
0
def get_log(message):
    user_action_log(message, "requested bot logs")
    with open(config.file_location['bot_logs'], 'r', encoding='utf-8') as file:
        lines = file.readlines()[-100:]
        for text in cut_long_text(''.join(lines), max_len=3500):
            my_bot.reply_to(message, "{}".format(text))
Beispiel #5
0
def get_log(message):
    user_action_log(message, "requested bot logs")
    with open(config.file_location['bot_logs'], 'r', encoding='utf-8') as file:
        lines = file.readlines()[-100:]
        for text in cut_long_text(''.join(lines), max_len=3500):
            my_bot.reply_to(message, "{}".format(text))
Beispiel #6
0
from configs import *
from model import *
from tqdm import tqdm
from utils import write_ann_file, cut_long_text, ernie_tokenizer
""" 设置模型与优化器 """
model = BilstmCRF(label_size)
""" 设置模型路径 """
ckpt = tf.train.Checkpoint(model=model)
ckpt.restore(tf.train.latest_checkpoint('../resource/model_1019/'))
""" 预测测试集 """
test_files = [x for x in os.listdir(TEST_PATH)]

for file in tqdm(test_files):
    with open(TEST_PATH + file, 'r') as reader:
        text = reader.read()
    cut_texts, _ = cut_long_text(text, [])

    pred_labels = []

    for cut_text in cut_texts:
        # cut_text的前后是有cls与sep两个token的
        text_ids = ernie_tokenizer.encode(list(cut_text))
        text_ids = tf.expand_dims(tf.constant(text_ids), axis=0)
        attention_mask = tf.math.not_equal(text_ids, 0)
        pred_label = model(text_ids, attention_mask)
        # 掐掉头尾的cls与sep
        pred_label = pred_label[0].numpy().tolist()[1:-1]
        pred_labels.extend(pred_label)

    write_ann_file(file_name=file.split('.')[0],
                   text=text,