File size: 2,293 Bytes
5546580 11ad260 740e062 72dd118 11ad260 2998219 e0461c3 11ad260 b56f69c c378b04 9650ea7 11ad260 d7fdc0e 11ad260 9650ea7 fad843f 1d604bd 2d3687c 96cd6d4 428e996 96cd6d4 740e062 fad843f 2d3687c 96cd6d4 740e062 fad843f 740e062 fad843f 740e062 fad843f 740e062 fad843f 740e062 fad843f 05a0741 fad843f 5546580 11ad260 5546580 740e062 e2fe3d1 af03dc5 e2fe3d1 740e062 5546580 e2fe3d1 |
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 82 83 84 85 86 87 88 89 90 91 92 |
import discord
import os
import gradio as gr
import asyncio
import time #
from discord.ext import commands
from gradio_client import Client
from PIL import Image
breaking bot
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)
MAX_WORKERS = 5
worker_semaphore = asyncio.Semaphore(MAX_WORKERS)
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"jojo image generated in {generation_time:.2f} seconds.")
await ctx.send(file=discord.File(im))
async def process_requests(queue):
while True:
ctx = await queue.get()
async with worker_semaphore:
await jojo(ctx)
queue.task_done()
@bot.command()
async def command(ctx, num_requests: int):
start_time = time.time()
queue = asyncio.Queue()
# Start the worker tasks
worker_tasks = []
for _ in range(MAX_WORKERS):
task = asyncio.create_task(process_requests(queue))
worker_tasks.append(task)
# Add the requests to the queue
for _ in range(num_requests):
await queue.put(ctx)
# Wait for all requests to be processed
await queue.join()
# Cancel the worker tasks
for task in worker_tasks:
task.cancel()
await ctx.send("Command executed.")
end_time = time.time()
generation_time = end_time - start_time
await ctx.send(f"{style} everything done in {generation_time:.2f} seconds.")
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()
async def main():
loop = asyncio.get_event_loop()
tasks = [
loop.create_task(run_bot()),
loop.create_task(run_gradio_interface())
]
await asyncio.wait(tasks)
asyncio.run(main())
|