Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import discord
|
2 |
from discord.ext import commands
|
3 |
from gradio_client import Client
|
|
|
4 |
import multiprocessing
|
5 |
import subprocess
|
6 |
import sys
|
@@ -28,23 +29,35 @@ async def on_message(message):
|
|
28 |
if message.channel.id != CHANNEL_ID and not isinstance(message.channel, discord.Thread):
|
29 |
return
|
30 |
|
31 |
-
# Generate image using Gradio client
|
32 |
try:
|
33 |
-
result =
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
42 |
)
|
43 |
-
|
44 |
-
# Send the generated image back to the user
|
45 |
await message.channel.send(file=discord.File(result))
|
|
|
|
|
46 |
except Exception as e:
|
47 |
await message.channel.send(f"An error occurred: {str(e)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
def run_web():
|
50 |
subprocess.run([sys.executable, "web.py"])
|
|
|
1 |
import discord
|
2 |
from discord.ext import commands
|
3 |
from gradio_client import Client
|
4 |
+
import asyncio
|
5 |
import multiprocessing
|
6 |
import subprocess
|
7 |
import sys
|
|
|
29 |
if message.channel.id != CHANNEL_ID and not isinstance(message.channel, discord.Thread):
|
30 |
return
|
31 |
|
|
|
32 |
try:
|
33 |
+
result = await asyncio.wait_for(
|
34 |
+
asyncio.to_thread(
|
35 |
+
gradio_client.predict,
|
36 |
+
prompt=message.content,
|
37 |
+
seed=123,
|
38 |
+
randomize_seed=False,
|
39 |
+
width=1024,
|
40 |
+
height=576,
|
41 |
+
guidance_scale=5,
|
42 |
+
num_inference_steps=30,
|
43 |
+
api_name="/infer_t2i"
|
44 |
+
),
|
45 |
+
timeout=60 # 60 seconds timeout
|
46 |
)
|
|
|
|
|
47 |
await message.channel.send(file=discord.File(result))
|
48 |
+
except asyncio.TimeoutError:
|
49 |
+
await message.channel.send("Image generation timed out. Please try again.")
|
50 |
except Exception as e:
|
51 |
await message.channel.send(f"An error occurred: {str(e)}")
|
52 |
+
print(f"Error in on_message: {str(e)}")
|
53 |
+
|
54 |
+
@bot.event
|
55 |
+
async def on_disconnect():
|
56 |
+
print("Bot disconnected. Attempting to reconnect...")
|
57 |
+
|
58 |
+
@bot.event
|
59 |
+
async def on_resume():
|
60 |
+
print("Bot connection resumed.")
|
61 |
|
62 |
def run_web():
|
63 |
subprocess.run([sys.executable, "web.py"])
|