|
import discord |
|
import os |
|
import gradio as gr |
|
from discord.ext import commands |
|
from gradio_client import Client |
|
from PIL import Image |
|
import asyncio |
|
|
|
DFIF_TOKEN = os.getenv('HF_TOKEN') |
|
DISCORD_TOKEN = os.environ.get("GRADIOTEST_TOKEN", None) |
|
|
|
df = Client("huggingface-projects/IF", DFIF_TOKEN) |
|
jojogan = Client("akhaliq/JoJoGAN", DFIF_TOKEN) |
|
|
|
|
|
intents = discord.Intents.default() |
|
intents.message_content = True |
|
|
|
bot = commands.Bot(command_prefix='!', intents=intents) |
|
|
|
|
|
async def generate_jojo_image(ctx): |
|
if ctx.message.attachments: |
|
attachment = ctx.message.attachments[0] |
|
await ctx.message.add_reaction('π€') |
|
await ctx.message.add_reaction('β') |
|
|
|
style = 'JoJo' |
|
im = jojogan.predict(attachment.url, style) |
|
await ctx.send(f'{ctx.author.mention} Here is the {style} version of it') |
|
await ctx.send(file=discord.File(im)) |
|
|
|
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 jojo(ctx): |
|
|
|
|
|
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() |