Spaces:
seawolf2357
/
Running on CPU Upgrade

File size: 2,194 Bytes
78efe79
440418c
f3985af
40d0e92
407a575
32c38ef
f3985af
440418c
1831164
440418c
40d0e92
440418c
98c1b1b
 
08baccf
40d0e92
 
74ccf1c
78efe79
08baccf
 
 
78efe79
40d0e92
78efe79
 
40d0e92
78efe79
40d0e92
 
 
fc74fc1
40d0e92
fc74fc1
40d0e92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0926d14
34428f1
40d0e92
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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)