CryptoScoutv1 commited on
Commit
1b994cd
·
verified ·
1 Parent(s): 8f7bcd0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -52
app.py CHANGED
@@ -12,11 +12,6 @@ from discord.utils import oauth_url
12
 
13
  import gradio_client as grc
14
  from gradio_client.utils import QueueError
15
- from discord.ext import commands
16
- from discord.ext import commands
17
- from discord.ext import SlashCommand, SlashContext
18
- from discord.ext import create_option, create_choice
19
-
20
 
21
  event = Event()
22
 
@@ -26,9 +21,9 @@ async def wait(job):
26
  while not job.done():
27
  await asyncio.sleep(0.2)
28
 
29
- ## GRADIO UI API LINK ##
30
  def get_client(session: Optional[str] = None) -> grc.Client:
31
- client = grc.Client("https://cryptoscoutv1-discord-chatbot-csv2.hf.space", hf_token=os.getenv("HF_TOKEN"))
32
  if session:
33
  client.session_hash = session
34
  return client
@@ -65,45 +60,17 @@ thread_to_client = {}
65
  thread_to_user = {}
66
 
67
  ## /echo command to return the llm repsonse ##
68
- # Assuming get_client, wait, truncate_response, QueueError are defined elsewhere in your code
69
-
70
- bot = commands.Bot(command_prefix="!", intents=discord.Intents.default())
71
-
72
- @bot.event
73
- async def on_ready():
74
- print(f"We have logged in as {bot.user}")
75
-
76
- @slash.slash(
77
- name="cryptotrend",
78
- description="Find top trending cryptocurrencies for a specific period.",
79
- options=[
80
- create_option(
81
- name="period",
82
- description="Choose the period",
83
- option_type=3, # Type 3 corresponds to STRING
84
- required=True,
85
- choices=[
86
- create_choice(name="Day", value="day"),
87
- create_choice(name="Week", value="week"),
88
- create_choice(name="Month", value="month")
89
- ]
90
- )
91
- ]
92
- )
93
- async def cryptotrend(ctx: SlashContext, period: str):
94
  if ctx.author.id == bot.user.id:
95
  return
96
-
97
  try:
98
- # Process the period parameter to create a suitable prompt
99
- prompt = f"Find me the top trending cryptocurrencies this {period}"
100
-
101
- # Acknowledge the command immediately
102
- await ctx.send(f"Processing for: {period}")
103
 
104
  loop = asyncio.get_running_loop()
105
  client = await loop.run_in_executor(None, get_client, None)
106
- job = client.submit(prompt, api_name="/predict") # Use the prompt with the period parameter
107
  await wait(job)
108
 
109
  try:
@@ -115,16 +82,6 @@ async def cryptotrend(ctx: SlashContext, period: str):
115
  except Exception as e:
116
  print(f"{e}")
117
 
118
-
119
-
120
-
121
- ######################## COMMAND #################################
122
-
123
-
124
-
125
-
126
- ######### END ####################################
127
-
128
  @bot.hybrid_command(name="cshelp", description="Get information on how to use this bot.")
129
  async def help_command(ctx):
130
  help_message = """
@@ -152,6 +109,7 @@ def run_bot():
152
 
153
  threading.Thread(target=run_bot).start()
154
 
 
155
  event.wait()
156
  if not DISCORD_TOKEN:
157
  welcome_message = """
@@ -197,8 +155,8 @@ else:
197
  with gr.Blocks() as demo:
198
  gr.Markdown(
199
  f"""
200
- # Discord bot of TITLE HERE
201
  {welcome_message}
202
  """
203
  )
204
- demo.launch()
 
12
 
13
  import gradio_client as grc
14
  from gradio_client.utils import QueueError
 
 
 
 
 
15
 
16
  event = Event()
17
 
 
21
  while not job.done():
22
  await asyncio.sleep(0.2)
23
 
24
+
25
  def get_client(session: Optional[str] = None) -> grc.Client:
26
+ client = grc.Client("https://cryptoscoutv1-cs-crewai-researchreport.hf.space", hf_token=os.getenv("HF_TOKEN"))
27
  if session:
28
  client.session_hash = session
29
  return client
 
60
  thread_to_user = {}
61
 
62
  ## /echo command to return the llm repsonse ##
63
+ @bot.hybrid_command(name="cryptoreport", description="Enter text a Cryptocurrency Symbol or name to build a report - Around 2 Minutes")
64
+ async def chat(ctx, prompt: str):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  if ctx.author.id == bot.user.id:
66
  return
 
67
  try:
68
+ # Acknowledge the command immediately - This is the discord message after the command / is called ##
69
+ await ctx.send(f"Processing request: {prompt}")
 
 
 
70
 
71
  loop = asyncio.get_running_loop()
72
  client = await loop.run_in_executor(None, get_client, None)
73
+ job = client.submit(prompt, api_name="/chat") ## /predict can be used for gradio interface ##
74
  await wait(job)
75
 
76
  try:
 
82
  except Exception as e:
83
  print(f"{e}")
84
 
 
 
 
 
 
 
 
 
 
 
85
  @bot.hybrid_command(name="cshelp", description="Get information on how to use this bot.")
86
  async def help_command(ctx):
87
  help_message = """
 
109
 
110
  threading.Thread(target=run_bot).start()
111
 
112
+ event.wait()
113
  event.wait()
114
  if not DISCORD_TOKEN:
115
  welcome_message = """
 
155
  with gr.Blocks() as demo:
156
  gr.Markdown(
157
  f"""
158
+ # Discord bot of CryptoSearch Portfolio Managment - Discord_CS_PM_Chatbot
159
  {welcome_message}
160
  """
161
  )
162
+ demo.launch()