File size: 1,531 Bytes
5546580
 
11ad260
740e062
11ad260
 
 
2998219
11ad260
b56f69c
 
c378b04
9650ea7
11ad260
 
d7fdc0e
11ad260
9650ea7
1d604bd
2d3687c
96cd6d4
 
 
 
 
 
 
 
740e062
2d3687c
96cd6d4
740e062
 
 
 
 
 
 
 
 
 
05a0741
5546580
11ad260
5546580
 
740e062
 
 
 
 
 
 
 
af03dc5
 
 
 
 
 
 
740e062
5546580
af03dc5
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
import discord
import os
import gradio as gr
import asyncio
from discord.ext import commands
from gradio_client import Client
from PIL import Image

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)


async def jojo(ctx):
    start_time = time.time()  
    style = 'JoJo'
    atchurl = 'https://cdn.discordapp.com/attachments/1100458786826747945/1111746037640601610/image.png'
    im = jojogan.predict(atchurl, style)
    end_time = time.time()
    generation_time = end_time - start_time    
    await ctx.send(f"{style} image generated in {generation_time:.2f} seconds.")
    await ctx.send(file=discord.File(im))


@bot.command()
async def command(ctx, num_requests: int):
    tasks = []

    for _ in range(num_requests):
        task = asyncio.create_task(jojo(ctx))
        tasks.append(task)

    await asyncio.gather(*tasks)
    await ctx.send("Command executed.")


def run_bot():
    bot.run(DISCORD_TOKEN)


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

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


def main():
    loop = asyncio.get_event_loop()
    tasks = [
        loop.create_task(run_bot()),
        loop.create_task(run_gradio_interface())
    ]
    loop.run_until_complete(asyncio.wait(tasks))


main()