[app.py] black + ruff
Browse files
app.py
CHANGED
|
@@ -1,25 +1,24 @@
|
|
| 1 |
import discord
|
| 2 |
from discord import app_commands
|
| 3 |
import gradio as gr
|
| 4 |
-
from gradio_client import Client
|
| 5 |
import os
|
| 6 |
-
import threading
|
| 7 |
-
import asyncio
|
| 8 |
-
import falcon
|
| 9 |
from falcon import try_falcon
|
| 10 |
from falcon import continue_falcon
|
| 11 |
-
import deepfloydif
|
| 12 |
from deepfloydif import deepfloydif_stage_1
|
| 13 |
-
from deepfloydif import deepfloydif_stage_2
|
| 14 |
from deepfloydif import deepfloydif_stage_2_react_check
|
| 15 |
|
| 16 |
# HF GUILD SETTINGS
|
| 17 |
-
MY_GUILD_ID =
|
|
|
|
|
|
|
| 18 |
MY_GUILD = discord.Object(id=MY_GUILD_ID)
|
| 19 |
DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)
|
| 20 |
|
|
|
|
| 21 |
class MyClient(discord.Client):
|
| 22 |
"""This structure allows slash commands to work instantly (instead of needing to sync global commands for up to an hour)"""
|
|
|
|
| 23 |
def __init__(self, *, intents: discord.Intents):
|
| 24 |
super().__init__(intents=intents)
|
| 25 |
self.tree = app_commands.CommandTree(self)
|
|
@@ -29,15 +28,20 @@ class MyClient(discord.Client):
|
|
| 29 |
self.tree.copy_global_to(guild=MY_GUILD)
|
| 30 |
await self.tree.sync(guild=MY_GUILD)
|
| 31 |
|
|
|
|
| 32 |
client = MyClient(intents=discord.Intents.all())
|
| 33 |
|
|
|
|
| 34 |
@client.event
|
| 35 |
async def on_ready():
|
| 36 |
-
print(f
|
| 37 |
-
print(
|
|
|
|
| 38 |
|
| 39 |
@client.tree.command()
|
| 40 |
-
@app_commands.describe(
|
|
|
|
|
|
|
| 41 |
async def falcon(interaction: discord.Interaction, prompt: str):
|
| 42 |
"""Command that begins a new conversation with Falcon"""
|
| 43 |
try:
|
|
@@ -45,43 +49,53 @@ async def falcon(interaction: discord.Interaction, prompt: str):
|
|
| 45 |
except Exception as e:
|
| 46 |
print(f"Error: {e}")
|
| 47 |
|
|
|
|
| 48 |
@client.event
|
| 49 |
async def on_message(message):
|
| 50 |
"""Checks channel and continues Falcon conversation if it's the right Discord Thread"""
|
| 51 |
try:
|
| 52 |
await continue_falcon(message)
|
| 53 |
-
#await message.remove_reaction('π', client.user) # test=π hf=π
|
| 54 |
except Exception as e:
|
| 55 |
print(f"Error: {e}")
|
| 56 |
|
|
|
|
| 57 |
@client.tree.command()
|
| 58 |
-
@app_commands.describe(
|
|
|
|
|
|
|
| 59 |
async def deepfloydif(interaction: discord.Interaction, prompt: str):
|
| 60 |
"""DeepfloydIF stage 1 generation"""
|
| 61 |
try:
|
| 62 |
await deepfloydif_stage_1(interaction, prompt, client)
|
| 63 |
-
|
| 64 |
except Exception as e:
|
| 65 |
print(f"Error: {e}")
|
| 66 |
|
|
|
|
| 67 |
@client.event
|
| 68 |
-
async def on_reaction_add(reaction, user):
|
| 69 |
"""Checks for a reaction in order to call dfif2"""
|
| 70 |
try:
|
| 71 |
await deepfloydif_stage_2_react_check(reaction, user)
|
| 72 |
-
|
| 73 |
except Exception as e:
|
| 74 |
-
print(f"Error: {e} (known error, does not cause issues, low priority)")
|
| 75 |
-
|
|
|
|
| 76 |
"""This allows us to run the Discord bot in a Python thread"""
|
|
|
|
|
|
|
| 77 |
def run_bot():
|
| 78 |
client.run(DISCORD_TOKEN)
|
|
|
|
|
|
|
| 79 |
threading.Thread(target=run_bot).start()
|
| 80 |
with gr.Blocks() as demo:
|
| 81 |
-
gr.Markdown(
|
|
|
|
| 82 |
# Huggingbots Server
|
| 83 |
This space hosts the huggingbots discord bot.
|
| 84 |
Currently supported models are Falcon and DeepfloydIF
|
| 85 |
-
"""
|
|
|
|
| 86 |
demo.queue(concurrency_count=20)
|
| 87 |
-
demo.launch()
|
|
|
|
| 1 |
import discord
|
| 2 |
from discord import app_commands
|
| 3 |
import gradio as gr
|
|
|
|
| 4 |
import os
|
| 5 |
+
import threading
|
|
|
|
|
|
|
| 6 |
from falcon import try_falcon
|
| 7 |
from falcon import continue_falcon
|
|
|
|
| 8 |
from deepfloydif import deepfloydif_stage_1
|
|
|
|
| 9 |
from deepfloydif import deepfloydif_stage_2_react_check
|
| 10 |
|
| 11 |
# HF GUILD SETTINGS
|
| 12 |
+
MY_GUILD_ID = (
|
| 13 |
+
1077674588122648679 if os.getenv("TEST_ENV", False) else 879548962464493619
|
| 14 |
+
)
|
| 15 |
MY_GUILD = discord.Object(id=MY_GUILD_ID)
|
| 16 |
DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)
|
| 17 |
|
| 18 |
+
|
| 19 |
class MyClient(discord.Client):
|
| 20 |
"""This structure allows slash commands to work instantly (instead of needing to sync global commands for up to an hour)"""
|
| 21 |
+
|
| 22 |
def __init__(self, *, intents: discord.Intents):
|
| 23 |
super().__init__(intents=intents)
|
| 24 |
self.tree = app_commands.CommandTree(self)
|
|
|
|
| 28 |
self.tree.copy_global_to(guild=MY_GUILD)
|
| 29 |
await self.tree.sync(guild=MY_GUILD)
|
| 30 |
|
| 31 |
+
|
| 32 |
client = MyClient(intents=discord.Intents.all())
|
| 33 |
|
| 34 |
+
|
| 35 |
@client.event
|
| 36 |
async def on_ready():
|
| 37 |
+
print(f"Logged in as {client.user} (ID: {client.user.id})")
|
| 38 |
+
print("------")
|
| 39 |
+
|
| 40 |
|
| 41 |
@client.tree.command()
|
| 42 |
+
@app_commands.describe(
|
| 43 |
+
prompt="Enter some text to chat with the bot! Like this: /falcon Hello, how are you?"
|
| 44 |
+
)
|
| 45 |
async def falcon(interaction: discord.Interaction, prompt: str):
|
| 46 |
"""Command that begins a new conversation with Falcon"""
|
| 47 |
try:
|
|
|
|
| 49 |
except Exception as e:
|
| 50 |
print(f"Error: {e}")
|
| 51 |
|
| 52 |
+
|
| 53 |
@client.event
|
| 54 |
async def on_message(message):
|
| 55 |
"""Checks channel and continues Falcon conversation if it's the right Discord Thread"""
|
| 56 |
try:
|
| 57 |
await continue_falcon(message)
|
| 58 |
+
# await message.remove_reaction('π', client.user) # test=π hf=π
|
| 59 |
except Exception as e:
|
| 60 |
print(f"Error: {e}")
|
| 61 |
|
| 62 |
+
|
| 63 |
@client.tree.command()
|
| 64 |
+
@app_commands.describe(
|
| 65 |
+
prompt="Enter a prompt to generate an image! Can generate realistic text, too!"
|
| 66 |
+
)
|
| 67 |
async def deepfloydif(interaction: discord.Interaction, prompt: str):
|
| 68 |
"""DeepfloydIF stage 1 generation"""
|
| 69 |
try:
|
| 70 |
await deepfloydif_stage_1(interaction, prompt, client)
|
|
|
|
| 71 |
except Exception as e:
|
| 72 |
print(f"Error: {e}")
|
| 73 |
|
| 74 |
+
|
| 75 |
@client.event
|
| 76 |
+
async def on_reaction_add(reaction, user):
|
| 77 |
"""Checks for a reaction in order to call dfif2"""
|
| 78 |
try:
|
| 79 |
await deepfloydif_stage_2_react_check(reaction, user)
|
|
|
|
| 80 |
except Exception as e:
|
| 81 |
+
print(f"Error: {e} (known error, does not cause issues, low priority)")
|
| 82 |
+
|
| 83 |
+
|
| 84 |
"""This allows us to run the Discord bot in a Python thread"""
|
| 85 |
+
|
| 86 |
+
|
| 87 |
def run_bot():
|
| 88 |
client.run(DISCORD_TOKEN)
|
| 89 |
+
|
| 90 |
+
|
| 91 |
threading.Thread(target=run_bot).start()
|
| 92 |
with gr.Blocks() as demo:
|
| 93 |
+
gr.Markdown(
|
| 94 |
+
"""
|
| 95 |
# Huggingbots Server
|
| 96 |
This space hosts the huggingbots discord bot.
|
| 97 |
Currently supported models are Falcon and DeepfloydIF
|
| 98 |
+
"""
|
| 99 |
+
)
|
| 100 |
demo.queue(concurrency_count=20)
|
| 101 |
+
demo.launch()
|