huggingbots / app.py
lunarflu's picture
lunarflu HF Staff
Update app.py
7fa9e07
raw
history blame
1.86 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
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()