Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -36,25 +36,17 @@ def run_bot():
|
|
36 |
threading.Thread(target=run_bot).start()
|
37 |
|
38 |
# Gradio ------------------------------------------------------------------------------------------------------------
|
39 |
-
def
|
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]
|
44 |
|
45 |
if user_id is None or token is None:
|
46 |
-
return
|
47 |
|
48 |
if int(user_id) not in user_tokens or user_tokens[int(user_id)] != token:
|
49 |
-
return
|
50 |
-
|
51 |
-
return True, user_id, token
|
52 |
-
|
53 |
-
def hello(profile: gr.OAuthProfile | None, request: gr.Request) -> str:
|
54 |
-
is_valid, user_id, token = validate_link(request)
|
55 |
-
|
56 |
-
if not is_valid:
|
57 |
-
return "❌ Invalid link or expired token."
|
58 |
|
59 |
if profile is None:
|
60 |
return f"❌ Not logged in. User ID: {user_id}"
|
@@ -63,16 +55,8 @@ def hello(profile: gr.OAuthProfile | None, request: gr.Request) -> str:
|
|
63 |
|
64 |
with gr.Blocks() as demo:
|
65 |
gr.Markdown("# Gradio OAuth Space")
|
|
|
66 |
m1 = gr.Markdown()
|
67 |
-
|
68 |
-
def conditional_login_button(request: gr.Request):
|
69 |
-
is_valid, _, _ = validate_link(request)
|
70 |
-
if is_valid:
|
71 |
-
return gr.LoginButton()
|
72 |
-
else:
|
73 |
-
return gr.Markdown("❌ Invalid link or expired token.")
|
74 |
-
|
75 |
-
login_button = conditional_login_button(gr.Request())
|
76 |
demo.load(hello, inputs=None, outputs=m1)
|
77 |
|
78 |
def check_login_status():
|
@@ -88,7 +72,6 @@ with gr.Blocks() as demo:
|
|
88 |
else:
|
89 |
return f"Logged in as {session.get('username', 'Unknown')}"
|
90 |
|
91 |
-
|
92 |
-
login_button.click(check_login_wrapper, inputs=None, outputs=m1)
|
93 |
|
94 |
-
demo.launch()
|
|
|
36 |
threading.Thread(target=run_bot).start()
|
37 |
|
38 |
# Gradio ------------------------------------------------------------------------------------------------------------
|
39 |
+
def hello(profile: gr.OAuthProfile | None, request: gr.Request) -> str:
|
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]
|
44 |
|
45 |
if user_id is None or token is None:
|
46 |
+
return "❌ Invalid link. Missing user_id or token."
|
47 |
|
48 |
if int(user_id) not in user_tokens or user_tokens[int(user_id)] != token:
|
49 |
+
return "❌ Invalid or expired token."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
if profile is None:
|
52 |
return f"❌ Not logged in. User ID: {user_id}"
|
|
|
55 |
|
56 |
with gr.Blocks() as demo:
|
57 |
gr.Markdown("# Gradio OAuth Space")
|
58 |
+
login_button = gr.LoginButton()
|
59 |
m1 = gr.Markdown()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
demo.load(hello, inputs=None, outputs=m1)
|
61 |
|
62 |
def check_login_status():
|
|
|
72 |
else:
|
73 |
return f"Logged in as {session.get('username', 'Unknown')}"
|
74 |
|
75 |
+
login_button.click(check_login_wrapper, inputs=None, outputs=m1)
|
|
|
76 |
|
77 |
+
demo.launch()
|