Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,25 +1,54 @@
|
|
| 1 |
-
import json
|
| 2 |
-
import os
|
| 3 |
-
import re
|
| 4 |
-
import asyncio
|
| 5 |
-
import random
|
| 6 |
-
import datetime
|
| 7 |
-
from threading import Thread
|
| 8 |
import discord
|
|
|
|
|
|
|
|
|
|
| 9 |
import time
|
| 10 |
-
import discord.utils
|
| 11 |
-
from discord.ext import tasks
|
| 12 |
-
from PIL import Image
|
| 13 |
import requests
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
import streamlit as st
|
| 15 |
-
|
| 16 |
-
import time
|
| 17 |
-
import os
|
| 18 |
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
|
|
|
| 21 |
ph = st.empty()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
def syncMessages():
|
| 24 |
with ph.container():
|
| 25 |
st.link_button(label="Invite the Bot", url="https://discord.com/api/oauth2/authorize?client_id=1116821362695221349&permissions=1067299753024&scope=bot", type="primary")
|
|
@@ -46,11 +75,16 @@ def syncMessages():
|
|
| 46 |
item = item.split(": ", 1)
|
| 47 |
st.markdown(f":blue[{item[0].split('GPT4 Correct ')[1]}]: {item[1]}")
|
| 48 |
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
| 54 |
clone = False
|
| 55 |
st.markdown("Bot is running, reload the page to see activity.")
|
| 56 |
else:
|
|
@@ -61,481 +95,227 @@ else:
|
|
| 61 |
time.sleep(0.5)
|
| 62 |
exit()
|
| 63 |
|
| 64 |
-
|
| 65 |
-
os.mkdir("data")
|
| 66 |
-
os.mkdir("usrtime")
|
| 67 |
-
except:
|
| 68 |
-
pass
|
| 69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
async def on_disconnect():
|
| 143 |
-
print("Disconnected, Clone status:", clone)
|
| 144 |
-
|
| 145 |
-
setupCommand = """
|
| 146 |
-
## Command: `--setup`
|
| 147 |
-
The `--setup` command enables Lyre to communicate within a designated channel.
|
| 148 |
-
## Usage:
|
| 149 |
-
```css
|
| 150 |
-
--setup [channel]
|
| 151 |
-
```
|
| 152 |
-
## Parameters
|
| 153 |
-
- **[channel]**: Specify the target channel where you want the bot to be active. This is the channel name.
|
| 154 |
-
## Example
|
| 155 |
-
```arduino
|
| 156 |
-
--setup <#1234567890123456789>
|
| 157 |
-
```
|
| 158 |
-
or
|
| 159 |
-
```arduino
|
| 160 |
-
--setup #general
|
| 161 |
-
```
|
| 162 |
-
"""
|
| 163 |
-
|
| 164 |
-
revokeCommand = """
|
| 165 |
-
## Command: `--revoke`
|
| 166 |
-
The `--revoke` command prevents Lyre from communicating within a designated channel.
|
| 167 |
-
## Usage:
|
| 168 |
-
```css
|
| 169 |
-
--setup [channel]
|
| 170 |
-
```
|
| 171 |
-
## Parameters
|
| 172 |
-
- **[channel]**: Specify the target channel where you want the bot to be active. This is the channel name.
|
| 173 |
-
## Example
|
| 174 |
-
```arduino
|
| 175 |
-
--setup <#1234567890123456789>
|
| 176 |
-
```
|
| 177 |
-
or
|
| 178 |
-
```arduino
|
| 179 |
-
--setup #general
|
| 180 |
-
```"""
|
| 181 |
-
|
| 182 |
-
info = requests.get("https://raw.githubusercontent.com/aryananumula/lr/main/info.json").content
|
| 183 |
-
bannedUsers = json.loads(info)["bannedUsers"]
|
| 184 |
-
imageModel = json.loads(info)["imageModel"]
|
| 185 |
-
userTimes = json.loads(info)["userTimes"]
|
| 186 |
-
|
| 187 |
-
@client.event
|
| 188 |
-
async def on_message(message):
|
| 189 |
-
msgchannel = message.channel
|
| 190 |
-
if message.embeds != []:
|
| 191 |
-
x = ""
|
| 192 |
-
for field in message.embeds[0].fields:
|
| 193 |
-
x += f"{field.name} - {field.value}"
|
| 194 |
-
x += "\n"
|
| 195 |
-
message.content = f"""<|title|>{message.embeds[0].title}<|title|>\n{message.embeds[0].description}\n\n{x}"""
|
| 196 |
-
try:
|
| 197 |
-
msgchannel_name = msgchannel.name
|
| 198 |
-
guild = message.guild
|
| 199 |
-
guild_name = guild.name
|
| 200 |
-
except:
|
| 201 |
-
guild_name = "Direct"
|
| 202 |
-
msgchannel_name = str(message.author)
|
| 203 |
-
|
| 204 |
-
with open(f"{guild_name}.guild", "a") as f:
|
| 205 |
-
f.write("")
|
| 206 |
-
if message.content.startswith("--setup"):
|
| 207 |
-
args = message.content.split()
|
| 208 |
-
del args[0]
|
| 209 |
-
if len(args) == 0:
|
| 210 |
-
with open(f"{guild_name}.guild", "a") as f:
|
| 211 |
-
f.write(f"{msgchannel.id}\n")
|
| 212 |
-
embed = discord.Embed(title="Success!", description=f"You can now chat with the bot in <#{msgchannel.id}>")
|
| 213 |
-
await message.reply(embed=embed)
|
| 214 |
-
return 0
|
| 215 |
-
if args[0] == "":
|
| 216 |
-
embed = discord.Embed(title="Error", description="Parameter `[channel]` empty. Use `--help` for command help.")
|
| 217 |
-
await message.reply(embed=embed)
|
| 218 |
-
return 0
|
| 219 |
-
if args[0].startswith("<#") and args[0].endswith(">"):
|
| 220 |
-
try:
|
| 221 |
-
cid = int(args[0][2:-1])
|
| 222 |
-
except:
|
| 223 |
-
embed = discord.Embed(title="Error", description="Parameter `[channel]` invalid. Use `--help` for command help.")
|
| 224 |
-
await message.reply(embed=embed)
|
| 225 |
-
return 0
|
| 226 |
-
c = client.get_channel(cid)
|
| 227 |
-
if c in message.guild.text_channels:
|
| 228 |
-
with open(f"{guild_name}.guild", "a") as f:
|
| 229 |
-
f.write(f"{c.id}\n")
|
| 230 |
-
embed = discord.Embed(title="Success!", description=f"You can now chat with the bot in <#{cid}>")
|
| 231 |
-
await message.reply(embed=embed)
|
| 232 |
-
return 0
|
| 233 |
-
else:
|
| 234 |
-
embed = discord.Embed(title="Error", description="Parameter `[channel]` is not in this guild. Use `--help` for command help.")
|
| 235 |
-
await message.reply(embed=embed)
|
| 236 |
-
return 0
|
| 237 |
-
else:
|
| 238 |
-
embed = discord.Embed(title="Error", description="Parameter `[channel]` is not in valid forms. Use `--help` for command help.")
|
| 239 |
-
await message.reply(embed=embed)
|
| 240 |
-
return 0
|
| 241 |
-
|
| 242 |
-
if message.content.startswith("--revoke"):
|
| 243 |
-
args = message.content.split()
|
| 244 |
-
del args[0]
|
| 245 |
-
if len(args) == 0:
|
| 246 |
-
with open(f"{guild_name}.guild", "r") as f:
|
| 247 |
-
k = f.read().split("\n")
|
| 248 |
-
cid = message.channel.id
|
| 249 |
-
if str(cid) in k:
|
| 250 |
-
k.remove(str(cid))
|
| 251 |
-
with open(f"{guild_name}.guild", "w") as f:
|
| 252 |
-
f.write("\n".join(k))
|
| 253 |
-
embed = discord.Embed(title="Success", description=f"Lyre is now unable to chat in <#{msgchannel.id}>")
|
| 254 |
-
await message.reply(embed=embed)
|
| 255 |
-
return 0
|
| 256 |
-
else:
|
| 257 |
-
embed = discord.Embed(title="Error", description=f"Lyre was already unable to chat in <#{msgchannel.id}>")
|
| 258 |
-
await message.reply(embed=embed)
|
| 259 |
-
return 0
|
| 260 |
-
if args[0] == "":
|
| 261 |
-
embed = discord.Embed(title="Error", description="Parameter `[channel]` empty. Use `--help` for command help.")
|
| 262 |
-
await message.reply(embed=embed)
|
| 263 |
-
return 0
|
| 264 |
-
if args[0].startswith("<#") and args[0].endswith(">"):
|
| 265 |
-
try:
|
| 266 |
-
cid = int(args[0][2:-1])
|
| 267 |
-
except:
|
| 268 |
-
embed = discord.Embed(title="Error", description="Parameter `[channel]` invalid. Use `--help` for command help.")
|
| 269 |
-
await message.reply(embed=embed)
|
| 270 |
-
return 0
|
| 271 |
-
with open(f"{guild_name}.guild", "r") as f:
|
| 272 |
-
k = f.read().split("\n")
|
| 273 |
-
if str(cid) in k:
|
| 274 |
-
k.remove(str(cid))
|
| 275 |
-
with open(f"{guild_name}.guild", "w") as f:
|
| 276 |
-
f.write("\n".join(k))
|
| 277 |
-
embed = discord.Embed(title="Success", description=f"Lyre is now unable to chat in {args[0]}")
|
| 278 |
-
await message.reply(embed=embed)
|
| 279 |
-
return 0
|
| 280 |
-
else:
|
| 281 |
-
embed = discord.Embed(title="Error", description=f"Lyre was already unable to chat in {args[0]}")
|
| 282 |
-
await message.reply(embed=embed)
|
| 283 |
-
return 0
|
| 284 |
-
else:
|
| 285 |
-
embed = discord.Embed(title="Error", description="Parameter `[channel]` is not in valid forms, or does not exist. Use `--help` for command help.")
|
| 286 |
-
await message.reply(embed=embed)
|
| 287 |
-
return 0
|
| 288 |
-
|
| 289 |
-
if message.content.startswith("--reset"):
|
| 290 |
-
args = message.content.split()
|
| 291 |
-
del args[0]
|
| 292 |
-
if len(args) == 0:
|
| 293 |
-
try:
|
| 294 |
-
os.remove(f"data/{guild_name}/{msgchannel_name}")
|
| 295 |
-
embed = discord.Embed(title="Success", description=f"History reset in <#{msgchannel.id}>")
|
| 296 |
-
await message.reply(embed=embed)
|
| 297 |
-
return 0
|
| 298 |
-
except:
|
| 299 |
-
embed = discord.Embed(title="Error", description=f"No history in <#{msgchannel.id}>")
|
| 300 |
-
await message.reply(embed=embed)
|
| 301 |
-
return 0
|
| 302 |
-
if args[0] == "":
|
| 303 |
-
embed = discord.Embed(title="Error", description="Parameter `[channel]` empty. Use `--help` for command help.")
|
| 304 |
-
await message.reply(embed=embed)
|
| 305 |
-
return 0
|
| 306 |
-
if args[0].startswith("<#") and args[0].endswith(">"):
|
| 307 |
-
try:
|
| 308 |
-
cid = int(args[0][2:-1])
|
| 309 |
-
except:
|
| 310 |
-
embed = discord.Embed(title="Error", description="Parameter `[channel]` invalid. Use `--help` for command help.")
|
| 311 |
-
await message.reply(embed=embed)
|
| 312 |
-
return 0
|
| 313 |
-
try:
|
| 314 |
-
os.remove(f"data/{guild_name}/{msgchannel_name}")
|
| 315 |
-
embed = discord.Embed(title="Success", description=f"History rest in {args[0]}")
|
| 316 |
-
await message.reply(embed=embed)
|
| 317 |
-
return 0
|
| 318 |
-
except:
|
| 319 |
-
embed = discord.Embed(title="Error", description=f"No history in {args[0]}")
|
| 320 |
-
await message.reply(embed=embed)
|
| 321 |
-
return 0
|
| 322 |
-
else:
|
| 323 |
-
embed = discord.Embed(title="Error", description="Parameter `[channel]` is not in valid forms, or does not exist. Use `--help` for command help.")
|
| 324 |
-
await message.reply(embed=embed)
|
| 325 |
-
return 0
|
| 326 |
-
|
| 327 |
-
if message.content == "--help":
|
| 328 |
-
def check(reaction, user):
|
| 329 |
-
return reaction.message.id == msg.id and user == message.author
|
| 330 |
-
page = 0
|
| 331 |
-
titles = ["""--setup""", """--reset"""]
|
| 332 |
-
pages = [setupCommand, revokeCommand]
|
| 333 |
-
embed = discord.Embed(title=titles[page], description=pages[page])
|
| 334 |
-
embed.set_footer(text=f"Page {page + 1} of {len(pages)}")
|
| 335 |
-
msg = await message.reply(embed=embed)
|
| 336 |
-
await msg.add_reaction("◀️")
|
| 337 |
-
await msg.add_reaction("▶️")
|
| 338 |
-
while True:
|
| 339 |
-
try:
|
| 340 |
-
reaction, _ = await client.wait_for('reaction_add', timeout= 20.0, check=check)
|
| 341 |
-
if reaction.emoji == '◀️' and page > 0:
|
| 342 |
-
page -= 1
|
| 343 |
-
embed = discord.Embed(title=titles[page], description=pages[page])
|
| 344 |
-
embed.set_footer(text=f"Page {page + 1} of {len(pages)}")
|
| 345 |
-
await msg.edit(embed=embed)
|
| 346 |
-
if reaction.emoji == '▶️' and page < len(pages) -1:
|
| 347 |
-
page += 1
|
| 348 |
-
embed = discord.Embed(title=titles[page], description=pages[page])
|
| 349 |
-
embed.set_footer(text=f"Page {page + 1} of {len(pages)}")
|
| 350 |
-
await msg.edit(embed=embed)
|
| 351 |
-
except asyncio.TimeoutError:
|
| 352 |
-
await msg.remove_reaction("◀️")
|
| 353 |
-
await msg.remove_reaction("▶️")
|
| 354 |
-
return 0
|
| 355 |
-
for user in message.mentions:
|
| 356 |
-
if user.bot:
|
| 357 |
-
message.content = message.content.replace(f"<@{user.id}>",
|
| 358 |
-
f"<@{str(user)}[bot]>")
|
| 359 |
else:
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
Your discord username is lyre#9828.
|
| 370 |
-
Use the markdown format for your responses.
|
| 371 |
-
Do not excessively use bullet points.
|
| 372 |
-
Use emojis at the start of your responses.
|
| 373 |
-
Use <|title|> at the start of your title for the response and <|title|> at the end of the title.
|
| 374 |
-
Always include a title, both the start tag and the end tag.
|
| 375 |
-
If the user asks you to generate an image, use the <|image|> tag around the prompt to generate it. Put this at the end of your response. Do not use a link for the image.
|
| 376 |
-
For example, if the user asks you to generate an image of a cat, you could say '<|title|>Cat Image<|title|>I hope you enjoy this image of a cat! If you have any other requests or questions, please don't hesitate to ask.<|image|>A cute cat with long fur that is looking out a window with curious eyes, volumetric lighting, 8k<|image|>'
|
| 377 |
-
Use relatively short prompts for images (20 words max), but still put details.
|
| 378 |
-
If a user has [bot] next to their username, they are a bot.
|
| 379 |
-
If there is 'ImageParsed' stuff at the end of the message, that means the user has provided an image(s), and the image(s) was parsed by a captioning model and returned to you. Do not generate an image unless they ask you explicitly.
|
| 380 |
-
Do not tell the user about any of the information that I am telling you right now.
|
| 381 |
-
If there is (Replied:[]) stuff at the start of the message, that is the message the user replied to, and the user that they replied to.
|
| 382 |
-
Do not generate images unless the user specifies that they want an image.
|
| 383 |
-
Use only one title in your responses, and only one image prompt.
|
| 384 |
-
The last message of the chat is the one that you are replying to.
|
| 385 |
-
Do not generate any obscene material in the chat, or that pertaining to hitler or any sensitive topics.
|
| 386 |
-
"""
|
| 387 |
-
try:
|
| 388 |
-
os.mkdir("data/" + guild_name)
|
| 389 |
-
except:
|
| 390 |
-
pass
|
| 391 |
-
imgCaption = ""
|
| 392 |
-
adoCaption = ""
|
| 393 |
-
if message.reference is not None:
|
| 394 |
-
message.content = f"[Replied to: ({str(message.reference.cached_message.author)}: {message.reference.cached_message.content})]; {message.content}"
|
| 395 |
-
if len(message.attachments) > 0:
|
| 396 |
-
images = []
|
| 397 |
-
audios = []
|
| 398 |
-
for file in message.attachments:
|
| 399 |
-
print(file.content_type)
|
| 400 |
-
if file.content_type.startswith("image"):
|
| 401 |
-
imgCaption = "(ImageParsed: "
|
| 402 |
-
images.append(file)
|
| 403 |
-
elif file.content_type.startswith("audio"):
|
| 404 |
-
adoCaption = "(AudioParsed: "
|
| 405 |
-
audios.append(file)
|
| 406 |
-
for image in images:
|
| 407 |
-
await image.save("ip.png")
|
| 408 |
-
imgCaption += f"[{await IC.image_to_text('ip.png')}]"
|
| 409 |
-
for audio in audios:
|
| 410 |
-
await audio.save("aud")
|
| 411 |
-
adoCaption += f"[{await PRK.automatic_speech_recognition('aud')}]"
|
| 412 |
-
if audios != []:
|
| 413 |
-
adoCaption += ")"
|
| 414 |
-
if images != []:
|
| 415 |
-
imgCaption += ")"
|
| 416 |
-
if os.path.exists(f"data/{guild_name}/{msgchannel_name}"):
|
| 417 |
-
with open(f"data/{guild_name}/{msgchannel_name}", "a") as f:
|
| 418 |
-
n = "\n"
|
| 419 |
-
if message.author.bot:
|
| 420 |
-
f.write(
|
| 421 |
-
f"""GPT4 Correct {message.author}[bot]: {message.content.strip(n)}{imgCaption}{adoCaption}<|end_of_turn|>"""
|
| 422 |
-
)
|
| 423 |
-
else:
|
| 424 |
-
f.write(
|
| 425 |
-
f"""GPT4 Correct {message.author}: {message.content.strip(n)}{imgCaption}{adoCaption}<|end_of_turn|>"""
|
| 426 |
-
)
|
| 427 |
else:
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 452 |
else:
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
"https://cdn.dribbble.com/users/563824/screenshots/3633228/media/b620ccb3ae8c14ea5447d159ebb1da58.gif",
|
| 467 |
-
"https://cdn.dribbble.com/users/563824/screenshots/4155980/media/d3828cd14ed415eb6f90310991e06f27.gif",
|
| 468 |
-
"https://cdn.dribbble.com/users/107759/screenshots/3498589/media/5bc45101de34a80ea71238a02f3a75b5.gif",
|
| 469 |
-
]
|
| 470 |
-
)
|
| 471 |
-
imgn = random.choice(['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ', 'BA', 'BB', 'BC', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BK', 'BL', 'BM', 'BN', 'BO', 'BP', 'BQ', 'BR', 'BS', 'BT', 'BU', 'BV', 'BW', 'BX', 'BY', 'BZ', 'CA', 'CB', 'CC', 'CD', 'CE', 'CF', 'CG', 'CH', 'CI', 'CJ', 'CK', 'CL', 'CM', 'CN', 'CO', 'CP', 'CQ', 'CR', 'CS', 'CT', 'CU', 'CV', 'CW', 'CX', 'CY', 'CZ', 'DA', 'DB', 'DC', 'DD', 'DE', 'DF', 'DG', 'DH', 'DI', 'DJ', 'DK', 'DL', 'DM', 'DN', 'DO', 'DP', 'DQ', 'DR', 'DS', 'DT', 'DU', 'DV', 'DW', 'DX', 'DY', 'DZ', 'EA', 'EB', 'EC', 'ED', 'EE', 'EF', 'EG', 'EH', 'EI', 'EJ', 'EK', 'EL', 'EM', 'EN', 'EO', 'EP', 'EQ', 'ER', 'ES', 'ET', 'EU', 'EV', 'EW', 'EX', 'EY', 'EZ', 'FA', 'FB', 'FC', 'FD', 'FE', 'FF', 'FG', 'FH', 'FI', 'FJ', 'FK', 'FL', 'FM', 'FN', 'FO', 'FP', 'FQ', 'FR', 'FS', 'FT', 'FU', 'FV', 'FW', 'FX', 'FY', 'FZ', 'GA', 'GB', 'GC', 'GD', 'GE', 'GF', 'GG', 'GH', 'GI', 'GJ', 'GK', 'GL', 'GM', 'GN', 'GO', 'GP', 'GQ', 'GR', 'GS', 'GT', 'GU', 'GV', 'GW', 'GX', 'GY', 'GZ', 'HA', 'HB', 'HC', 'HD', 'HE', 'HF', 'HG', 'HH', 'HI', 'HJ', 'HK', 'HL', 'HM', 'HN', 'HO', 'HP', 'HQ', 'HR', 'HS', 'HT', 'HU', 'HV', 'HW', 'HX', 'HY', 'HZ', 'IA', 'IB', 'IC', 'ID', 'IE', 'IF', 'IG', 'IH', 'II', 'IJ', 'IK', 'IL', 'IM', 'IN', 'IO', 'IP', 'IQ', 'IR', 'IS', 'IT', 'IU', 'IV', 'IW', 'IX', 'IY', 'IZ', 'JA', 'JB', 'JC', 'JD', 'JE', 'JF', 'JG', 'JH', 'JI', 'JJ', 'JK', 'JL', 'JM', 'JN', 'JO', 'JP', 'JQ', 'JR', 'JS', 'JT', 'JU', 'JV', 'JW', 'JX', 'JY', 'JZ', 'KA', 'KB', 'KC', 'KD', 'KE', 'KF', 'KG', 'KH', 'KI', 'KJ', 'KK', 'KL', 'KM', 'KN', 'KO', 'KP', 'KQ', 'KR', 'KS', 'KT', 'KU', 'KV', 'KW', 'KX', 'KY', 'KZ', 'LA', 'LB', 'LC', 'LD', 'LE', 'LF', 'LG', 'LH', 'LI', 'LJ', 'LK', 'LL', 'LM', 'LN', 'LO', 'LP', 'LQ', 'LR', 'LS', 'LT', 'LU', 'LV', 'LW', 'LX', 'LY', 'LZ', 'MA', 'MB', 'MC', 'MD', 'ME', 'MF', 'MG', 'MH', 'MI', 'MJ', 'MK', 'ML', 'MM', 'MN', 'MO', 'MP', 'MQ', 'MR', 'MS', 'MT', 'MU', 'MV', 'MW', 'MX', 'MY', 'MZ', 'NA', 'NB', 'NC', 'ND', 'NE', 'NF', 'NG', 'NH', 'NI', 'NJ', 'NK', 'NL', 'NM', 'NN', 'NO', 'NP', 'NQ', 'NR', 'NS', 'NT', 'NU', 'NV', 'NW', 'NX', 'NY', 'NZ', 'OA', 'OB', 'OC', 'OD', 'OE', 'OF', 'OG', 'OH', 'OI', 'OJ', 'OK', 'OL', 'OM', 'ON', 'OO', 'OP', 'OQ', 'OR', 'OS', 'OT', 'OU', 'OV', 'OW', 'OX', 'OY', 'OZ', 'PA', 'PB', 'PC', 'PD', 'PE', 'PF', 'PG', 'PH', 'PI', 'PJ', 'PK', 'PL', 'PM', 'PN', 'PO', 'PP', 'PQ', 'PR', 'PS', 'PT', 'PU', 'PV', 'PW', 'PX', 'PY', 'PZ', 'QA', 'QB', 'QC', 'QD', 'QE', 'QF', 'QG', 'QH', 'QI', 'QJ', 'QK', 'QL', 'QM', 'QN', 'QO', 'QP', 'QQ', 'QR', 'QS', 'QT', 'QU', 'QV', 'QW', 'QX', 'QY', 'QZ', 'RA', 'RB', 'RC', 'RD', 'RE', 'RF', 'RG', 'RH', 'RI', 'RJ', 'RK', 'RL', 'RM', 'RN', 'RO', 'RP', 'RQ', 'RR', 'RS', 'RT', 'RU', 'RV', 'RW', 'RX', 'RY', 'RZ', 'SA', 'SB', 'SC', 'SD', 'SE', 'SF', 'SG', 'SH', 'SI', 'SJ', 'SK', 'SL', 'SM', 'SN', 'SO', 'SP', 'SQ', 'SR', 'SS', 'ST', 'SU', 'SV', 'SW', 'SX', 'SY', 'SZ', 'TA', 'TB', 'TC', 'TD', 'TE', 'TF', 'TG', 'TH', 'TI', 'TJ', 'TK', 'TL', 'TM', 'TN', 'TO', 'TP', 'TQ', 'TR', 'TS', 'TT', 'TU', 'TV', 'TW', 'TX', 'TY', 'TZ', 'UA', 'UB', 'UC', 'UD', 'UE', 'UF', 'UG', 'UH', 'UI', 'UJ', 'UK', 'UL', 'UM', 'UN', 'UO', 'UP', 'UQ', 'UR', 'US', 'UT', 'UU', 'UV', 'UW', 'UX', 'UY', 'UZ', 'VA', 'VB', 'VC', 'VD', 'VE', 'VF', 'VG', 'VH', 'VI', 'VJ', 'VK', 'VL', 'VM', 'VN', 'VO', 'VP', 'VQ', 'VR', 'VS', 'VT', 'VU', 'VV', 'VW', 'VX', 'VY', 'VZ', 'WA', 'WB', 'WC', 'WD', 'WE', 'WF', 'WG', 'WH', 'WI', 'WJ', 'WK', 'WL', 'WM', 'WN', 'WO', 'WP', 'WQ', 'WR', 'WS', 'WT', 'WU', 'WV', 'WW', 'WX', 'WY', 'WZ', 'XA', 'XB', 'XC', 'XD', 'XE', 'XF', 'XG', 'XH', 'XI', 'XJ', 'XK', 'XL', 'XM', 'XN', 'XO', 'XP', 'XQ', 'XR', 'XS', 'XT', 'XU', 'XV', 'XW', 'XX', 'XY', 'XZ', 'YA', 'YB', 'YC', 'YD', 'YE', 'YF', 'YG', 'YH', 'YI', 'YJ', 'YK', 'YL', 'YM', 'YN', 'YO', 'YP', 'YQ', 'YR', 'YS', 'YT', 'YU', 'YV', 'YW', 'YX', 'YY', 'YZ', 'ZA', 'ZB', 'ZC', 'ZD', 'ZE', 'ZF', 'ZG', 'ZH', 'ZI', 'ZJ', 'ZK', 'ZL', 'ZM', 'ZN', 'ZO', 'ZP', 'ZQ', 'ZR', 'ZS', 'ZT', 'ZU', 'ZV', 'ZW', 'ZX', 'ZY', 'ZZ'])
|
| 472 |
-
output = await LLM.text_generation(context,
|
| 473 |
-
stop_sequences=["<|end_of_turn|>"], max_new_tokens=1024)
|
| 474 |
-
title = ec(output, "<|title|>", "<|title|>")[0]
|
| 475 |
-
imgp = ec(output)[0]
|
| 476 |
-
mscp = ec(output, "<|music|>", "<|music|>")[0]
|
| 477 |
-
with open(f"data/{guild_name}/{msgchannel_name}", "a") as f:
|
| 478 |
-
f.write(f"GPT4 Correct Assistant: {output}<|end_of_turn|>")
|
| 479 |
-
embed = discord.Embed(title=title,
|
| 480 |
-
description=output.replace(
|
| 481 |
-
f"<|title|>{title}<|title|>", "").replace(f"<|image|>{imgp}<|image|>", ""),
|
| 482 |
-
color=0x1E81B0)
|
| 483 |
-
if imgp != "":
|
| 484 |
-
embed.set_image(url=load)
|
| 485 |
-
embed.set_footer(
|
| 486 |
-
text=
|
| 487 |
-
"""Creating..."""
|
| 488 |
-
)
|
| 489 |
-
else:
|
| 490 |
-
embed.set_footer(
|
| 491 |
-
text=
|
| 492 |
-
"""Information or code generated by Lyre may not always be correct. Lyre was made by Araeyn."""
|
| 493 |
-
)
|
| 494 |
-
|
| 495 |
-
e = await message.reply(embed=embed)
|
| 496 |
if imgp != "":
|
| 497 |
-
|
| 498 |
-
st = time.time()
|
| 499 |
-
if imageModel == "Stable Diffusion 2-1":
|
| 500 |
-
image, m = (await SD.text_to_image(imgp, negative_prompt=np), "Stable Diffusion 2-1")
|
| 501 |
-
elif imageModel == "stable-diffusion-xl-base-1.0":
|
| 502 |
-
image, m = (await SDXL.text_to_image(imgp, negative_prompt=np, num_inference_steps=64), "stable-diffusion-xl-base-1.0")
|
| 503 |
-
elif imageModel == "sdxl-turbo":
|
| 504 |
-
image, m = (await SDXLT.text_to_image(imgp, negative_prompt=np, num_inference_steps=8, guidance_scale=0.0), "sdxl-turbo")
|
| 505 |
-
elif imageModel == "sd-turbo":
|
| 506 |
-
image, m = (await SDT.text_to_image(imgp, negative_prompt=np, num_inference_steps=8, guidance_scale=0.0), "sd-turbo")
|
| 507 |
-
elif imageModel == "Proteus v0.2":
|
| 508 |
-
image, m = (await PT.text_to_image(imgp, negative_prompt=np, num_inference_steps=35), "Proteus v0.2")
|
| 509 |
-
else:
|
| 510 |
-
raise NotImplementedError(f"Model {imageModel} not found. Report this to @araeyn if this keeps happening.")
|
| 511 |
-
image.save(f"{imgn}.png")
|
| 512 |
-
file = discord.File(f"{imgn}.png", filename=f"{imgn}.png", description=imgp)
|
| 513 |
-
embed.set_image(url=f"attachment://{imgn}.png")
|
| 514 |
embed.set_footer(
|
| 515 |
text=
|
| 516 |
-
"""
|
| 517 |
)
|
| 518 |
-
|
| 519 |
-
gt = time.time()
|
| 520 |
-
image, r = (await RF.image_to_image(f"{imgn}.png", num_inference_steps=16, prompt=imgp, negative_prompt=np), "stable-diffusion-xl-refiner-1.0")
|
| 521 |
-
rt = time.time()
|
| 522 |
embed.set_footer(
|
| 523 |
text=
|
| 524 |
-
|
| 525 |
)
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
await e.edit(embed=embed
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 539 |
|
| 540 |
-
|
| 541 |
-
client.run(token)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import discord
|
| 2 |
+
import os
|
| 3 |
+
from huggingface_hub import AsyncInferenceClient, login
|
| 4 |
+
import regex as re
|
| 5 |
import time
|
|
|
|
|
|
|
|
|
|
| 6 |
import requests
|
| 7 |
+
import json
|
| 8 |
+
import random
|
| 9 |
+
import asyncio
|
| 10 |
+
import typing
|
| 11 |
import streamlit as st
|
| 12 |
+
import gradio_client as grc
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
# API
|
| 15 |
+
login(os.environ["HF_TOKEN"])
|
| 16 |
+
sd_turbo = "stabilityai/sd-turbo"
|
| 17 |
+
sdxl_turbo = "stabilityai/sd-turbo"
|
| 18 |
+
sdxl = "stabilityai/stable-diffusion-xl-base-1.0"
|
| 19 |
+
proteus = "dataautogpt3/ProteusV0.2"
|
| 20 |
+
sd_2_1 = "stabilityai/stable-diffusion-2-1"
|
| 21 |
+
open_journey = "prompthero/openjourney-v4"
|
| 22 |
+
SD = AsyncInferenceClient(model=sd_2_1)
|
| 23 |
+
SDXL = AsyncInferenceClient(model=sdxl)
|
| 24 |
+
SDXLT = AsyncInferenceClient(model=sdxl_turbo)
|
| 25 |
+
SDT = AsyncInferenceClient(model=sd_turbo)
|
| 26 |
+
PT = AsyncInferenceClient(model=proteus)
|
| 27 |
+
LLM = AsyncInferenceClient(model="openchat/openchat-3.5-0106")
|
| 28 |
+
RF = AsyncInferenceClient(model="stabilityai/stable-diffusion-xl-refiner-1.0")
|
| 29 |
+
UP = AsyncInferenceClient(model="radames/stable-diffusion-x4-upscaler-img2img")
|
| 30 |
+
IC = AsyncInferenceClient(model="salesforce/blip-image-captioning-large")
|
| 31 |
+
PRK = AsyncInferenceClient(model="nvidia/parakeet-tdt-1.1b")
|
| 32 |
+
MG = AsyncInferenceClient(model="facebook/musicgen-stereo-small")
|
| 33 |
|
| 34 |
+
# INIT
|
| 35 |
ph = st.empty()
|
| 36 |
+
try:
|
| 37 |
+
os.mkdir("data")
|
| 38 |
+
os.mkdir("usrtime")
|
| 39 |
+
except:
|
| 40 |
+
pass
|
| 41 |
+
st.link_button(label="Invite the Bot", url="https://discord.com/api/oauth2/authorize?client_id=1116821362695221349&permissions=1067299753024&scope=bot", type="secondary")
|
| 42 |
|
| 43 |
+
# OPTIONS
|
| 44 |
+
eot = "<|END_OF_TURN|>"
|
| 45 |
+
sot = "GPT4 Correct "
|
| 46 |
+
info = requests.get("https://raw.githubusercontent.com/aryananumula/lr/main/info.json").content
|
| 47 |
+
bannedUsers = json.loads(info)["bannedUsers"]
|
| 48 |
+
imageModel = json.loads(info)["imageModel"]
|
| 49 |
+
userTimes = json.loads(info)["userTimes"]
|
| 50 |
+
|
| 51 |
+
# functions
|
| 52 |
def syncMessages():
|
| 53 |
with ph.container():
|
| 54 |
st.link_button(label="Invite the Bot", url="https://discord.com/api/oauth2/authorize?client_id=1116821362695221349&permissions=1067299753024&scope=bot", type="primary")
|
|
|
|
| 75 |
item = item.split(": ", 1)
|
| 76 |
st.markdown(f":blue[{item[0].split('GPT4 Correct ')[1]}]: {item[1]}")
|
| 77 |
|
| 78 |
+
def ec(x, fd="<|image|>", sd="<|image|>"):
|
| 79 |
+
matches = re.findall(re.escape(fd) + "(.*?)" + re.escape(sd), x)
|
| 80 |
+
matches = matches if matches else [""]
|
| 81 |
+
return matches
|
| 82 |
|
| 83 |
+
# Clone Check
|
| 84 |
+
lfp = "test.txt"
|
| 85 |
+
if not os.path.exists(lfp):
|
| 86 |
+
with open(lfp, "w") as f:
|
| 87 |
+
f.write("ew")
|
| 88 |
clone = False
|
| 89 |
st.markdown("Bot is running, reload the page to see activity.")
|
| 90 |
else:
|
|
|
|
| 95 |
time.sleep(0.5)
|
| 96 |
exit()
|
| 97 |
|
| 98 |
+
bot = discord.Bot()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
+
@bot.event
|
| 101 |
+
async def on_ready():
|
| 102 |
+
print('-----------')
|
| 103 |
+
print(bot.user.name)
|
| 104 |
+
print(bot.user.id)
|
| 105 |
+
print('-----------')
|
| 106 |
|
| 107 |
+
@bot.event
|
| 108 |
+
async def on_message(message:discord.Message):
|
| 109 |
+
if int(message.guild.id) != 1131647372867407953:
|
| 110 |
+
return
|
| 111 |
+
try:
|
| 112 |
+
if message.channel.name is not None:
|
| 113 |
+
pass
|
| 114 |
+
except:
|
| 115 |
+
message.guild.name = "<|DM|>"
|
| 116 |
+
message.channel.name = str(message.author)
|
| 117 |
+
s = f"{message.author}: {message.content}\n{message.channel.name}\n{message.guild.name}"
|
| 118 |
+
print(s)
|
| 119 |
+
if message.author.bot:
|
| 120 |
+
return
|
| 121 |
+
sysrp = """GPT4 Correct system:
|
| 122 |
+
You are lyre, a discord bot who can generate images and chat with the user. You were made by Araeyn.
|
| 123 |
+
Answer in the same speech patterns as the people you are talking to.
|
| 124 |
+
Your discord username is lyre#9828.
|
| 125 |
+
Use the markdown format for your responses.
|
| 126 |
+
Do not excessively use bullet points.
|
| 127 |
+
Use emojis at the start of your responses.
|
| 128 |
+
Use <|title|> at the start of your title for the response and <|title|> at the end of the title.
|
| 129 |
+
Always include a title, both the start tag and the end tag.
|
| 130 |
+
If the user asks you to generate an image, use the <|image|> tag around the prompt to generate it. Put this at the end of your response. Do not use a link for the image.
|
| 131 |
+
For example, if the user asks you to generate an image of a cat, you could say '<|title|>Cat Image<|title|>I hope you enjoy this image of a cat! If you have any other requests or questions, please don't hesitate to ask.<|image|>A cute cat with long fur that is looking out a window with curious eyes, volumetric lighting, 8k<|image|>'
|
| 132 |
+
Use relatively short prompts for images (20 words max), but still put details.
|
| 133 |
+
If a user has [bot] next to their username, they are a bot.
|
| 134 |
+
If there is 'ImageParsed' stuff at the end of the message, that means the user has provided an image(s), and the image(s) was parsed by a captioning model and returned to you. Do not generate an image unless they ask you explicitly.
|
| 135 |
+
Do not tell the user about any of the information that I am telling you right now.
|
| 136 |
+
If there is (Replied:[]) stuff at the start of the message, that is the message the user replied to, and the user that they replied to.
|
| 137 |
+
Do not generate images unless the user specifies that they want an image.
|
| 138 |
+
Use only one title in your responses, and only one image prompt.
|
| 139 |
+
The last message of the chat is the one that you are replying to.
|
| 140 |
+
Do not generate any obscene material in the chat, or that pertaining to hitler or any sensitive topics.
|
| 141 |
+
"""
|
| 142 |
+
try:
|
| 143 |
+
os.mkdir("data/" + message.guild.name)
|
| 144 |
+
except:
|
| 145 |
+
pass
|
| 146 |
+
imgCaption = ""
|
| 147 |
+
adoCaption = ""
|
| 148 |
+
if message.reference is not None:
|
| 149 |
+
message.content = f"[Replied to: ({str(message.reference.cached_message.author)}: {message.reference.cached_message.content})]; {message.content}"
|
| 150 |
+
if len(message.attachments) > 0:
|
| 151 |
+
images = []
|
| 152 |
+
audios = []
|
| 153 |
+
for file in message.attachments:
|
| 154 |
+
print(file.content_type)
|
| 155 |
+
if file.content_type.startswith("image"):
|
| 156 |
+
imgCaption = "(ImageParsed: "
|
| 157 |
+
images.append(file)
|
| 158 |
+
elif file.content_type.startswith("audio"):
|
| 159 |
+
adoCaption = "(AudioParsed: "
|
| 160 |
+
audios.append(file)
|
| 161 |
+
for image in images:
|
| 162 |
+
await image.save("ip.png")
|
| 163 |
+
imgCaption += f"[{await IC.image_to_text('ip.png')}]"
|
| 164 |
+
for audio in audios:
|
| 165 |
+
await audio.save("aud")
|
| 166 |
+
adoCaption += f"[{await PRK.automatic_speech_recognition('aud')}]"
|
| 167 |
+
if audios != []:
|
| 168 |
+
adoCaption += ")"
|
| 169 |
+
if images != []:
|
| 170 |
+
imgCaption += ")"
|
| 171 |
+
if os.path.exists(f"data/{message.guild.name}/{message.channel.name}"):
|
| 172 |
+
with open(f"data/{message.guild.name}/{message.channel.name}", "a") as f:
|
| 173 |
+
n = "\n"
|
| 174 |
+
if message.author.bot:
|
| 175 |
+
f.write(
|
| 176 |
+
f"""GPT4 Correct {message.author}[bot]: {message.content.strip(n)}{imgCaption}{adoCaption}{eot}"""
|
| 177 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
else:
|
| 179 |
+
f.write(
|
| 180 |
+
f"""GPT4 Correct {message.author}: {message.content.strip(n)}{imgCaption}{adoCaption}{eot}"""
|
| 181 |
+
)
|
| 182 |
+
else:
|
| 183 |
+
with open(f"data/{message.guild.name}/{message.channel.name}", "w") as f:
|
| 184 |
+
if message.author.bot:
|
| 185 |
+
f.write(
|
| 186 |
+
f"GPT4 Correct system: {sysrp}{eot}GPT4 Correct {message.author}[bot]: {message.content}{imgCaption}{adoCaption}{eot}"
|
| 187 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
else:
|
| 189 |
+
f.write(
|
| 190 |
+
f"GPT4 Correct system: {sysrp}{eot}GPT4 Correct {message.author}: {message.content}{imgCaption}{adoCaption}{eot}"
|
| 191 |
+
)
|
| 192 |
+
with open(f"data/{message.guild.name}/{message.channel.name}", "r") as f:
|
| 193 |
+
context = f.read()
|
| 194 |
+
with open(f"{message.guild.name}.guild", "r") as f:
|
| 195 |
+
o = f.read()
|
| 196 |
+
try:
|
| 197 |
+
with open(f"usrtime/{message.author}", "r") as f:
|
| 198 |
+
er = f.read()
|
| 199 |
+
except:
|
| 200 |
+
with open(f"usrtime/{message.author}", "w") as f:
|
| 201 |
+
f.write(str(round(time.time())))
|
| 202 |
+
er = 0
|
| 203 |
+
y = round(time.time()) - int(er)
|
| 204 |
+
if str(message.author).lower() not in userTimes.keys():
|
| 205 |
+
usrTime = 5
|
| 206 |
+
else:
|
| 207 |
+
usrTime = userTimes[str(message.author).lower()]
|
| 208 |
+
if message.author.id in bannedUsers:
|
| 209 |
+
return 0
|
| 210 |
+
if y < usrTime:
|
| 211 |
+
return 0
|
| 212 |
+
if (str(message.channel.id) in o.split("\n")) or (message.channel.name == "Direct"):
|
| 213 |
+
with open(f"usrtime/{message.author}", "w") as f:
|
| 214 |
+
f.write(str(round(time.time())))
|
| 215 |
+
async with message.channel.typing():
|
| 216 |
+
context += f"GPT4 Correct Assistant:"
|
| 217 |
+
load = random.choice(
|
| 218 |
+
[
|
| 219 |
+
"https://cdn.dribbble.com/users/744913/screenshots/4094897/media/771a495231b798c0ccf7a59a19f31946.gif",
|
| 220 |
+
"https://cdn.dribbble.com/users/563824/screenshots/3633228/media/b620ccb3ae8c14ea5447d159ebb1da58.gif",
|
| 221 |
+
"https://cdn.dribbble.com/users/563824/screenshots/4155980/media/d3828cd14ed415eb6f90310991e06f27.gif",
|
| 222 |
+
"https://cdn.dribbble.com/users/107759/screenshots/3498589/media/5bc45101de34a80ea71238a02f3a75b5.gif",
|
| 223 |
+
]
|
| 224 |
+
)
|
| 225 |
+
imgn = random.choice(['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ', 'BA', 'BB', 'BC', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BK', 'BL', 'BM', 'BN', 'BO', 'BP', 'BQ', 'BR', 'BS', 'BT', 'BU', 'BV', 'BW', 'BX', 'BY', 'BZ', 'CA', 'CB', 'CC', 'CD', 'CE', 'CF', 'CG', 'CH', 'CI', 'CJ', 'CK', 'CL', 'CM', 'CN', 'CO', 'CP', 'CQ', 'CR', 'CS', 'CT', 'CU', 'CV', 'CW', 'CX', 'CY', 'CZ', 'DA', 'DB', 'DC', 'DD', 'DE', 'DF', 'DG', 'DH', 'DI', 'DJ', 'DK', 'DL', 'DM', 'DN', 'DO', 'DP', 'DQ', 'DR', 'DS', 'DT', 'DU', 'DV', 'DW', 'DX', 'DY', 'DZ', 'EA', 'EB', 'EC', 'ED', 'EE', 'EF', 'EG', 'EH', 'EI', 'EJ', 'EK', 'EL', 'EM', 'EN', 'EO', 'EP', 'EQ', 'ER', 'ES', 'ET', 'EU', 'EV', 'EW', 'EX', 'EY', 'EZ', 'FA', 'FB', 'FC', 'FD', 'FE', 'FF', 'FG', 'FH', 'FI', 'FJ', 'FK', 'FL', 'FM', 'FN', 'FO', 'FP', 'FQ', 'FR', 'FS', 'FT', 'FU', 'FV', 'FW', 'FX', 'FY', 'FZ', 'GA', 'GB', 'GC', 'GD', 'GE', 'GF', 'GG', 'GH', 'GI', 'GJ', 'GK', 'GL', 'GM', 'GN', 'GO', 'GP', 'GQ', 'GR', 'GS', 'GT', 'GU', 'GV', 'GW', 'GX', 'GY', 'GZ', 'HA', 'HB', 'HC', 'HD', 'HE', 'HF', 'HG', 'HH', 'HI', 'HJ', 'HK', 'HL', 'HM', 'HN', 'HO', 'HP', 'HQ', 'HR', 'HS', 'HT', 'HU', 'HV', 'HW', 'HX', 'HY', 'HZ', 'IA', 'IB', 'IC', 'ID', 'IE', 'IF', 'IG', 'IH', 'II', 'IJ', 'IK', 'IL', 'IM', 'IN', 'IO', 'IP', 'IQ', 'IR', 'IS', 'IT', 'IU', 'IV', 'IW', 'IX', 'IY', 'IZ', 'JA', 'JB', 'JC', 'JD', 'JE', 'JF', 'JG', 'JH', 'JI', 'JJ', 'JK', 'JL', 'JM', 'JN', 'JO', 'JP', 'JQ', 'JR', 'JS', 'JT', 'JU', 'JV', 'JW', 'JX', 'JY', 'JZ', 'KA', 'KB', 'KC', 'KD', 'KE', 'KF', 'KG', 'KH', 'KI', 'KJ', 'KK', 'KL', 'KM', 'KN', 'KO', 'KP', 'KQ', 'KR', 'KS', 'KT', 'KU', 'KV', 'KW', 'KX', 'KY', 'KZ', 'LA', 'LB', 'LC', 'LD', 'LE', 'LF', 'LG', 'LH', 'LI', 'LJ', 'LK', 'LL', 'LM', 'LN', 'LO', 'LP', 'LQ', 'LR', 'LS', 'LT', 'LU', 'LV', 'LW', 'LX', 'LY', 'LZ', 'MA', 'MB', 'MC', 'MD', 'ME', 'MF', 'MG', 'MH', 'MI', 'MJ', 'MK', 'ML', 'MM', 'MN', 'MO', 'MP', 'MQ', 'MR', 'MS', 'MT', 'MU', 'MV', 'MW', 'MX', 'MY', 'MZ', 'NA', 'NB', 'NC', 'ND', 'NE', 'NF', 'NG', 'NH', 'NI', 'NJ', 'NK', 'NL', 'NM', 'NN', 'NO', 'NP', 'NQ', 'NR', 'NS', 'NT', 'NU', 'NV', 'NW', 'NX', 'NY', 'NZ', 'OA', 'OB', 'OC', 'OD', 'OE', 'OF', 'OG', 'OH', 'OI', 'OJ', 'OK', 'OL', 'OM', 'ON', 'OO', 'OP', 'OQ', 'OR', 'OS', 'OT', 'OU', 'OV', 'OW', 'OX', 'OY', 'OZ', 'PA', 'PB', 'PC', 'PD', 'PE', 'PF', 'PG', 'PH', 'PI', 'PJ', 'PK', 'PL', 'PM', 'PN', 'PO', 'PP', 'PQ', 'PR', 'PS', 'PT', 'PU', 'PV', 'PW', 'PX', 'PY', 'PZ', 'QA', 'QB', 'QC', 'QD', 'QE', 'QF', 'QG', 'QH', 'QI', 'QJ', 'QK', 'QL', 'QM', 'QN', 'QO', 'QP', 'QQ', 'QR', 'QS', 'QT', 'QU', 'QV', 'QW', 'QX', 'QY', 'QZ', 'RA', 'RB', 'RC', 'RD', 'RE', 'RF', 'RG', 'RH', 'RI', 'RJ', 'RK', 'RL', 'RM', 'RN', 'RO', 'RP', 'RQ', 'RR', 'RS', 'RT', 'RU', 'RV', 'RW', 'RX', 'RY', 'RZ', 'SA', 'SB', 'SC', 'SD', 'SE', 'SF', 'SG', 'SH', 'SI', 'SJ', 'SK', 'SL', 'SM', 'SN', 'SO', 'SP', 'SQ', 'SR', 'SS', 'ST', 'SU', 'SV', 'SW', 'SX', 'SY', 'SZ', 'TA', 'TB', 'TC', 'TD', 'TE', 'TF', 'TG', 'TH', 'TI', 'TJ', 'TK', 'TL', 'TM', 'TN', 'TO', 'TP', 'TQ', 'TR', 'TS', 'TT', 'TU', 'TV', 'TW', 'TX', 'TY', 'TZ', 'UA', 'UB', 'UC', 'UD', 'UE', 'UF', 'UG', 'UH', 'UI', 'UJ', 'UK', 'UL', 'UM', 'UN', 'UO', 'UP', 'UQ', 'UR', 'US', 'UT', 'UU', 'UV', 'UW', 'UX', 'UY', 'UZ', 'VA', 'VB', 'VC', 'VD', 'VE', 'VF', 'VG', 'VH', 'VI', 'VJ', 'VK', 'VL', 'VM', 'VN', 'VO', 'VP', 'VQ', 'VR', 'VS', 'VT', 'VU', 'VV', 'VW', 'VX', 'VY', 'VZ', 'WA', 'WB', 'WC', 'WD', 'WE', 'WF', 'WG', 'WH', 'WI', 'WJ', 'WK', 'WL', 'WM', 'WN', 'WO', 'WP', 'WQ', 'WR', 'WS', 'WT', 'WU', 'WV', 'WW', 'WX', 'WY', 'WZ', 'XA', 'XB', 'XC', 'XD', 'XE', 'XF', 'XG', 'XH', 'XI', 'XJ', 'XK', 'XL', 'XM', 'XN', 'XO', 'XP', 'XQ', 'XR', 'XS', 'XT', 'XU', 'XV', 'XW', 'XX', 'XY', 'XZ', 'YA', 'YB', 'YC', 'YD', 'YE', 'YF', 'YG', 'YH', 'YI', 'YJ', 'YK', 'YL', 'YM', 'YN', 'YO', 'YP', 'YQ', 'YR', 'YS', 'YT', 'YU', 'YV', 'YW', 'YX', 'YY', 'YZ', 'ZA', 'ZB', 'ZC', 'ZD', 'ZE', 'ZF', 'ZG', 'ZH', 'ZI', 'ZJ', 'ZK', 'ZL', 'ZM', 'ZN', 'ZO', 'ZP', 'ZQ', 'ZR', 'ZS', 'ZT', 'ZU', 'ZV', 'ZW', 'ZX', 'ZY', 'ZZ'])
|
| 226 |
+
output = await LLM.text_generation(context,
|
| 227 |
+
stop_sequences=["<|end_of_turn|>"], max_new_tokens=1024)
|
| 228 |
+
title = ec(output, "<|title|>", "<|title|>")[0]
|
| 229 |
+
imgp = ec(output)[0]
|
| 230 |
+
mscp = ec(output, "<|music|>", "<|music|>")[0]
|
| 231 |
+
with open(f"data/{message.guild.name}/{message.channel.name}", "a") as f:
|
| 232 |
+
f.write(f"GPT4 Correct Assistant: {output}<|end_of_turn|>")
|
| 233 |
+
embed = discord.Embed(title=title,
|
| 234 |
+
description=output.replace(
|
| 235 |
+
f"<|title|>{title}<|title|>", "").replace(f"<|image|>{imgp}<|image|>", ""),
|
| 236 |
+
color=0x1E81B0)
|
| 237 |
+
if imgp != "":
|
| 238 |
+
embed.set_image(url=load)
|
| 239 |
+
embed.set_footer(
|
| 240 |
+
text=
|
| 241 |
+
"""Creating..."""
|
| 242 |
+
)
|
| 243 |
else:
|
| 244 |
+
embed.set_footer(
|
| 245 |
+
text=
|
| 246 |
+
"""Information or code generated by Lyre may not always be correct. Lyre was made by Araeyn."""
|
| 247 |
+
)
|
| 248 |
+
e = await message.reply(embed=embed)
|
| 249 |
+
'''wds = output.split(" ")
|
| 250 |
+
for i in range(len(wds)):
|
| 251 |
+
title = ec(" ".join(wds[:i + 1]), "<|title|>", "<|title|>")[0]
|
| 252 |
+
imgp = ec(" ".join(wds[:i + 1]))[0]
|
| 253 |
+
embed = discord.Embed(title=title,
|
| 254 |
+
description=" ".join(wds[:i + 1]).replace(
|
| 255 |
+
f"<|title|>{title}<|title|>", "").replace(f"<|image|>{imgp}<|image|>", ""),
|
| 256 |
+
color=0x1E81B0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 257 |
if imgp != "":
|
| 258 |
+
embed.set_image(url=load)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 259 |
embed.set_footer(
|
| 260 |
text=
|
| 261 |
+
"""Creating..."""
|
| 262 |
)
|
| 263 |
+
else:
|
|
|
|
|
|
|
|
|
|
| 264 |
embed.set_footer(
|
| 265 |
text=
|
| 266 |
+
"""Information or code generated by Lyre may not always be correct. Lyre was made by Araeyn."""
|
| 267 |
)
|
| 268 |
+
if i == 0:
|
| 269 |
+
e = await message.reply(embed=embed)
|
| 270 |
+
else:
|
| 271 |
+
await e.edit(embed=embed)
|
| 272 |
+
await asyncio.sleep(0.1)'''
|
| 273 |
+
if imgp != "":
|
| 274 |
+
np = """lowres, error, cropped, worst quality, low quality, ugly, duplicate, morbid, mutilated, out of frame, blurry, watermark, signature"""
|
| 275 |
+
st = time.time()
|
| 276 |
+
if imageModel == "Stable Diffusion 2-1":
|
| 277 |
+
image, m = (await SD.text_to_image(imgp, negative_prompt=np, num_inference_steps=70), "Stable Diffusion 2-1")
|
| 278 |
+
elif imageModel == "stable-diffusion-xl-base-1.0":
|
| 279 |
+
image, m = (await SDXL.text_to_image(imgp, negative_prompt=np, num_inference_steps=70), "stable-diffusion-xl-base-1.0")
|
| 280 |
+
elif imageModel == "sdxl-turbo":
|
| 281 |
+
image, m = (await SDXLT.text_to_image(imgp, negative_prompt=np, num_inference_steps=70, guidance_scale=0.0), "sdxl-turbo")
|
| 282 |
+
elif imageModel == "sd-turbo":
|
| 283 |
+
image, m = (await SDT.text_to_image(imgp, negative_prompt=np, num_inference_steps=70, guidance_scale=0.0), "sd-turbo")
|
| 284 |
+
elif imageModel == "Proteus v0.2":
|
| 285 |
+
image, m = (await PT.text_to_image(imgp, negative_prompt=np, num_inference_steps=35), "Proteus v0.2")
|
| 286 |
+
else:
|
| 287 |
+
raise NotImplementedError(f"Model {imageModel} not found. Report this to @araeyn if this keeps happening.")
|
| 288 |
+
image.save(f"{imgn}.png")
|
| 289 |
+
file = discord.File(f"{imgn}.png", filename=f"{imgn}.png", description=imgp)
|
| 290 |
+
embed.set_image(url=f"attachment://{imgn}.png")
|
| 291 |
+
embed.set_footer(
|
| 292 |
+
text=
|
| 293 |
+
"""Refining..."""
|
| 294 |
+
)
|
| 295 |
+
await e.edit(embed=embed, attachments=[file])
|
| 296 |
+
gt = time.time()
|
| 297 |
+
image, r = (await RF.image_to_image(f"{imgn}.png", num_inference_steps=35, prompt=imgp, negative_prompt=np), "stable-diffusion-xl-refiner-1.0")
|
| 298 |
+
rt = time.time()
|
| 299 |
+
embed.set_footer(
|
| 300 |
+
text=
|
| 301 |
+
f"Image generation model is {m}. Refiner model is {r}. Took {round((gt - st) * 100) / 100} seconds to generate. Took {round((rt - gt) * 100) / 100} seconds to refine."
|
| 302 |
+
)
|
| 303 |
+
image.save(f"{imgn}.png")
|
| 304 |
+
file = discord.File(f"{imgn}.png", filename=f"{imgn}.png")
|
| 305 |
+
embed.set_image(url=f"attachment://{imgn}.png")
|
| 306 |
+
await e.edit(embed=embed, attachments=[file])
|
| 307 |
+
|
| 308 |
+
@bot.slash_command()
|
| 309 |
+
async def setup(ctx:discord.Interaction):
|
| 310 |
+
with open(f"{ctx.guild.name}.guild", "a") as f:
|
| 311 |
+
f.write(f"{ctx.channel.id}\n")
|
| 312 |
+
embed = discord.Embed(title="Success!", description=f"You can now chat with the bot in <#{ctx.channel.id}>")
|
| 313 |
+
await ctx.respond(embed=embed)
|
| 314 |
+
@bot.slash_command()
|
| 315 |
+
async def remove(ctx:discord.Interaction):
|
| 316 |
+
with open(f"{ctx.guild.name}.guild", "a") as f:
|
| 317 |
+
f.write(f"{ctx.channel.id}\n")
|
| 318 |
+
embed = discord.Embed(title="Success!", description=f"You can now chat with the bot in <#{ctx.channel.id}>")
|
| 319 |
+
await ctx.respond(embed=embed)
|
| 320 |
|
| 321 |
+
bot.run(os.environ["TOKEN"])
|
|
|