This commit is contained in:
Adam 2023-03-03 13:49:19 -05:00
parent 51e20ae01e
commit 0bc9a6ec82
5 changed files with 78 additions and 43 deletions

3
.gitignore vendored
View file

@ -1,2 +1,5 @@
.sekrit .sekrit
__pycache__ __pycache__
bin/
lib/
pyvenv.cfg

View file

@ -1,3 +1,12 @@
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 = ''' motd = '''
_ _ ____ ___ _ _ _ ____ ___ _
| | _ _| | ___| __ ) / _ \| |_ | | _ _| | ___| __ ) / _ \| |_
@ -5,6 +14,7 @@ motd ='''
| |__| |_| | |___ / /| |_) | |_| | |_ | |__| |_| | |___ / /| |_) | |_| | |_
|_____\__,_|_____/___|____/ \___/ \__| |_____\__,_|_____/___|____/ \___/ \__|
''' '''
menu = '''``` menu = '''```
Commands: Commands:
fortune: tell a fortune fortune: tell a fortune
@ -18,39 +28,40 @@ Commands:
Contribute! Contribute!
https://github.com/adoyle0/lulzbot```''' 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') chuck_quotes = open('data/chuck_quotes').read().split('\n%\n')
ligma_list = open('data/ligma_list').read().split('\n') ligma_list = open('data/ligma_list').read().split('\n')
limericks = open('data/limericks').read().split('\n%\n') limericks = open('data/limericks').read().split('\n%\n')
aclist = open('data/aclist').read().split('\n') aclist = open('data/aclist').read().split('\n')
def show_menu(): def show_menu():
return menu return menu
def musk(): def musk():
return get_tweet(44196397) return get_tweet(44196397)
def ligma(): def ligma():
return np.random.choice(ligma_list) return np.random.choice(ligma_list)
def limerick(): def limerick():
return np.random.choice(limericks) return np.random.choice(limericks)
def prost(): def prost():
return 'https://tenor.com/view/prost-christoph-waltz-django-bier-zum-wohle-gif-11041516' return 'https://tenor.com/view/prost-christoph-waltz-django-bier-zum-wohle-gif-11041516'
def chuck(): def chuck():
return np.random.choice(chuck_quotes) return np.random.choice(chuck_quotes)
def ac(): def ac():
return np.random.choice(aclist) 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, 'musk': musk,
'deez': ligma, 'deez': ligma,
@ -67,14 +78,18 @@ triggers = {'lulzbot': show_menu, # these need to be functions
TOKEN = open('.sekrit/discord_token').read() TOKEN = open('.sekrit/discord_token').read()
intents = discord.Intents.default() intents = discord.Intents.default()
# intents.message_content = True intents.message_content = True
client = discord.Client(activity=discord.Game(name='with myself'), intents=intents) client = discord.Client(activity=discord.Game(
name='with myself'), intents=intents)
@client.event @client.event
async def on_ready(): 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 return
@client.event @client.event
async def on_message(message): async def on_message(message):
username = str(message.author).split('#')[0] username = str(message.author).split('#')[0]

6
requirements.txt Normal file
View file

@ -0,0 +1,6 @@
discord
numpy
fortune-python
tweepy
transformers
torch

7
run Executable file
View file

@ -0,0 +1,7 @@
#!/bin/bash
source bin/activate &&
pip install --upgrade pip &&
pip install --upgrade -r requirements.txt &&
clear &&
python lulzbot.py

View file

@ -1,21 +1,25 @@
from transformers.models.auto.modeling_auto import AutoModelForCausalLM
from transformers.models.auto.tokenization_auto import AutoTokenizer
import requests import requests
import json import json
url = 'https://doordesk.net/chat' url = 'https://doordesk.net/chat'
def cartman_respond(user_message): def cartman_respond(user_message):
message = {'Message': 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') 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") tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-medium")
model = AutoModelForCausalLM.from_pretrained("../cartman/train/cartman/models/output-medium") model = AutoModelForCausalLM.from_pretrained(
"../cartman/train/cartman/models/output-medium-3ep")
def cartman_speak(input_text): 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( outputs = model.generate(
input_ids, input_ids,
pad_token_id=tokenizer.eos_token_id, pad_token_id=tokenizer.eos_token_id,