File size: 1,860 Bytes
5546580
 
7fa9e07
11ad260
7fa9e07
 
 
 
 
 
11ad260
 
 
7fa9e07
 
2998219
e0461c3
11ad260
b56f69c
 
c378b04
9650ea7
11ad260
 
d7fdc0e
11ad260
9650ea7
fad843f
1d604bd
2afeadf
 
2d3687c
2afeadf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96cd6d4
2afeadf
 
 
 
 
96cd6d4
2afeadf
 
740e062
2d3687c
2afeadf
 
 
 
 
 
 
 
 
 
fad843f
5546580
11ad260
5546580
dbb572b
5546580
dbb572b
 
740e062
dbb572b
 
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import discord
import os
import threading
import gradio as gr
import requests
import json
import random
import time
import re
from discord import Embed, Color
from discord.ext import commands
from gradio_client import Client
from PIL import Image
import asyncio
import shutil # for doing image movement magic


DFIF_TOKEN = os.getenv('HF_TOKEN')
DISCORD_TOKEN = os.environ.get("GRADIOTEST_TOKEN", None)

jojogan = Client("akhaliq/JoJoGAN", DFIF_TOKEN)

intents = discord.Intents.default()
intents.message_content = True

bot = commands.Bot(command_prefix='!', intents=intents)




@bot.command()
async def jojo(ctx):
    attachment = await discord_before(ctx)
    im = await generation(attachment)
    await discord_after(ctx, im)   
    
async def discord_before(ctx):
    if ctx.message.attachments: 
        await ctx.message.add_reaction('πŸ€–')
        await ctx.message.add_reaction('βŒ›')
        attachment = ctx.message.attachments[0]
        return attachment
    else:
        await ctx.send(f"{ctx.author.mention} No attachments to be found... Can't animify dat! Try sending me an image πŸ˜‰")
        await ctx.message.add_reaction('❌') 
        return False

async def generation(attachment):
    style = 'JoJo'
    im = jojogan.predict(attachment.url, style)
    return im

async def discord_after(ctx, im):
    await ctx.send(f'{ctx.author.mention} Here is the jojo version of it')
    await ctx.send(file=discord.File(im))
    await ctx.message.remove_reaction('βŒ›', bot.user)
    await ctx.message.add_reaction('βœ…')



'''
    task = asyncio.create_task(generate_jojo_image(ctx))
    await task 
'''       

 

    
    
    
def run_bot():
    bot.run(DISCORD_TOKEN)

threading.Thread(target=run_bot).start()

def greet(name):
    return "Hello " + name + "!"

demo = gr.Interface(fn=greet, inputs="text", outputs="text")
demo.launch()