Araeynn commited on
Commit
7731f17
1 Parent(s): 490eb94

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +101 -101
app.py CHANGED
@@ -13,9 +13,9 @@ import streamlit as st
13
  from huggingface_hub import InferenceClient, login
14
 
15
  try:
16
- os.mkdir("data")
17
  except:
18
- pass
19
 
20
 
21
  HF_TOKEN = os.environ["HF_TOKEN"]
@@ -27,9 +27,9 @@ LLM = InferenceClient(model="openchat/openchat-3.5-0106")
27
 
28
 
29
  def ec(x, fd="<image>", sd="</image>"):
30
- matches = re.findall(re.escape(fd) + "(.*?)" + re.escape(sd), x)
31
- matches = matches if matches else [""]
32
- return matches
33
 
34
 
35
  intents = discord.Intents.default()
@@ -42,114 +42,114 @@ launch_time = datetime.datetime.utcnow()
42
  ph = st.empty()
43
 
44
  async def syncMessages():
45
- print(os.listdir("data"))
46
- if os.listdir("data") == []:
47
- return 0
48
- with ph.container():
49
- dirs = st.tabs(os.listdir("data"))
50
- i = -1
51
- for dir in os.listdir("data"):
52
- i += 1
53
- with dirs[i]:
54
- if files == []:
55
- return 0
56
- files = st.tabs(os.listdir("data/" + dir))
57
- k = -1
58
- for file in os.listdir("data/" + dir):
59
- k += 1
60
- with files[k]:
61
- with open(f"data/{dir}/{file}", "r") as f:
62
- o = f.read().split("<|end_of_turn|>")
63
- for item in o:
64
- item = item.split(": ", 1)
65
- if len(item) < 2:
66
- return 0
67
- st.markdown(f":blue[{item[0].split('GPT4 Correct ')[1]}]: {item[1]}")
68
 
69
  @client.event
70
  async def on_ready():
71
- print(f"Logged in as {client.user}")
72
- presence.start()
73
 
74
 
75
  @tasks.loop(seconds=1)
76
  async def presence():
77
- delta_uptime = datetime.datetime.utcnow() - launch_time
78
- hours, remainder = divmod(int(delta_uptime.total_seconds()), 3600)
79
- minutes, seconds = divmod(remainder, 60)
80
- days, hours = divmod(hours, 24)
81
- print(f"Online Time: {days:02d}d | {hours:02d}h | {minutes:02d}m | {seconds:02d}s")
82
- print("Syncing.")
83
- await syncMessages()
84
- await client.change_presence(
85
- status=discord.Status.dnd,
86
- activity=discord.Activity(
87
- type=discord.ActivityType.playing,
88
- large_image="https://i.imgur.com/Kk2BvJg.jpg",
89
- large_text="This is Game Icon",
90
- name="Escaping the IRS.",
91
- details="",
92
- state=f"Running for {days:02d}d | {hours:02d}h | {minutes:02d}m",
93
- ),
94
- )
95
 
96
 
97
  @client.event
98
  async def on_message(message):
99
- for user in message.mentions:
100
- message.content = message.content.replace(f"<@{user.id}>",
101
- f"@{str(user)}")
102
- try:
103
- msgchannel = message.channel
104
- try:
105
- msgchannel_name = msgchannel.name
106
- guild = message.guild
107
- guild_name = guild.name
108
- except:
109
- guild_name = "Direct"
110
- msgchannel_name = message.author.display_name
111
- s = f":green[{message.author}]: :violet[{message.content}] :blue[{msgchannel_name}] :orange[{guild_name}]"
112
- if message.author == client.user:
113
- return
114
- sysp = """You are Lyre, a helpful discord chatbot. Respond in markdown. Your username is lyre#9828."""
115
- try:
116
- os.mkdir("data/" + guild_name)
117
- except:
118
  try:
119
- with open(f"data/{guild_name}/{msgchannel_name}", "a") as f:
120
- n = "\n"
121
- f.write(
122
- f"""GPT4 Correct {message.author.name}: {message.content.strip(n)}<|end_of_turn|>"""
123
- )
124
- except error:
125
- with open(f"data/{guild_name}/{msgchannel_name}", "w") as f:
126
- f.write(
127
- f"GPT4 Correct system: {sysp}<|end_of_turn|>GPT4 Correct {message.author}: {message.content}<|end_of_turn|>"
128
- )
129
- finally:
130
- with open(f"data/{guild_name}/{msgchannel_name}", "r") as f:
131
- context = f.read()
132
- if "Feeway" in guild_name:
133
- context += f"GPT4 Correct Assistant:"
134
- title = ec(context, "<title>", "</title>")[0]
135
- output = LLM.text_generation(context,
136
- stop_sequences=["<|end_of_turn|>"],
137
- max_new_tokens=4096)
138
- with open(f"data/{guild_name}/{msgchannel_name}", "a") as f:
139
- f.write(f"GPT4 Correct Assistant: {output}<|end_of_turn|>")
140
- embed = discord.Embed(title=title,
141
- description=output.replace(
142
- f"<title>{title}</title>", ""),
143
- color=0x1E81B0)
144
- embed.set_footer(
145
- text=
146
- """Information or code generated by Lyre may not always be correct. Lyre was made by Araeyn."""
147
- )
148
- e = await message.reply(embed=embed)
149
- except Exception as e:
150
- print(Fore.RED)
151
- print(e)
152
- print(Style.RESET_ALL)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
 
154
  token = os.environ["TOKEN"]
155
  client.run(token)
 
13
  from huggingface_hub import InferenceClient, login
14
 
15
  try:
16
+ os.mkdir("data")
17
  except:
18
+ pass
19
 
20
 
21
  HF_TOKEN = os.environ["HF_TOKEN"]
 
27
 
28
 
29
  def ec(x, fd="<image>", sd="</image>"):
30
+ matches = re.findall(re.escape(fd) + "(.*?)" + re.escape(sd), x)
31
+ matches = matches if matches else [""]
32
+ return matches
33
 
34
 
35
  intents = discord.Intents.default()
 
42
  ph = st.empty()
43
 
44
  async def syncMessages():
45
+ print(os.listdir("data"))
46
+ if os.listdir("data") == []:
47
+ return 0
48
+ with ph.container():
49
+ dirs = st.tabs(os.listdir("data"))
50
+ i = -1
51
+ for dir in os.listdir("data"):
52
+ i += 1
53
+ with dirs[i]:
54
+ if os.listdir(f"data/{dir}") == []:
55
+ return 0
56
+ files = st.tabs(os.listdir("data/" + dir))
57
+ k = -1
58
+ for file in os.listdir("data/" + dir):
59
+ k += 1
60
+ with files[k]:
61
+ with open(f"data/{dir}/{file}", "r") as f:
62
+ o = f.read().split("<|end_of_turn|>")
63
+ for item in o:
64
+ item = item.split(": ", 1)
65
+ if len(item) < 2:
66
+ return 0
67
+ st.markdown(f":blue[{item[0].split('GPT4 Correct ')[1]}]: {item[1]}")
68
 
69
  @client.event
70
  async def on_ready():
71
+ print(f"Logged in as {client.user}")
72
+ presence.start()
73
 
74
 
75
  @tasks.loop(seconds=1)
76
  async def presence():
77
+ delta_uptime = datetime.datetime.utcnow() - launch_time
78
+ hours, remainder = divmod(int(delta_uptime.total_seconds()), 3600)
79
+ minutes, seconds = divmod(remainder, 60)
80
+ days, hours = divmod(hours, 24)
81
+ print(f"Online Time: {days:02d}d | {hours:02d}h | {minutes:02d}m | {seconds:02d}s")
82
+ print("Syncing.")
83
+ await syncMessages()
84
+ await client.change_presence(
85
+ status=discord.Status.dnd,
86
+ activity=discord.Activity(
87
+ type=discord.ActivityType.playing,
88
+ large_image="https://i.imgur.com/Kk2BvJg.jpg",
89
+ large_text="This is Game Icon",
90
+ name="Escaping the IRS.",
91
+ details="",
92
+ state=f"Running for {days:02d}d | {hours:02d}h | {minutes:02d}m",
93
+ ),
94
+ )
95
 
96
 
97
  @client.event
98
  async def on_message(message):
99
+ for user in message.mentions:
100
+ message.content = message.content.replace(f"<@{user.id}>",
101
+ f"@{str(user)}")
102
+ try:
103
+ msgchannel = message.channel
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  try:
105
+ msgchannel_name = msgchannel.name
106
+ guild = message.guild
107
+ guild_name = guild.name
108
+ except:
109
+ guild_name = "Direct"
110
+ msgchannel_name = message.author.display_name
111
+ s = f":green[{message.author}]: :violet[{message.content}] :blue[{msgchannel_name}] :orange[{guild_name}]"
112
+ if message.author == client.user:
113
+ return
114
+ sysp = """You are Lyre, a helpful discord chatbot. Respond in markdown. Your username is lyre#9828."""
115
+ try:
116
+ os.mkdir("data/" + guild_name)
117
+ except:
118
+ try:
119
+ with open(f"data/{guild_name}/{msgchannel_name}", "a") as f:
120
+ n = "\n"
121
+ f.write(
122
+ f"""GPT4 Correct {message.author.name}: {message.content.strip(n)}<|end_of_turn|>"""
123
+ )
124
+ except error:
125
+ with open(f"data/{guild_name}/{msgchannel_name}", "w") as f:
126
+ f.write(
127
+ f"GPT4 Correct system: {sysp}<|end_of_turn|>GPT4 Correct {message.author}: {message.content}<|end_of_turn|>"
128
+ )
129
+ finally:
130
+ with open(f"data/{guild_name}/{msgchannel_name}", "r") as f:
131
+ context = f.read()
132
+ if "Feeway" in guild_name:
133
+ context += f"GPT4 Correct Assistant:"
134
+ title = ec(context, "<title>", "</title>")[0]
135
+ output = LLM.text_generation(context,
136
+ stop_sequences=["<|end_of_turn|>"],
137
+ max_new_tokens=4096)
138
+ with open(f"data/{guild_name}/{msgchannel_name}", "a") as f:
139
+ f.write(f"GPT4 Correct Assistant: {output}<|end_of_turn|>")
140
+ embed = discord.Embed(title=title,
141
+ description=output.replace(
142
+ f"<title>{title}</title>", ""),
143
+ color=0x1E81B0)
144
+ embed.set_footer(
145
+ text=
146
+ """Information or code generated by Lyre may not always be correct. Lyre was made by Araeyn."""
147
+ )
148
+ e = await message.reply(embed=embed)
149
+ except Exception as e:
150
+ print(Fore.RED)
151
+ print(e)
152
+ print(Style.RESET_ALL)
153
 
154
  token = os.environ["TOKEN"]
155
  client.run(token)