diff --git a/.gitignore b/.gitignore index f64629e..ff9614a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ .sekrit __pycache__ +bin/ +lib/ +pyvenv.cfg diff --git a/lulzbot.py b/lulzbot.py index df4a8ec..9e7a08f 100644 --- a/lulzbot.py +++ b/lulzbot.py @@ -1,11 +1,21 @@ -motd =''' - _ _ ____ ___ _ -| | _ _| | ___| __ ) / _ \| |_ -| | | | | | | |_ / _ \| | | | __| -| |__| |_| | |___ / /| |_) | |_| | |_ -|_____\__,_|_____/___|____/ \___/ \__| +import datetime +import discord +from src.flan import flan_speak +from src.cartman import cartman_speak +from src.twitter import get_tweet +from fortune import fortune +import numpy as np + + +motd = ''' + _ _ ____ ___ _ +| | _ _| | ___| __ ) / _ \| |_ +| | | | | | | |_ / _ \| | | | __| +| |__| |_| | |___ / /| |_) | |_| | |_ +|_____\__,_|_____/___|____/ \___/ \__| ''' -menu ='''``` + +menu = '''``` Commands: fortune: tell a fortune chuck: give a Chuck Norris quote @@ -18,40 +28,41 @@ Commands: Contribute! https://github.com/adoyle0/lulzbot```''' -import discord, datetime -import numpy as np -from fortune import fortune -from src.twitter import get_tweet -from src.cartman import cartman_speak -from src.flan import flan_speak chuck_quotes = open('data/chuck_quotes').read().split('\n%\n') ligma_list = open('data/ligma_list').read().split('\n') limericks = open('data/limericks').read().split('\n%\n') aclist = open('data/aclist').read().split('\n') + def show_menu(): return menu + def musk(): return get_tweet(44196397) + def ligma(): return np.random.choice(ligma_list) + def limerick(): return np.random.choice(limericks) + def prost(): return 'https://tenor.com/view/prost-christoph-waltz-django-bier-zum-wohle-gif-11041516' def chuck(): return np.random.choice(chuck_quotes) + def ac(): return np.random.choice(aclist) -triggers = {'lulzbot': show_menu, # these need to be functions + +triggers = {'lulzbot': show_menu, # these need to be functions 'musk': musk, 'deez': ligma, 'ligma': ligma, @@ -63,18 +74,22 @@ triggers = {'lulzbot': show_menu, # these need to be functions 'fortune': fortune, 'chuck': chuck, 'ac': ac, - } + } TOKEN = open('.sekrit/discord_token').read() intents = discord.Intents.default() -# intents.message_content = True -client = discord.Client(activity=discord.Game(name='with myself'), intents=intents) +intents.message_content = True +client = discord.Client(activity=discord.Game( + name='with myself'), intents=intents) + @client.event async def on_ready(): - print(motd+'\n'+datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')+'\nLogged in as {0.user}'.format(client)) + print(motd+'\n'+datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + + '\nLogged in as {0.user}'.format(client)) return + @client.event async def on_message(message): username = str(message.author).split('#')[0] @@ -87,14 +102,14 @@ async def on_message(message): elif message.channel.name == 'cartman': await message.channel.send(cartman_speak(user_message)) - #await message.channel.send("I'm broken, come back later.") + # await message.channel.send("I'm broken, come back later.") elif message.channel.name == 'flan': - await message.channel.send(flan_speak(user_message)) - # await message.channel.send('GPU is busy, come back later') + await message.channel.send(flan_speak(user_message)) + # await message.channel.send('GPU is busy, come back later') elif message.channel.name == 'shitposting': - if user_message.lower() in triggers: + if user_message.lower() in triggers: await message.channel.send(triggers[user_message.lower()]()) return diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..7c74927 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,6 @@ +discord +numpy +fortune-python +tweepy +transformers +torch diff --git a/run b/run new file mode 100755 index 0000000..3121156 --- /dev/null +++ b/run @@ -0,0 +1,7 @@ +#!/bin/bash + +source bin/activate && +pip install --upgrade pip && +pip install --upgrade -r requirements.txt && +clear && +python lulzbot.py diff --git a/src/cartman.py b/src/cartman.py index d97468f..365c1c8 100644 --- a/src/cartman.py +++ b/src/cartman.py @@ -1,36 +1,40 @@ +from transformers.models.auto.modeling_auto import AutoModelForCausalLM +from transformers.models.auto.tokenization_auto import AutoTokenizer import requests import json url = 'https://doordesk.net/chat' + def cartman_respond(user_message): message = {'Message': user_message} - response = requests.post(url,json.dumps(message)) + response = requests.post(url, json.dumps(message)) return response.json().get('Cartman') -from transformers.models.auto.modeling_auto import AutoModelForCausalLM -from transformers.models.auto.tokenization_auto import AutoTokenizer -tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-large") -model = AutoModelForCausalLM.from_pretrained("../cartman/train/cartman/models/output-medium") +tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-medium") +model = AutoModelForCausalLM.from_pretrained( + "../cartman/train/cartman/models/output-medium-3ep") + def cartman_speak(input_text): - input_ids = tokenizer(input_text + tokenizer.eos_token, return_tensors="pt").input_ids + input_ids = tokenizer(input_text + tokenizer.eos_token, + return_tensors="pt").input_ids outputs = model.generate( - input_ids, - pad_token_id=tokenizer.eos_token_id, - max_new_tokens = 200, - num_beams = 8, - num_beam_groups = 4, - no_repeat_ngram_size=3, - length_penalty = 1.4, - diversity_penalty = 0, - repetition_penalty = 2.1, - early_stopping = True, + input_ids, + pad_token_id=tokenizer.eos_token_id, + max_new_tokens=200, + num_beams=8, + num_beam_groups=4, + no_repeat_ngram_size=3, + length_penalty=1.4, + diversity_penalty=0, + repetition_penalty=2.1, + early_stopping=True, - # do_sample = True, - # top_k = 100, - # top_p = 0.7, - # temperature = 0.8, - ) + # do_sample = True, + # top_k = 100, + # top_p = 0.7, + # temperature = 0.8, + ) return tokenizer.decode(outputs[:, input_ids.shape[-1]:][0], skip_special_tokens=True)