Spaces:
Runtime error
Runtime error
Update app.py
Browse files11 unmodified lines12131415161718192021223 unmodified lines26272829303132333430 unmodified lines65666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081095 unmodified lines11511611711811912012112212312412512612712812913021 unmodified lines15215315415515615739 unmodified lines19719819920020120220320411 unmodified linesimport gradio_client as grcfrom gradio_client.utils import QueueErrorfrom discord.ext import commandsfrom discord.ext import commandsfrom discord.ext import SlashCommand, SlashContextfrom discord.ext import create_option, create_choiceevent = Event()3 unmodified lineswhile not job.done():await asyncio.sleep(0.2)## GRADIO UI API LINK ##def get_client(session: Optional[str] = None) -> grc.Client:client = grc.Client("https://cryptoscoutv1-discord-chatbot-csv2.hf.space", hf_token=os.getenv("HF_TOKEN"))if session:client.session_hash = sessionreturn client30 unmodified linesthread_to_user = {}## /echo command to return the llm repsonse ### Assuming get_client, wait, truncate_response, QueueError are defined elsewhere in your codebot = commands.Bot(command_prefix="!", intents=discord.Intents.default())@bot.eventasync def on_ready():print(f"We have logged in as {bot.user}")@slash.slash(name="cryptotrend",description="Find top trending cryptocurrencies for a specific period.",options=[create_option(name="period",description="Choose the period",option_type=3, # Type 3 corresponds to STRINGrequired=True,choices=[create_choice(name="Day", value="day"),create_choice(name="Week", value="week"),create_choice(name="Month", value="month")])])async def cryptotrend(ctx: SlashContext, period: str):if ctx.author.id == bot.user.id:returntry:# Process the period parameter to create a suitable promptprompt = f"Find me the top trending cryptocurrencies this {period}"# Acknowledge the command immediatelyawait ctx.send(f"Processing for: {period}")loop = asyncio.get_running_loop()client = await loop.run_in_executor(None, get_client, None)job = client.submit(prompt, api_name="/predict") # Use the prompt with the period parameterawait wait(job)try:5 unmodified linesexcept Exception as e:print(f"{e}")######################## COMMAND ########################################## END ####################################@bot.hybrid_command(name="cshelp", description="Get information on how to use this bot.")async def help_command(ctx):help_message = """21 unmodified linesthreading.Thread(target=run_bot).start()event.wait()if not DISCORD_TOKEN:welcome_message = """39 unmodified lineswith gr.Blocks() as demo:gr.Markdown(f"""# Discord bot of TITLE HERE{welcome_message}""")demo.launch()11 unmodified lines1213141516173 unmodified lines21222324252627282930 unmodified lines60616263646566676869707172737475765 unmodified lines82838485868721 unmodified lines10911011111211311411539 unmodified lines15515615715815916016116211 unmodified linesimport gradio_client as grcfrom gradio_client.utils import QueueErrorevent = Event()3 unmodified lineswhile not job.done():await asyncio.sleep(0.2)def get_client(session: Optional[str] = None) -> grc.Client:client = grc.Client("https://cryptoscoutv1-cs-crewai-researchreport.hf.space", hf_token=os.getenv("HF_TOKEN"))if session:client.session_hash = sessionreturn client30 unmodified linesthread_to_user = {}## /echo command to return the llm repsonse ##@bot.hybrid_command(name="cryptoreport", description="Enter text a Cryptocurrency Symbol or name to build a report - Around 2 Minutes")async def chat(ctx, prompt: str):if ctx.author.id == bot.user.id:returntry:# Acknowledge the command immediately - This is the discord message after the command / is called ##await ctx.send(f"Processing request: {prompt}")loop = asyncio.get_running_loop()client = await loop.run_in_executor(None, get_client, None)job = client.submit(prompt, api_name="/chat") ## /predict can be used for gradio interface ##await wait(job)try:5 unmodified linesexcept Exception as e:print(f"{e}")@bot.hybrid_command(name="cshelp", description="Get information on how to use this bot.")async def help_command(ctx):help_message = """21 unmodified linesthreading.Thread(target=run_bot).start()event.wait()event.wait()if not DISCORD_TOKEN:welcome_message = """39 unmodified lineswith gr.Blocks() as demo:gr.Markdown(f"""# Discord bot of CryptoSearch Portfolio Managment - Discord_CS_PM_Chatbot{welcome_message}""")demo.launch()
app.py+10-52