Spaces:
Running
Running
File size: 993 Bytes
e0fa04b |
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 |
import discord
from discord import app_commands
import os
import requests
import asyncio
import aiohttp # Use aiohttp for asynchronous HTTP requests
import gradio as gr # Import Gradio
# --- Environment Variables & Setup ---
DISCORD_BOT_TOKEN = os.getenv("DISCORD_BOT_TOKEN")
# --- Discord Bot Setup ---
intents = discord.Intents.default()
client = discord.Client(intents=intents)
tree = app_commands.CommandTree(client)
# --- Gradio Interface ---
def echo_text(text):
return text
def run_gradio():
gr.Interface(
fn=echo_text,
inputs="text",
outputs="text",
live=False,
title="Minimal Gradio Interface",
).launch(server_name="0.0.0.0", server_port=7860, share=False, show_error=True)
async def main():
bot_task = asyncio.create_task(client.start(DISCORD_BOT_TOKEN))
gradio_task = asyncio.to_thread(run_gradio)
await asyncio.gather(bot_task, gradio_task)
if __name__ == "__main__":
asyncio.run(main())
|