Spaces:
Running
Running
big oauth test
Browse files
app.py
CHANGED
@@ -1,31 +1,55 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
|
|
|
|
|
|
3 |
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
|
15 |
|
16 |
with gr.Blocks() as demo:
|
17 |
gr.Markdown(
|
18 |
"# Gradio OAuth Space"
|
19 |
-
"\n\nThis Space is a demo for the **Sign in with Hugging Face** feature. "
|
20 |
-
"Duplicate this Space to get started."
|
21 |
-
"\n\nFor more details, check out:"
|
22 |
-
"\n- https://www.gradio.app/guides/sharing-your-app#o-auth-login-via-hugging-face"
|
23 |
-
"\n- https://huggingface.co/docs/hub/spaces-oauth"
|
24 |
)
|
25 |
gr.LoginButton()
|
26 |
# ^ add a login button to the Space
|
27 |
m1 = gr.Markdown()
|
28 |
-
m2 = gr.Markdown()
|
29 |
demo.load(hello, inputs=None, outputs=m1)
|
30 |
|
31 |
demo.launch()
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import os
|
3 |
+
from urllib.parse import urlparse, parse_qs
|
4 |
+
import discord
|
5 |
+
from discord.ext import commands
|
6 |
|
7 |
|
8 |
+
|
9 |
+
# discord bot -----------------------------------------------------------------------------------------------
|
10 |
+
intents = discord.Intents.all()
|
11 |
+
bot = commands.Bot(command_prefix="!", intents=intents)
|
12 |
+
GRADIO_APP_URL = "https://lunarflu-gradio-oauth2"
|
13 |
+
DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)
|
14 |
+
|
15 |
+
|
16 |
+
@bot.event
|
17 |
+
async def on_ready():
|
18 |
+
print(f'Logged in as {bot.user}')
|
19 |
+
|
20 |
+
|
21 |
+
@bot.command()
|
22 |
+
async def sendlink(ctx, user: discord.User):
|
23 |
+
if ctx.author.id == 811235357663297546:
|
24 |
+
unique_link = f"{GRADIO_APP_URL}?user_id={user.id}"
|
25 |
+
await user.send(f"Click the link to sign in with Hugging Face: {unique_link}")
|
26 |
|
27 |
|
28 |
+
def run_bot():
|
29 |
+
bot.run(DISCORD_TOKEN)
|
30 |
+
threading.Thread(target=run_bot).start()
|
31 |
+
|
32 |
+
|
33 |
+
#gradio------------------------------------------------------------------------------------------------------------
|
34 |
+
def hello(profile: gr.OAuthProfile | None, request: gr.Request) -> str:
|
35 |
+
query_params = parse_qs(urlparse(request.url).query)
|
36 |
+
user_id = query_params.get('user_id', [None])[0]
|
37 |
+
if profile is None:
|
38 |
+
return f"❌ Not logged in. User ID: {user_id}"
|
39 |
+
return f"✅ Successfully logged in as {profile.username}. User ID: {user_id}"
|
40 |
+
|
41 |
|
42 |
|
43 |
|
44 |
with gr.Blocks() as demo:
|
45 |
gr.Markdown(
|
46 |
"# Gradio OAuth Space"
|
|
|
|
|
|
|
|
|
|
|
47 |
)
|
48 |
gr.LoginButton()
|
49 |
# ^ add a login button to the Space
|
50 |
m1 = gr.Markdown()
|
|
|
51 |
demo.load(hello, inputs=None, outputs=m1)
|
52 |
|
53 |
demo.launch()
|
54 |
+
|
55 |
+
|