modbot / app.py
lunarflu's picture
lunarflu HF Staff
[main] syncing with deepfloydif.py
8eba0de
raw
history blame
3.67 kB
import discord
from discord import app_commands
from discord.ext import commands
import gradio_client
import gradio as gr
from gradio_client import Client
import os #
import threading
import requests
import json
import random
import time
from PIL import Image
import asyncio
import glob
import falcon
from falcon import try_falcon
from falcon import continue_falcon
import deepfloydif
from deepfloydif import try_deepfloydif
#-------------------------------------------------------------------------------------------------------------------------------------
MY_GUILD = discord.Object(id=1077674588122648679) # HF = 879548962464493619, test = 1077674588122648679
DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)
DEEPFLOYD_CHANNEL_ID = 1121834257959092234 # 1121834257959092234 = test
#df = Client("huggingface-projects/IF", HF_TOKEN)
#-------------------------------------------------------------------------------------------------------------------------------------
# This structure allows commands to work instantly (instead of needing to sync global commands for up to an hour)
class MyClient(discord.Client):
def __init__(self, *, intents: discord.Intents):
super().__init__(intents=intents)
self.tree = app_commands.CommandTree(self)
async def setup_hook(self):
# This copies the global commands over to our guild
self.tree.copy_global_to(guild=MY_GUILD)
await self.tree.sync(guild=MY_GUILD)
intents = discord.Intents.all()
client = MyClient(intents=intents)
#-------------------------------------------------------------------------------------------------------------------------------------
@client.event
async def on_ready():
print(f'Logged in as {client.user} (ID: {client.user.id})')
print('------')
#-------------------------------------------------------------------------------------------------------------------------------------
@client.tree.command()
@app_commands.describe(
prompt='Enter some text to chat with the bot! Like this: /falcon Hello, how are you?')
async def falcon(interaction: discord.Interaction, prompt: str):
try:
await try_falcon(interaction, prompt)
except Exception as e:
print(f"Error: {e}")
#-------------------------------------------------------------------------------------------------------------------------------------
@client.event
async def on_message(message):
try:
await continue_falcon(message)
await message.remove_reaction('πŸ”', client.user) # test=πŸ” hf=πŸ”
except Exception as e:
print(f"Error: {e}")
#-------------------------------------------------------------------------------------------------------------------------------------
@client.tree.command()
@app_commands.describe(
prompt='Enter a prompt to generate an image! Can generate realistic text, too!')
async def deepfloydif(interaction: discord.Interaction, prompt: str):
try:
await try_deepfloydif(interaction, prompt)
except Exception as e:
print(f"Error: {e}")
#-------------------------------------------------------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------------------------------------------------------
# running in thread
DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)
def run_bot():
client.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.queue(concurrency_count=20)
demo.launch()