Spaces:
Running
Running
asyncio
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
-
import
|
4 |
from urllib.parse import urlparse, parse_qs
|
5 |
import discord
|
6 |
from discord.ext import commands
|
@@ -12,7 +12,6 @@ bot = commands.Bot(command_prefix="!", intents=intents)
|
|
12 |
GRADIO_APP_URL = "https://huggingface.co/spaces/lunarflu/gradio-oauth2"
|
13 |
DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)
|
14 |
|
15 |
-
|
16 |
# Dictionary to store user IDs and their corresponding unique strings
|
17 |
user_tokens = {}
|
18 |
|
@@ -31,10 +30,8 @@ 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 |
-
def run_bot():
|
35 |
-
bot.
|
36 |
-
|
37 |
-
threading.Thread(target=run_bot).start()
|
38 |
|
39 |
# Gradio ------------------------------------------------------------------------------------------------------------
|
40 |
async def hello(profile: gr.OAuthProfile | None, request: gr.Request) -> str:
|
@@ -60,30 +57,38 @@ async def hello(profile: gr.OAuthProfile | None, request: gr.Request) -> str:
|
|
60 |
|
61 |
return f"# ✅ Successfully logged in as {profile.username}. Discord username: {user.name}"
|
62 |
|
63 |
-
|
64 |
-
with gr.
|
65 |
-
gr.
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
+
import asyncio
|
4 |
from urllib.parse import urlparse, parse_qs
|
5 |
import discord
|
6 |
from discord.ext import commands
|
|
|
12 |
GRADIO_APP_URL = "https://huggingface.co/spaces/lunarflu/gradio-oauth2"
|
13 |
DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)
|
14 |
|
|
|
15 |
# Dictionary to store user IDs and their corresponding unique strings
|
16 |
user_tokens = {}
|
17 |
|
|
|
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 |
+
async def run_bot():
|
34 |
+
await bot.start(DISCORD_TOKEN)
|
|
|
|
|
35 |
|
36 |
# Gradio ------------------------------------------------------------------------------------------------------------
|
37 |
async def hello(profile: gr.OAuthProfile | None, request: gr.Request) -> str:
|
|
|
57 |
|
58 |
return f"# ✅ Successfully logged in as {profile.username}. Discord username: {user.name}"
|
59 |
|
60 |
+
def launch_gradio():
|
61 |
+
with gr.Blocks() as demo:
|
62 |
+
with gr.Row():
|
63 |
+
gr.Markdown("# Discord Verification Space")
|
64 |
+
with gr.Row():
|
65 |
+
login_button = gr.LoginButton()
|
66 |
+
|
67 |
+
m1 = gr.Markdown()
|
68 |
+
demo.load(hello, inputs=None, outputs=m1)
|
69 |
+
|
70 |
+
def check_login_status():
|
71 |
+
try:
|
72 |
+
return login_button.get_session().get("oauth_info", None)
|
73 |
+
except AttributeError:
|
74 |
+
return None
|
75 |
+
|
76 |
+
def check_login_wrapper():
|
77 |
+
session = check_login_status()
|
78 |
+
if session is None:
|
79 |
+
return "Not logged in."
|
80 |
+
else:
|
81 |
+
return f"Logged in as {session.get('username', 'Unknown')}"
|
82 |
+
|
83 |
+
login_button.click(check_login_wrapper, inputs=None, outputs=m1)
|
84 |
+
|
85 |
+
demo.launch()
|
86 |
+
|
87 |
+
async def main():
|
88 |
+
await asyncio.gather(
|
89 |
+
run_bot(),
|
90 |
+
asyncio.to_thread(launch_gradio)
|
91 |
+
)
|
92 |
+
|
93 |
+
if __name__ == "__main__":
|
94 |
+
asyncio.run(main())
|