seawolf2357
commited on
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)
|