artintel235 commited on
Commit
e0fa04b
·
verified ·
1 Parent(s): 0703306

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import discord
2
+ from discord import app_commands
3
+ import os
4
+ import requests
5
+ import asyncio
6
+ import aiohttp # Use aiohttp for asynchronous HTTP requests
7
+ import gradio as gr # Import Gradio
8
+
9
+ # --- Environment Variables & Setup ---
10
+ DISCORD_BOT_TOKEN = os.getenv("DISCORD_BOT_TOKEN")
11
+
12
+ # --- Discord Bot Setup ---
13
+ intents = discord.Intents.default()
14
+ client = discord.Client(intents=intents)
15
+ tree = app_commands.CommandTree(client)
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+ # --- Gradio Interface ---
29
+ def echo_text(text):
30
+ return text
31
+
32
+
33
+ def run_gradio():
34
+ gr.Interface(
35
+ fn=echo_text,
36
+ inputs="text",
37
+ outputs="text",
38
+ live=False,
39
+ title="Minimal Gradio Interface",
40
+ ).launch(server_name="0.0.0.0", server_port=7860, share=False, show_error=True)
41
+
42
+ async def main():
43
+ bot_task = asyncio.create_task(client.start(DISCORD_BOT_TOKEN))
44
+ gradio_task = asyncio.to_thread(run_gradio)
45
+
46
+ await asyncio.gather(bot_task, gradio_task)
47
+
48
+
49
+ if __name__ == "__main__":
50
+ asyncio.run(main())
51
+
52
+