lunarflu HF staff commited on
Commit
5166981
·
verified ·
1 Parent(s): b85b6b9
Files changed (1) hide show
  1. app.py +8 -17
app.py CHANGED
@@ -5,7 +5,6 @@ from urllib.parse import urlparse, parse_qs
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,10 +30,14 @@ async def sendlink(ctx, user: discord.User):
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', '')
37
- url_str = str(referer)
38
  query_params = parse_qs(urlparse(url_str).query)
39
  user_id = query_params.get('user_id', [None])[0]
40
  token = query_params.get('token', [None])[0]
@@ -51,8 +54,7 @@ def hello(profile: gr.OAuthProfile | None, request: gr.Request) -> str:
51
  if not validate_link(request):
52
  return "❌ Invalid link. Please use the link provided by the bot."
53
 
54
- referer = request.headers.get('Referer', '')
55
- url_str = str(referer)
56
  query_params = parse_qs(urlparse(url_str).query)
57
  user_id = query_params.get('user_id', [None])[0]
58
 
@@ -89,15 +91,4 @@ with gr.Blocks() as demo:
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.")
 
5
  import discord
6
  from discord.ext import commands
7
  import secrets
 
8
 
9
  # Discord bot -----------------------------------------------------------------------------------------------
10
  intents = discord.Intents.all()
 
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
+ url_str = str(request.url)
 
41
  query_params = parse_qs(urlparse(url_str).query)
42
  user_id = query_params.get('user_id', [None])[0]
43
  token = query_params.get('token', [None])[0]
 
54
  if not validate_link(request):
55
  return "❌ Invalid link. Please use the link provided by the bot."
56
 
57
+ url_str = str(request.url)
 
58
  query_params = parse_qs(urlparse(url_str).query)
59
  user_id = query_params.get('user_id', [None])[0]
60
 
 
91
 
92
  login_button.click(check_login_wrapper, inputs=None, outputs=m1)
93
 
94
+ demo.launch()