huggingbots / app.py
lunarflu's picture
lunarflu HF Staff
test
2d3687c
raw
history blame
4.05 kB
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()