lunarflu HF staff commited on
Commit
b85b6b9
·
verified ·
1 Parent(s): ac9050d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -6
app.py CHANGED
@@ -5,6 +5,7 @@ from urllib.parse import urlparse, parse_qs
5
  import discord
6
  from discord.ext import commands
7
  import secrets
 
8
 
9
  # Discord bot -----------------------------------------------------------------------------------------------
10
  intents = discord.Intents.all()
@@ -30,11 +31,6 @@ async def sendlink(ctx, user: discord.User):
30
  unique_link = f"{GRADIO_APP_URL}?user_id={user.id}&token={unique_string}"
31
  await user.send(f"Click the link to sign in with Hugging Face: {unique_link}")
32
 
33
- def run_bot():
34
- bot.run(DISCORD_TOKEN)
35
-
36
- threading.Thread(target=run_bot).start()
37
-
38
  # Gradio ------------------------------------------------------------------------------------------------------------
39
  def validate_link(request: gr.Request) -> bool:
40
  referer = request.headers.get('Referer', '')
@@ -93,4 +89,15 @@ with gr.Blocks() as demo:
93
 
94
  login_button.click(check_login_wrapper, inputs=None, outputs=m1)
95
 
96
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
5
  import discord
6
  from discord.ext import commands
7
  import secrets
8
+ import asyncio
9
 
10
  # Discord bot -----------------------------------------------------------------------------------------------
11
  intents = discord.Intents.all()
 
31
  unique_link = f"{GRADIO_APP_URL}?user_id={user.id}&token={unique_string}"
32
  await user.send(f"Click the link to sign in with Hugging Face: {unique_link}")
33
 
 
 
 
 
 
34
  # Gradio ------------------------------------------------------------------------------------------------------------
35
  def validate_link(request: gr.Request) -> bool:
36
  referer = request.headers.get('Referer', '')
 
89
 
90
  login_button.click(check_login_wrapper, inputs=None, outputs=m1)
91
 
92
+ def run_gradio():
93
+ demo.launch()
94
+
95
+ # Run the Gradio app in a separate thread
96
+ gradio_thread = threading.Thread(target=run_gradio)
97
+ gradio_thread.start()
98
+
99
+ # Run the Discord bot on the main thread
100
+ if DISCORD_TOKEN:
101
+ bot.run(DISCORD_TOKEN)
102
+ else:
103
+ print("Discord token not found. Please set the DISCORD_TOKEN environment variable.")