Advertisement
KrishnaDas

Discord AI Text Generator Using textgenrnn and Tensorflow

Apr 8th, 2020
1,163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. import discord
  2. from textgenrnn import textgenrnn
  3. from discord.ext import commands
  4. import string
  5. import requests
  6. import time, threading
  7. import asyncio
  8. from pathlib import Path
  9. my_file = Path('/textgenrnn_weights.hdf5')
  10. prefix = "?"
  11. bot = commands.Bot(command_prefix = prefix)
  12. async def textgenerator():
  13.     await bot.wait_until_ready()
  14.     channel = bot.get_channel(541495294857183244)
  15.     while not bot.is_closed():
  16.         if my_file.exists():
  17.             t = textgenrnn('textgenrnn_weights.hdf5')
  18.         else:
  19.             t = textgenrnn()
  20.         t.train_from_file('index.txt', num_epochs = 1)
  21.         generation = (t.generate(1, temperature = 0.5, return_as_list=True,)[0])
  22.         embed=discord.Embed(title="Machiavelli Text Generation", description = generation, color = (0xF48D1))
  23.         await channel.send(embed=embed)
  24.         await asyncio.sleep(1800)
  25. bot.loop.create_task(textgenerator())
  26. bot.run('put your bot token here')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement