seawolf2357 commited on
Commit
0902fd4
ยท
verified ยท
1 Parent(s): e552e5d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -9
app.py CHANGED
@@ -28,7 +28,7 @@ async def on_ready():
28
  logging.info(f'{bot.user.name} has connected to Discord!')
29
  try:
30
  # Gradio ์—ฐ๊ฒฐ ํ…Œ์ŠคํŠธ
31
- gradio_client.predict("test", api_name="/infer_t2i")
32
  logging.info("Gradio API connection successful")
33
  except Exception as e:
34
  logging.error(f"Gradio API connection failed: {str(e)}")
@@ -58,10 +58,11 @@ async def on_message(message):
58
  )
59
 
60
  logging.debug(f"Predict result: {result}")
61
-
62
- if isinstance(result, tuple):
63
  file_path = result[0]
64
- await message.channel.send(file=discord.File(file_path))
 
 
65
  except asyncio.TimeoutError:
66
  await message.channel.send("Image generation timed out. Please try again.")
67
  except Exception as e:
@@ -81,20 +82,17 @@ def run_web():
81
  subprocess.run([sys.executable, "web.py"])
82
 
83
  def run_discord_bot():
84
- # ํ™˜๊ฒฝ ๋ณ€์ˆ˜์—์„œ ๋””์Šค์ฝ”๋“œ ํ† ํฐ ์ฝ๊ธฐ
85
  discord_token = os.getenv('DISCORD_TOKEN')
86
  if discord_token:
87
  bot.run(discord_token)
88
  else:
89
  logging.error("Discord token is not set. Please check your environment variables.")
 
90
 
91
  if __name__ == "__main__":
92
- # ์›น ์„œ๋ฒ„๋ฅผ ๋ณ„๋„์˜ ํ”„๋กœ์„ธ์Šค๋กœ ์‹œ์ž‘
93
  web_process = subprocess.Popen([sys.executable, "web.py"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
94
  logging.info("Web server process started.")
95
 
96
- # Discord ๋ด‡ ์‹คํ–‰
97
  run_discord_bot()
98
 
99
- # ์›น ํ”„๋กœ์„ธ์Šค ์ข…๋ฃŒ ๋Œ€๊ธฐ
100
- web_process.wait()
 
28
  logging.info(f'{bot.user.name} has connected to Discord!')
29
  try:
30
  # Gradio ์—ฐ๊ฒฐ ํ…Œ์ŠคํŠธ
31
+ response = gradio_client.predict("test", api_name="/infer_t2i")
32
  logging.info("Gradio API connection successful")
33
  except Exception as e:
34
  logging.error(f"Gradio API connection failed: {str(e)}")
 
58
  )
59
 
60
  logging.debug(f"Predict result: {result}")
61
+ if isinstance(result, tuple) and len(result) > 0:
 
62
  file_path = result[0]
63
+ await message.channel.send(file=discord.File(file_path))
64
+ else:
65
+ logging.error("Unexpected result format from Gradio API")
66
  except asyncio.TimeoutError:
67
  await message.channel.send("Image generation timed out. Please try again.")
68
  except Exception as e:
 
82
  subprocess.run([sys.executable, "web.py"])
83
 
84
  def run_discord_bot():
 
85
  discord_token = os.getenv('DISCORD_TOKEN')
86
  if discord_token:
87
  bot.run(discord_token)
88
  else:
89
  logging.error("Discord token is not set. Please check your environment variables.")
90
+ sys.exit(1) # Exit if token is not set
91
 
92
  if __name__ == "__main__":
 
93
  web_process = subprocess.Popen([sys.executable, "web.py"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
94
  logging.info("Web server process started.")
95
 
 
96
  run_discord_bot()
97
 
98
+ web_process.wait() # Ensure the web process completes