File size: 1,532 Bytes
ccec886
ddbc9ac
 
 
 
afc2013
 
ddbc9ac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91bbd67
ea0fbdd
ddbc9ac
 
 
 
 
 
 
 
 
 
 
 
 
5dd8b6d
91bbd67
ea0fbdd
91bbd67
afc2013
e2ff7c2
afc2013
99e1d75
c8f7bea
f37ec25
 
3110228
e464d27
ddbc9ac
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import gradio as gr
import os
from urllib.parse import urlparse, parse_qs
import discord
from discord.ext import commands



# discord bot -----------------------------------------------------------------------------------------------
intents = discord.Intents.all()
bot = commands.Bot(command_prefix="!", intents=intents)
GRADIO_APP_URL = "https://lunarflu-gradio-oauth2"
DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)


@bot.event
async def on_ready():
    print(f'Logged in as {bot.user}')


@bot.command()
async def sendlink(ctx, user: discord.User):
    if ctx.author.id == 811235357663297546:
        unique_link = f"{GRADIO_APP_URL}?user_id={user.id}"
        await user.send(f"Click the link to sign in with Hugging Face: {unique_link}")


def run_bot():
    bot.run(DISCORD_TOKEN)
threading.Thread(target=run_bot).start()


#gradio------------------------------------------------------------------------------------------------------------
def hello(profile: gr.OAuthProfile | None, request: gr.Request) -> str:
    query_params = parse_qs(urlparse(request.url).query)
    user_id = query_params.get('user_id', [None])[0]
    if profile is None:
        return f"❌ Not logged in. User ID: {user_id}"
    return f"✅ Successfully logged in as {profile.username}. User ID: {user_id}"




with gr.Blocks() as demo:
    gr.Markdown(
        "# Gradio OAuth Space"
    )
    gr.LoginButton()
    # ^ add a login button to the Space
    m1 = gr.Markdown()
    demo.load(hello, inputs=None, outputs=m1)

demo.launch()