File size: 4,049 Bytes
5546580 d11f62f 11ad260 d11f62f 11ad260 d11f62f 11ad260 75dfc1c 2998219 11ad260 b56f69c c378b04 9650ea7 d7fdc0e 11ad260 d7fdc0e 11ad260 9650ea7 dc2fc67 2d3687c 75dfc1c d48cc05 2d3687c d48cc05 0a57242 2d3687c d48cc05 2d3687c dc2fc67 d48cc05 1756027 dc2fc67 11ad260 2d3687c 19308af 5546580 11ad260 5546580 11ad260 |
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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
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
#from ratelimiter import RateLimiter
import asyncio
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))
#---------------------------------------------------------------------------------------------------------------------------
async def spiderverse(ctx, attachment):
start_time = time.time()
style = 'Spider-Verse'
im = jojogan.predict(attachment.url, 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))
#---------------------------------------------------------------------------------------------------------------------------
async def disney(ctx, attachment):
start_time = time.time()
style = 'disney'
im = jojogan.predict(attachment.url, 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))
#---------------------------------------------------------------------------------------------------------------------------
async def sketch(ctx, attachment):
start_time = time.time()
style = 'sketch'
im = jojogan.predict(attachment.url, 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 jojo2(ctx):
if ctx.message.attachments:
attachment = ctx.message.attachments[0]
await ctx.message.add_reaction('π€')
await ctx.message.add_reaction('β')
task = asyncio.create_task(generate_jojo_image(ctx, attachment))
await task
await ctx.message.remove_reaction('β', bot.user)
await ctx.message.add_reaction('β
')
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('β')
#----------------------------------------------------------------------------------------------------------------------------
@bot.command()
async def run_commands(ctx):
await ctx.send("running 4 commands...")
task1 = asyncio.create_task(jojo(ctx))
task2 = asyncio.create_task(jojo(ctx))
task3 = asyncio.create_task(jojo(ctx))
task4 = asyncio.create_task(jojo(ctx))
await asyncio.gather(task1, task2, task3, task4)
await ctx.send("All commands completed.")
#----------------------------------------------------------------------------------------------------------------------------
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() |