|
import discord |
|
import logging |
|
import os |
|
from gradio_client import Client |
|
|
|
|
|
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s:%(levelname)s:%(name)s: %(message)s', handlers=[logging.StreamHandler()]) |
|
|
|
|
|
intents = discord.Intents.default() |
|
intents.message_content = True |
|
intents.messages = True |
|
intents.guilds = True |
|
intents.guild_messages = True |
|
|
|
|
|
SPECIFIC_CHANNEL_ID = int(os.getenv("DISCORD_CHANNEL_ID")) |
|
|
|
class MyClient(discord.Client): |
|
def __init__(self, *args, **kwargs): |
|
super().__init__(*args, **kwargs) |
|
|
|
async def on_ready(self): |
|
logging.info(f'{self.user}로 로그인되었습니다!') |
|
|
|
async def on_message(self, message): |
|
if message.author == self.user or message.channel.id != SPECIFIC_CHANNEL_ID: |
|
return |
|
if message.content.startswith("!generate"): |
|
prompt = message.content[len("!generate "):] |
|
image_path = await self.generate_image(prompt) |
|
if image_path: |
|
await message.channel.send(file=discord.File(image_path)) |
|
else: |
|
await message.channel.send("이미지를 생성하지 못했습니다.") |
|
|
|
async def generate_image(self, prompt): |
|
client = Client("ginipick/komodel") |
|
result = client.predict( |
|
prompt=prompt, |
|
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)", |
|
width=1024, |
|
height=1024, |
|
scale=7, |
|
steps=50, |
|
api_name="/generate_image" |
|
) |
|
if 'image_path' in result: |
|
return result['image_path'] |
|
return None |
|
|
|
if __name__ == "__main__": |
|
discord_token = os.getenv('DISCORD_TOKEN') |
|
client = MyClient(intents=intents) |
|
client.run(discord_token) |
|
|