Araeynn commited on
Commit
6c22325
1 Parent(s): 80f9977

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +95 -3
app.py CHANGED
@@ -1,5 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
 
2
 
3
- x = st.slider('Select a value')
4
- st.write(x, 'squared is', x * x)
5
- st.write(x, 'cubed is', x * x * x)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ print("Started.")
2
+ import json
3
+ import os
4
+ import re
5
+ from threading import Thread
6
+ import discord
7
+ from colorama import Fore, Style
8
+ import random
9
+ from huggingface_hub import InferenceClient, login
10
+ from PIL import Image
11
+ import math
12
  import streamlit as st
13
+ import asyncio
14
 
15
+ HF_TOKEN = os.environ["HF_TOKEN"]
16
+
17
+ login(HF_TOKEN)
18
+
19
+ SD = InferenceClient(model="stabilityai/stable-diffusion-2-1")
20
+ LLM = InferenceClient(model="openchat/openchat-3.5-0106")
21
+
22
+
23
+ def ec(x, fd="<image>", sd="</image>"):
24
+ matches = re.findall(re.escape(fd) + "(.*?)" + re.escape(sd), x)
25
+ matches = matches if matches else [""]
26
+ return matches
27
+
28
+
29
+ intents = discord.Intents.default()
30
+ intents.message_content = True
31
+
32
+ client = discord.Client(intents=intents)
33
+
34
+
35
+ @client.event
36
+ async def on_ready():
37
+ print(f"Logged in as {client.user}")
38
+
39
+
40
+ @client.event
41
+ async def on_message(message):
42
+ for user in message.mentions:
43
+ message.content = message.content.replace(f"<@{user.id}>",
44
+ f"@{str(user)}")
45
+ try:
46
+ msgchannel = message.channel
47
+ try:
48
+ msgchannel_name = msgchannel.name
49
+ guild = message.guild
50
+ guild_name = guild.name
51
+ except:
52
+ guild_name = "Direct"
53
+ msgchannel_name = message.author.display_name
54
+ s = f":green[{message.author}]: :white[{message.content}] :blue[{msgchannel_name}] :purple[{guild_name}]"
55
+ st.markdown(s)
56
+ if message.author == client.user:
57
+ return
58
+ sysp = """You are Lyre, a helpful discord chatbot. Respond in markdown. Your username is lyre#9828."""
59
+ try:
60
+ os.mkdir(guild_name)
61
+ with open(f"{guild_name}/{msgchannel_name}", "w") as f:
62
+ f.write(
63
+ f"GPT4 Correct system: {sysp}<|end_of_turn|>\nGPT4 Correct {message.author}: {message.content}<|end_of_turn|>"
64
+ )
65
+ except:
66
+ with open(f"{guild_name}/{msgchannel_name}", "a") as f:
67
+ n = "\n"
68
+ f.write(
69
+ f"""GPT4 Correct {message.author.name}: {message.content.strip(n)}<|end_of_turn|>"""
70
+ )
71
+ finally:
72
+ with open(f"{guild_name}/{msgchannel_name}", "r") as f:
73
+ context = f.read()
74
+ context += f"GPT4 Correct Assistant: {message.content}<|end_of_turn|>\n"
75
+ title = ec(context, "<title>", "</title>")[0]
76
+ output = LLM.text_generation(context,
77
+ stop_sequences=["<|end_of_turn|>"],
78
+ max_new_tokens=4096)
79
+ with open(f"{guild_name}/{msgchannel_name}", "a") as f:
80
+ f.write(f"GPT4 Correct Assistant: {output}<|end_of_turn|>")
81
+ words = output.split()
82
+ embed = discord.Embed(title=title,
83
+ description=" ".join(words[:i * 10]).replace(
84
+ f"<title>{title}</title>", ""),
85
+ color=0x1E81B0)
86
+ embed.set_footer(
87
+ text=
88
+ """Information or code generated by Lyre may not always be correct. Lyre was made by Araeyn."""
89
+ )
90
+ e = await message.reply(embed=embed)
91
+ except Exception as e:
92
+ print(Fore.RED)
93
+ print(e)
94
+ print(Style.RESET_ALL)
95
+
96
+ token = os.environ["TOKEN"]
97
+ client.run(token)