File size: 3,290 Bytes
c674706
069699b
cf29d35
34b1666
bf74790
df08eaa
1cea653
655e8cd
 
3148736
 
bf74790
 
 
3148736
cf29d35
3148736
bf74790
cf29d35
fe5d109
bf74790
cf29d35
 
 
ebe5be1
cf29d35
 
 
 
ebe5be1
bf74790
c818f42
3148736
bf74790
a59b0ae
 
bf74790
 
 
3148736
2a46d18
bf74790
 
 
448f731
7a8fb34
f805a66
314ff34
cf29d35
 
3148736
bf74790
8e2c4e2
 
fe5d109
8e2c4e2
1cea653
bf74790
8eba0de
 
3148736
bf74790
d138499
bf74790
 
 
d138499
fe5d109
d138499
 
 
 
3148736
bf74790
425245c
 
 
 
 
 
 
 
 
 
 
 
d138499
bf74790
d138499
 
 
 
bf74790
 
 
fe5d109
bf74790
 
7a62795
 
bf74790
 
7a62795
b81d5d0
bf74790
 
b81d5d0
 
553829d
bf74790
 
7a62795
bf74790
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import discord
from discord import app_commands
import gradio as gr
import os
import threading
from falcon import try_falcon
from falcon import continue_falcon
from deepfloydif import deepfloydif_stage_1
from deepfloydif import deepfloydif_stage_2_react_check

# HF GUILD SETTINGS
MY_GUILD_ID = (
    1077674588122648679 if os.getenv("TEST_ENV", False) else 879548962464493619
)
MY_GUILD = discord.Object(id=MY_GUILD_ID)
DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)


class MyClient(discord.Client):
    """This structure allows slash commands to work instantly (instead of needing to sync global commands for up to an hour)"""

    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)


client = MyClient(intents=discord.Intents.all())


@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):
    """Command that begins a new conversation with Falcon"""
    try:
        await try_falcon(interaction, prompt)
    except Exception as e:
        print(f"Error: {e}")


@client.event
async def on_message(message):
    """Checks channel and continues Falcon conversation if it's the right Discord Thread"""
    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):
    """DeepfloydIF stage 1 generation"""
    try:
        await deepfloydif_stage_1(interaction, prompt, client)
    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 test(interaction: discord.Interaction, prompt: str):
    """DeepfloydIF stage 1 generation"""
    try:
        await interaction.response.send_message(f"{prompt}")
    except Exception as e:
        print(f"Error: {e}")
        

@client.event
async def on_reaction_add(reaction, user):
    """Checks for a reaction in order to call dfif2"""
    try:
        await deepfloydif_stage_2_react_check(reaction, user)
    except Exception as e:
        print(f"Error: {e} (known error, does not cause issues, low priority)")


"""This allows us to run the Discord bot in a Python thread"""


def run_bot():
    client.run(DISCORD_TOKEN)


threading.Thread(target=run_bot).start()
with gr.Blocks() as demo:
    gr.Markdown(
        """
    # Huggingbots Server
    This space hosts the huggingbots discord bot.
    Currently supported models are Falcon and DeepfloydIF
    """
    )
demo.queue(concurrency_count=20)
demo.launch()