Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,6 @@
|
|
| 1 |
-
#from typing import Optional
|
| 2 |
import discord
|
| 3 |
from discord import app_commands
|
| 4 |
from discord.ext import commands
|
| 5 |
-
#from discord import Embed, Color
|
| 6 |
import gradio_client
|
| 7 |
import gradio as gr
|
| 8 |
from gradio_client import Client
|
|
@@ -12,49 +10,33 @@ import requests
|
|
| 12 |
import json
|
| 13 |
import random
|
| 14 |
import time
|
| 15 |
-
#import re
|
| 16 |
from PIL import Image
|
| 17 |
import asyncio
|
| 18 |
-
#import concurrent.futures
|
| 19 |
-
#import multiprocessing
|
| 20 |
import glob
|
| 21 |
|
| 22 |
import falcon
|
| 23 |
from falcon import try_falcon
|
| 24 |
from falcon import continue_falcon
|
| 25 |
#-------------------------------------------------------------------------------------------------------------------------------------
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
MY_GUILD = discord.Object(id=1077674588122648679) # HF = 879548962464493619, test = 1077674588122648679
|
| 30 |
-
HF_TOKEN = os.getenv('HF_TOKEN')
|
| 31 |
DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)
|
| 32 |
|
| 33 |
-
falcon_userid_threadid_dictionary = {}
|
| 34 |
-
|
| 35 |
-
GUILD_ID = 1077674588122648679 # 1077674588122648679 = test
|
| 36 |
-
DEEPFLOYD_CHANNEL_ID = 1121834257959092234 # 1121834257959092234 = test
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
|
|
|
| 41 |
df = Client("huggingface-projects/IF", HF_TOKEN)
|
| 42 |
-
falconclient = Client("HuggingFaceH4/falcon-chat", HF_TOKEN)
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
#-------------------------------------------------------------------------------------------------------------------------------------
|
| 47 |
# This structure allows commands to work instantly (instead of needing to sync global commands for up to an hour)
|
| 48 |
class MyClient(discord.Client):
|
| 49 |
def __init__(self, *, intents: discord.Intents):
|
| 50 |
super().__init__(intents=intents)
|
| 51 |
self.tree = app_commands.CommandTree(self)
|
| 52 |
-
|
| 53 |
async def setup_hook(self):
|
| 54 |
# This copies the global commands over to our guild
|
| 55 |
self.tree.copy_global_to(guild=MY_GUILD)
|
| 56 |
await self.tree.sync(guild=MY_GUILD)
|
| 57 |
-
|
| 58 |
intents = discord.Intents.all()
|
| 59 |
client = MyClient(intents=intents)
|
| 60 |
#-------------------------------------------------------------------------------------------------------------------------------------
|
|
@@ -69,7 +51,6 @@ async def on_ready():
|
|
| 69 |
async def falcon(interaction: discord.Interaction, prompt: str):
|
| 70 |
try:
|
| 71 |
await try_falcon(interaction, prompt)
|
| 72 |
-
|
| 73 |
except Exception as e:
|
| 74 |
print(f"Error: {e}")
|
| 75 |
#-------------------------------------------------------------------------------------------------------------------------------------
|
|
@@ -78,21 +59,16 @@ async def on_message(message):
|
|
| 78 |
try:
|
| 79 |
await continue_falcon(message)
|
| 80 |
await message.remove_reaction('π', client.user) # test=π hf=π
|
| 81 |
-
|
| 82 |
except Exception as e:
|
| 83 |
print(f"Error: {e}")
|
| 84 |
#-------------------------------------------------------------------------------------------------------------------------------------
|
| 85 |
# running in thread
|
| 86 |
DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)
|
| 87 |
-
|
| 88 |
def run_bot():
|
| 89 |
client.run(DISCORD_TOKEN)
|
| 90 |
-
|
| 91 |
threading.Thread(target=run_bot).start()
|
| 92 |
-
|
| 93 |
def greet(name):
|
| 94 |
return "Hello " + name + "!"
|
| 95 |
-
|
| 96 |
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 97 |
demo.queue(concurrency_count=20)
|
| 98 |
demo.launch()
|
|
|
|
|
|
|
| 1 |
import discord
|
| 2 |
from discord import app_commands
|
| 3 |
from discord.ext import commands
|
|
|
|
| 4 |
import gradio_client
|
| 5 |
import gradio as gr
|
| 6 |
from gradio_client import Client
|
|
|
|
| 10 |
import json
|
| 11 |
import random
|
| 12 |
import time
|
|
|
|
| 13 |
from PIL import Image
|
| 14 |
import asyncio
|
|
|
|
|
|
|
| 15 |
import glob
|
| 16 |
|
| 17 |
import falcon
|
| 18 |
from falcon import try_falcon
|
| 19 |
from falcon import continue_falcon
|
| 20 |
#-------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
| 21 |
MY_GUILD = discord.Object(id=1077674588122648679) # HF = 879548962464493619, test = 1077674588122648679
|
|
|
|
| 22 |
DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
+
DEEPFLOYD_CHANNEL_ID = 1121834257959092234 # 1121834257959092234 = test
|
| 29 |
df = Client("huggingface-projects/IF", HF_TOKEN)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
#-------------------------------------------------------------------------------------------------------------------------------------
|
| 31 |
# This structure allows commands to work instantly (instead of needing to sync global commands for up to an hour)
|
| 32 |
class MyClient(discord.Client):
|
| 33 |
def __init__(self, *, intents: discord.Intents):
|
| 34 |
super().__init__(intents=intents)
|
| 35 |
self.tree = app_commands.CommandTree(self)
|
|
|
|
| 36 |
async def setup_hook(self):
|
| 37 |
# This copies the global commands over to our guild
|
| 38 |
self.tree.copy_global_to(guild=MY_GUILD)
|
| 39 |
await self.tree.sync(guild=MY_GUILD)
|
|
|
|
| 40 |
intents = discord.Intents.all()
|
| 41 |
client = MyClient(intents=intents)
|
| 42 |
#-------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
| 51 |
async def falcon(interaction: discord.Interaction, prompt: str):
|
| 52 |
try:
|
| 53 |
await try_falcon(interaction, prompt)
|
|
|
|
| 54 |
except Exception as e:
|
| 55 |
print(f"Error: {e}")
|
| 56 |
#-------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
| 59 |
try:
|
| 60 |
await continue_falcon(message)
|
| 61 |
await message.remove_reaction('π', client.user) # test=π hf=π
|
|
|
|
| 62 |
except Exception as e:
|
| 63 |
print(f"Error: {e}")
|
| 64 |
#-------------------------------------------------------------------------------------------------------------------------------------
|
| 65 |
# running in thread
|
| 66 |
DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)
|
|
|
|
| 67 |
def run_bot():
|
| 68 |
client.run(DISCORD_TOKEN)
|
|
|
|
| 69 |
threading.Thread(target=run_bot).start()
|
|
|
|
| 70 |
def greet(name):
|
| 71 |
return "Hello " + name + "!"
|
|
|
|
| 72 |
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 73 |
demo.queue(concurrency_count=20)
|
| 74 |
demo.launch()
|