Spaces:
seawolf2357
/
Running on CPU Upgrade

kai-math / app.py
seawolf2357's picture
Update app.py
40d0e92 verified
raw
history blame
2.19 kB
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)