Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,16 +18,24 @@ from aiohttp.resolver import AsyncResolver
|
|
| 18 |
import utils
|
| 19 |
|
| 20 |
event = Event()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
# Setup Discord bot
|
| 23 |
-
logging.basicConfig(level=logging.INFO)
|
| 24 |
intents = discord.Intents.default()
|
| 25 |
intents.message_content = True
|
| 26 |
intents.members = True
|
| 27 |
-
|
| 28 |
-
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
|
| 29 |
-
HF_TOKEN=os.getenv("HF_TOKEN")
|
| 30 |
-
|
| 31 |
|
| 32 |
async def main():
|
| 33 |
# Setup DNS resolver to avoid potential issues
|
|
@@ -35,55 +43,37 @@ async def main():
|
|
| 35 |
connector = aiohttp.TCPConnector(resolver=resolver)
|
| 36 |
client = Client("https://standarovskid-bot.hf.space/", token=HF_TOKEN)
|
| 37 |
|
| 38 |
-
# Instantiate bot
|
| 39 |
-
bot = commands.Bot(intents=intents, connector=connector, command_prefix="!")
|
| 40 |
|
| 41 |
-
@bot.event
|
| 42 |
-
async def on_ready():
|
| 43 |
-
print(f"Logged in as {bot.user} (ID: {bot.user.id})")
|
| 44 |
-
synced = await bot.tree.sync()
|
| 45 |
-
print(f"Synced commands: {', '.join([s.name for s in synced])}.")
|
| 46 |
-
event.set()
|
| 47 |
-
print("------")
|
| 48 |
-
|
| 49 |
-
async def response(input_text):
|
| 50 |
-
return "fine"
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
)
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
await ctx.channel.send("toto2")
|
| 60 |
-
# 调用 Gradio 应用 API
|
| 61 |
-
result = client.predict(
|
| 62 |
-
message=input_text,
|
| 63 |
-
api_name="/slow_echo"
|
| 64 |
-
)
|
| 65 |
-
await ctx.channel.send(f"yeah right lmfao 🥀🥀")
|
| 66 |
-
|
| 67 |
-
return result
|
| 68 |
-
except Exception as e:
|
| 69 |
-
await ctx.channel.send("issueo")
|
| 70 |
-
return f"Erreur:{e}"
|
| 71 |
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
#if message.author == bot.user:
|
| 76 |
-
#return
|
| 77 |
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
-
|
| 89 |
-
asyncio.run(main())
|
|
|
|
| 18 |
import utils
|
| 19 |
|
| 20 |
event = Event()
|
| 21 |
+
logging.basicConfig(level=logging.INFO)
|
| 22 |
+
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
|
| 23 |
+
HF_TOKEN=os.getenv("HF_TOKEN")
|
| 24 |
+
|
| 25 |
+
def get_client(session: Optional[str] = None) -> grc.Client:
|
| 26 |
+
# Setup DNS resolver to avoid potential issues
|
| 27 |
+
resolver = AsyncResolver(nameservers=["1.1.1.1", "8.8.8.8"])
|
| 28 |
+
connector = aiohttp.TCPConnector(resolver=resolver)
|
| 29 |
+
client = Client("https://standarovskid-bot.hf.space/", token=HF_TOKEN)
|
| 30 |
+
if session:
|
| 31 |
+
client.session_hash = session
|
| 32 |
+
return client
|
| 33 |
|
| 34 |
# Setup Discord bot
|
|
|
|
| 35 |
intents = discord.Intents.default()
|
| 36 |
intents.message_content = True
|
| 37 |
intents.members = True
|
| 38 |
+
bot = commands.Bot(intents=intents, connector=connector, command_prefix="!")
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
async def main():
|
| 41 |
# Setup DNS resolver to avoid potential issues
|
|
|
|
| 43 |
connector = aiohttp.TCPConnector(resolver=resolver)
|
| 44 |
client = Client("https://standarovskid-bot.hf.space/", token=HF_TOKEN)
|
| 45 |
|
|
|
|
|
|
|
| 46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
+
@bot.event
|
| 49 |
+
async def on_ready():
|
| 50 |
+
print(f"Logged in as {bot.user} (ID: {bot.user.id})")
|
| 51 |
+
synced = await bot.tree.sync()
|
| 52 |
+
print(f"Synced commands: {', '.join([s.name for s in synced])}.")
|
| 53 |
+
event.set()
|
| 54 |
+
print("------")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
+
@bot.command()
|
| 57 |
+
async def test(ctx, *, arg):
|
| 58 |
+
await ctx.send(arg)
|
|
|
|
|
|
|
| 59 |
|
| 60 |
+
# running in thread
|
| 61 |
+
def run_bot():
|
| 62 |
+
if not DISCORD_TOKEN:
|
| 63 |
+
print("DISCORD_TOKEN NOT SET")
|
| 64 |
+
event.set()
|
| 65 |
+
else:
|
| 66 |
+
bot.run(DISCORD_TOKEN)
|
| 67 |
+
|
| 68 |
+
threading.Thread(target=run_bot).start()
|
| 69 |
+
|
| 70 |
+
event.wait()
|
| 71 |
+
|
| 72 |
+
with gr.Blocks() as demo:
|
| 73 |
+
gr.Markdown(
|
| 74 |
+
f"""
|
| 75 |
+
# Discord bot of https://standarovskid-bot.hf.space
|
| 76 |
+
"""
|
| 77 |
+
)
|
| 78 |
|
| 79 |
+
demo.launch()
|
|
|