-
Notifications
You must be signed in to change notification settings - Fork 0
/
aitextgen_bot.py
60 lines (55 loc) · 1.86 KB
/
aitextgen_bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from pathlib import Path
import discord
from aitextgen import aitextgen
from discord.ext import commands
import os
from datetime import datetime
bot = commands.Bot(command_prefix='~')
token = ''
ai = aitextgen(model_folder="trained_model")
dirpath = os.getcwd()
@bot.command()
async def generate(ctx, arg=None):
'''
Function: generates text randomly or based on a prompt.
'''
if arg is not None:
the_prompt = ' '.join(arg)
if isinstance(the_prompt, str):
ai.generate_to_file(n=1, max_length=120,
prompt=the_prompt, temperature=0.8)
dirFiles = os.listdir(".")
dirFiles.sort(reverse=True)
print(dirFiles)
file_name = dirFiles[0]
if (file_name == "trained_model"):
file_name = dirFiles[1]
if (file_name == ''):
file_name = dirFiles[2]
print(file_name)
file = open(file_name, encoding="utf8")
lines = file.readlines()
output = ""
for line in lines:
output += line
await ctx.send(output)
else:
await ctx.send("Prompt should be a string. Not sure where this went wrong.")
else:
ai.generate_to_file(n=1, max_length=120, temperature=0.8)
dirFiles = os.listdir(".")
dirFiles.sort(reverse=True)
print(dirFiles)
file_name = dirFiles[0]
if (file_name == "trained_model"):
file_name = dirFiles[1]
if (file_name == 'drizzy.py'):
file_name = dirFiles[2]
print(file_name)
file = open(file_name, encoding="utf8")
lines = file.readlines()
output = ""
for line in lines:
output += line
await ctx.send(output)
bot.run(token)