CryptoScoutv1 commited on
Commit
55a0ace
·
verified ·
1 Parent(s): d9e1f0e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -35
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="/", intents=intents)
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
- ## /echo command to return the llm repsonse ##
63
- @bot.hybrid_command(name="cryptoportfolio", description="Enter text and parameters like this: /cryptoportfolio ")
64
- async def chat(ctx, prompt: str):
65
- if ctx.author.id == bot.user.id:
66
- return
67
- @bot.hybrid_command(name="cryptoportfolio", description="Select a predefined sentence")
68
- async def crypto_portfolio(ctx,
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
- job.result()
88
- response = job.outputs()[-1]
89
- await ctx.send(f"```{truncate_response(response)}```") # Send the LLM response
90
- except QueueError:
91
- await ctx.send("The gradio space powering this bot is really busy! Please try again later!")
92
- except Exception as e:
93
- print(f"{e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
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.")