Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
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 | |
# ํน์ ์ฑ๋ ID ์ค์ | |
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'] # API๊ฐ ๋ฐํํ ์ด๋ฏธ์ง ๊ฒฝ๋ก | |
return None | |
if __name__ == "__main__": | |
discord_token = os.getenv('DISCORD_TOKEN') | |
client = MyClient(intents=intents) | |
client.run(discord_token) | |