Update app.py
Browse files
app.py
CHANGED
@@ -9,7 +9,6 @@ import gradio as gr
|
|
9 |
from discord import Permissions
|
10 |
from discord.ext import commands
|
11 |
from discord.utils import oauth_url
|
12 |
-
from discord.ext import Option
|
13 |
import gradio_client as grc
|
14 |
from gradio_client.utils import QueueError
|
15 |
|
@@ -35,10 +34,11 @@ def truncate_response(response: str) -> str:
|
|
35 |
else:
|
36 |
return response
|
37 |
|
|
|
|
|
38 |
intents = discord.Intents.default()
|
39 |
intents.message_content = True
|
40 |
-
bot = commands.Bot(command_prefix="
|
41 |
-
|
42 |
|
43 |
|
44 |
## BOT COMMANDS ##
|
@@ -56,41 +56,37 @@ async def on_ready():
|
|
56 |
url = oauth_url(bot.user.id, permissions=permissions)
|
57 |
print(f"Add this bot to your server by clicking this link: {url}")
|
58 |
|
59 |
-
thread_to_client = {}
|
60 |
-
thread_to_user = {}
|
61 |
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
selection: Option(str,
|
70 |
-
"Select an option",
|
71 |
-
choices=[
|
72 |
-
"Find the top performing cryptocurrencies of the day.",
|
73 |
-
"Find the top performing cryptocurrencies of the week.",
|
74 |
-
"Find the top performing cryptocurrencies of the month."
|
75 |
-
])):
|
76 |
-
try:
|
77 |
-
# Acknowledge the command
|
78 |
-
await ctx.send(f"Processing request: {selection}")
|
79 |
-
|
80 |
-
# Simulated external processing
|
81 |
-
loop = asyncio.get_running_loop()
|
82 |
-
client = await loop.run_in_executor(None, get_client, None)
|
83 |
-
job = client.submit(selection, api_name="/predict")
|
84 |
-
await wait(job)
|
85 |
|
|
|
86 |
try:
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
|
95 |
|
96 |
@bot.hybrid_command(name="cshelp", description="Get information on how to use this bot.")
|
|
|
9 |
from discord import Permissions
|
10 |
from discord.ext import commands
|
11 |
from discord.utils import oauth_url
|
|
|
12 |
import gradio_client as grc
|
13 |
from gradio_client.utils import QueueError
|
14 |
|
|
|
34 |
else:
|
35 |
return response
|
36 |
|
37 |
+
thread_to_client = {}
|
38 |
+
thread_to_user = {}
|
39 |
intents = discord.Intents.default()
|
40 |
intents.message_content = True
|
41 |
+
bot = commands.Bot(command_prefix="!", intents=intents)
|
|
|
42 |
|
43 |
|
44 |
## BOT COMMANDS ##
|
|
|
56 |
url = oauth_url(bot.user.id, permissions=permissions)
|
57 |
print(f"Add this bot to your server by clicking this link: {url}")
|
58 |
|
|
|
|
|
59 |
|
60 |
+
@bot.command(name="cryptoportfolio", help="Select a predefined sentence by typing it")
|
61 |
+
async def crypto_portfolio(ctx, *, input_text: str):
|
62 |
+
valid_choices = [
|
63 |
+
"Find the top performing cryptocurrencies of the day.",
|
64 |
+
"Find the top performing cryptocurrencies of the week.",
|
65 |
+
"Find the top performing cryptocurrencies of the month."
|
66 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
+
if input_text in valid_choices:
|
69 |
try:
|
70 |
+
# Acknowledge the command
|
71 |
+
await ctx.send(f"Processing request: {input_text}")
|
72 |
+
|
73 |
+
# Simulated external processing (replace this with your actual logic)
|
74 |
+
loop = asyncio.get_running_loop()
|
75 |
+
client = await loop.run_in_executor(None, get_client, None)
|
76 |
+
job = client.submit(input_text, api_name="/predict")
|
77 |
+
await wait(job)
|
78 |
+
|
79 |
+
try:
|
80 |
+
job.result()
|
81 |
+
response = job.outputs()[-1]
|
82 |
+
await ctx.send(f"```{truncate_response(response)}```") # Send the LLM response
|
83 |
+
except QueueError:
|
84 |
+
await ctx.send("The gradio space powering this bot is really busy! Please try again later!")
|
85 |
+
except Exception as e:
|
86 |
+
print(f"{e}")
|
87 |
+
else:
|
88 |
+
# Handle invalid input
|
89 |
+
await ctx.send("Invalid input. Please select one of the predefined sentences.")
|
90 |
|
91 |
|
92 |
@bot.hybrid_command(name="cshelp", description="Get information on how to use this bot.")
|