diff options
author | Anthony Wang | 2022-07-17 15:50:29 -0500 |
---|---|---|
committer | Anthony Wang | 2022-07-17 15:50:29 -0500 |
commit | 458143cf4511ad7b473740c901982dea01f7aab0 (patch) | |
tree | aab27b10ead6ae75458fe69ca81a88a1c005c55d | |
parent | a4765e17c55ec7793621f7bcb3be6255ededab3a (diff) |
Actually remove mentions
-rw-r--r-- | bot.py | 19 |
1 files changed, 10 insertions, 9 deletions
@@ -1,5 +1,6 @@ from argparse import ArgumentParser from random import randint, choice +from re import sub from transformers import AutoTokenizer, AutoModelForCausalLM @@ -61,11 +62,6 @@ if args.input is None: while len(line) < 2: line = choice(lines).split() - # Remove mentions - if line[0].count('@') > 1: - line[0] = '@'.join(line[0].split('@')[0:2]) - if line[1].count('@') > 1: - line[1] = '@'.join(line[1].split('@')[0:2]) args.input = line[0] + ' ' + line[1] @@ -77,10 +73,6 @@ output = tokenizer.decode(model.generate( print(output) -if args.instance is None: - quit() - - # Prepare the post output = output.split('\n') post = output[0] @@ -89,6 +81,15 @@ if len(post) < 200 and len(output) > 1: post = post[:500] +# Remove mentions +post = sub('(@[^ ]*)@[^ ]*', '\\1', post) + + +# Quit if no instance specified +if args.instance is None: + quit() + + # Post it! if args.backend == 'mastodon': from mastodon import Mastodon |