seawolf2357
commited on
Commit
โข
40d0e92
1
Parent(s):
74ccf1c
Update app.py
Browse files
app.py
CHANGED
@@ -1,63 +1,55 @@
|
|
1 |
import discord
|
2 |
import logging
|
3 |
import os
|
4 |
-
import
|
5 |
-
import subprocess
|
6 |
-
from huggingface_hub import InferenceClient
|
7 |
-
from PIL import Image
|
8 |
-
import io
|
9 |
-
import base64
|
10 |
|
11 |
# ๋ก๊น
์ค์
|
12 |
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s:%(levelname)s:%(name)s: %(message)s', handlers=[logging.StreamHandler()])
|
13 |
|
14 |
# ์ธํ
ํธ ์ค์
|
15 |
intents = discord.Intents.default()
|
16 |
-
intents.message_content = True
|
17 |
intents.messages = True
|
18 |
intents.guilds = True
|
19 |
intents.guild_messages = True
|
20 |
|
21 |
-
#
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
# SPECIFIC_CHANNEL_ID๋ฅผ ์ํ๋ ์ฑ๋์ ์ซ์ ID๋ก ์ ์
|
26 |
-
SPECIFIC_CHANNEL_ID = 1251774883113734167 # ์ค์ ์ฑ๋ ID๋ก ๊ต์ฒดํ์ธ์
|
27 |
-
|
28 |
-
|
29 |
|
30 |
class MyClient(discord.Client):
|
31 |
def __init__(self, *args, **kwargs):
|
32 |
super().__init__(*args, **kwargs)
|
33 |
-
self.is_processing = False
|
34 |
|
35 |
async def on_ready(self):
|
36 |
-
logging.info(f'{self.user}
|
37 |
-
subprocess.Popen(["python", "web.py"])
|
38 |
-
logging.info("Web.py server has been started.")
|
39 |
|
40 |
async def on_message(self, message):
|
41 |
-
if message.author == self.user or
|
42 |
return
|
43 |
-
if message.
|
44 |
-
|
45 |
-
|
46 |
-
return
|
47 |
-
self.is_processing = True
|
48 |
-
try:
|
49 |
-
image_path = await generate_image(message.content)
|
50 |
if image_path:
|
51 |
-
await
|
52 |
else:
|
53 |
-
await message.channel.send("
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
if __name__ == "__main__":
|
62 |
-
|
63 |
-
|
|
|
|
1 |
import discord
|
2 |
import logging
|
3 |
import os
|
4 |
+
from gradio_client import Client
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
# ๋ก๊น
์ค์
|
7 |
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s:%(levelname)s:%(name)s: %(message)s', handlers=[logging.StreamHandler()])
|
8 |
|
9 |
# ์ธํ
ํธ ์ค์
|
10 |
intents = discord.Intents.default()
|
11 |
+
intents.message_content = True # ๋ฉ์์ง ๋ด์ฉ ์์ ์ธํ
ํธ ํ์ฑํ
|
12 |
intents.messages = True
|
13 |
intents.guilds = True
|
14 |
intents.guild_messages = True
|
15 |
|
16 |
+
# ํน์ ์ฑ๋ ID ์ค์
|
17 |
+
SPECIFIC_CHANNEL_ID = int(os.getenv("DISCORD_CHANNEL_ID"))
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
class MyClient(discord.Client):
|
20 |
def __init__(self, *args, **kwargs):
|
21 |
super().__init__(*args, **kwargs)
|
|
|
22 |
|
23 |
async def on_ready(self):
|
24 |
+
logging.info(f'{self.user}๋ก ๋ก๊ทธ์ธ๋์์ต๋๋ค!')
|
|
|
|
|
25 |
|
26 |
async def on_message(self, message):
|
27 |
+
if message.author == self.user or message.channel.id != SPECIFIC_CHANNEL_ID:
|
28 |
return
|
29 |
+
if message.content.startswith("!generate"): # ํ๋กฌํํธ ์์ ๋ช
๋ น์ด
|
30 |
+
prompt = message.content[len("!generate "):] # ๋ช
๋ น์ด ์ ๊ฑฐ ํ ํ๋กฌํํธ ์ถ์ถ
|
31 |
+
image_path = await self.generate_image(prompt)
|
|
|
|
|
|
|
|
|
32 |
if image_path:
|
33 |
+
await message.channel.send(file=discord.File(image_path))
|
34 |
else:
|
35 |
+
await message.channel.send("์ด๋ฏธ์ง๋ฅผ ์์ฑํ์ง ๋ชปํ์ต๋๋ค.")
|
36 |
+
|
37 |
+
async def generate_image(self, prompt):
|
38 |
+
client = Client("ginipick/komodel")
|
39 |
+
result = client.predict(
|
40 |
+
prompt=prompt,
|
41 |
+
negative="low quality, low quality, (deformed, distorted, disfigured:1.3), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, (mutated hands and fingers:1.4), disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation, (NSFW:1.25)",
|
42 |
+
width=1024,
|
43 |
+
height=1024,
|
44 |
+
scale=7,
|
45 |
+
steps=50,
|
46 |
+
api_name="/generate_image"
|
47 |
+
)
|
48 |
+
if 'image_path' in result:
|
49 |
+
return result['image_path'] # API๊ฐ ๋ฐํํ ์ด๋ฏธ์ง ๊ฒฝ๋ก
|
50 |
+
return None
|
51 |
|
52 |
if __name__ == "__main__":
|
53 |
+
discord_token = os.getenv('DISCORD_TOKEN')
|
54 |
+
client = MyClient(intents=intents)
|
55 |
+
client.run(discord_token)
|