Update app.py
Browse files
app.py
CHANGED
|
@@ -65,20 +65,31 @@ async def chat(ctx, prompt: str):
|
|
| 65 |
if ctx.author.id == bot.user.id:
|
| 66 |
return
|
| 67 |
try:
|
| 68 |
-
|
| 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="/predict")
|
| 74 |
await wait(job)
|
| 75 |
|
| 76 |
try:
|
| 77 |
job.result()
|
| 78 |
response = job.outputs()[-1]
|
| 79 |
-
await
|
|
|
|
|
|
|
| 80 |
except QueueError:
|
| 81 |
-
await
|
|
|
|
|
|
|
|
|
|
| 82 |
except Exception as e:
|
| 83 |
print(f"{e}")
|
| 84 |
|
|
|
|
| 65 |
if ctx.author.id == bot.user.id:
|
| 66 |
return
|
| 67 |
try:
|
| 68 |
+
message = await ctx.send("Creating thread...")
|
|
|
|
| 69 |
|
| 70 |
+
# User triggered bot via !echo
|
| 71 |
+
if ctx.message.content:
|
| 72 |
+
prompt = ctx.message.content.replace(
|
| 73 |
+
f"{bot.command_prefix}echo", ""
|
| 74 |
+
).strip()
|
| 75 |
+
|
| 76 |
+
thread = await message.create_thread(name=prompt)
|
| 77 |
loop = asyncio.get_running_loop()
|
| 78 |
client = await loop.run_in_executor(None, get_client, None)
|
| 79 |
+
job = client.submit(prompt, api_name="/predict")
|
| 80 |
await wait(job)
|
| 81 |
|
| 82 |
try:
|
| 83 |
job.result()
|
| 84 |
response = job.outputs()[-1]
|
| 85 |
+
await thread.send(truncate_response(response))
|
| 86 |
+
thread_to_client[thread.id] = client
|
| 87 |
+
thread_to_user[thread.id] = ctx.author.id
|
| 88 |
except QueueError:
|
| 89 |
+
await thread.send(
|
| 90 |
+
"The gradio space powering this bot is really busy! Please try again later!"
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
except Exception as e:
|
| 94 |
print(f"{e}")
|
| 95 |
|