File size: 1,688 Bytes
5bf5ca7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
57
58
import discord
import os

import gradio_client as gr 

from fastapi import FastAPI

# Get Gradio client
jojogan = gr.Client("akhaliq/JoJoGAN")

# Set up discord bot 
class MyClient(discord.Client):
    async def on_ready(self):
        print('Logged on as', self.user)

    async def on_message(self, message):
        # don't respond to ourselves
        if message.author == self.user:
            return

        if message.content.find("!help") != -1:
            await message.reply("Use !jojo !disney !spidey or !sketch. Have fun!", mention_author=True)

        style = None
        if message.content.startswith('!jojo'):
            style = 'JoJo'
        if message.content.startswith('!disney'):
            style = 'Disney'
        if message.content.startswith('!spidey'):
            style = 'Spider-Verse'
        if message.content.startswith('!sketch'):
            style = 'sketch'

        if style:
            if message.attachments:
                attachment = message.attachments[0]
                im = jojogan.predict(attachment.url, style)
                await message.reply(f'Here is the {style} version of it', file=discord.File(im))
            else:
                await message.channel.send("No attachments to be found...Can't animify dat! Try sending me an image πŸ˜‰")

DISCORD_TOKEN = os.environ.get("DISCORD_PAINTER_TOKEN", None)
intents = discord.Intents.default()
intents.message_content = True
client = MyClient(intents=intents)


app = FastAPI()

async def run_bot():
  client.run(DISCORD_TOKEN)

# Hacky, keep FastAPI running so Space is running
@app.get("/")
async def root():
    return {"message": "Hello World"}

asyncio.create_task(run_bot)