Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
async test
Browse files
app.py
CHANGED
@@ -843,15 +843,11 @@ def get_member_def(user_id, server):
|
|
843 |
return loop.run_until_complete(get_member_async(user_id, server))
|
844 |
|
845 |
|
846 |
-
def verify_button(profile: gr.OAuthProfile | None, request: gr.Request) -> str:
|
847 |
url_str = str(request.url)
|
848 |
query_params = parse_qs(urlparse(url_str).query)
|
849 |
user_id = query_params.get('user_id', [None])[0]
|
850 |
-
print(f"user_id={user_id}")
|
851 |
token = query_params.get('token', [None])[0]
|
852 |
-
print(f"token={token}")
|
853 |
-
|
854 |
-
print(f"||| token:{token}||| user_id:{user_id}||| profile:{profile}||| user_tokens:{user_tokens}")
|
855 |
|
856 |
if user_id is None or token is None:
|
857 |
return "# β Invalid link. Generate a new link [here](https://discord.com/channels/879548962464493619/900125909984624713) !"
|
@@ -863,13 +859,10 @@ def verify_button(profile: gr.OAuthProfile | None, request: gr.Request) -> str:
|
|
863 |
return f"# β Not logged in with Hugging Face yet."
|
864 |
|
865 |
server = bot.get_guild(879548962464493619)
|
866 |
-
print(f"server={server}")
|
867 |
role = server.get_role(900063512829755413)
|
868 |
|
869 |
-
|
870 |
-
|
871 |
-
|
872 |
-
print(f"member={member}")
|
873 |
verified_date = datetime.now().strftime("%m/%d/%Y, %H:%M:%S")
|
874 |
likes = 0
|
875 |
models = 0
|
@@ -879,38 +872,34 @@ def verify_button(profile: gr.OAuthProfile | None, request: gr.Request) -> str:
|
|
879 |
papers = 0
|
880 |
upvotes = 0
|
881 |
|
882 |
-
# do they have the verified role already?
|
883 |
if role in member.roles:
|
884 |
return (f" β {member} already has has the '{role}' role! To change discord accounts or HF accounts, contact @lunarflu on discord or [email protected]")
|
885 |
|
886 |
-
|
887 |
-
# check if hf_user_name in dataframe:
|
888 |
if profile.username in global_df['hf_user_name'].values:
|
889 |
return (f"The HF account {profile.username} is already verified! To change discord accounts or HF accounts, contact @lunarflu or [email protected]")
|
890 |
|
891 |
-
# check if discord_user_id in dataframe:
|
892 |
lunar = bot.get_user(811235357663297546)
|
893 |
altered_member_id = "L" + str(member.id) + "L"
|
894 |
if altered_member_id in global_df['discord_user_id'].values:
|
895 |
-
|
896 |
hf_user_name = global_df.loc[global_df['discord_user_id'] == altered_member_id, 'hf_user_name'].iloc[0]
|
897 |
|
898 |
if pd.isnull(hf_user_name) or hf_user_name == 'n/a':
|
899 |
-
# empty (no link created yet between discord_user_id and hf_user_name) so we can update
|
900 |
global_df.loc[global_df['discord_user_id'] == altered_member_id, 'hf_user_name'] = profile.username
|
901 |
global_df.loc[global_df['discord_user_id'] == altered_member_id, 'verified_date'] = verified_date
|
902 |
-
|
903 |
if role in member.roles:
|
904 |
-
|
905 |
-
return (f" β
Verification successful! [{member} <---> {profile.username}] π€\n{invite_message}\n{org_link} ")
|
906 |
-
send_lunar_verification_logs_def(lunar, member, profile.username)
|
907 |
-
print(f" β
Verification successful! [{member} <---> {profile.username}] π€")
|
908 |
else:
|
909 |
-
return (f" β The Discord account {member} is already verified! To change discord accounts or HF accounts, contact @lunarflu or [email protected]")
|
910 |
-
print(f"The Discord account {member} is already verified! To change discord accounts or HF accounts, contact @lunarflu or [email protected]")
|
911 |
|
912 |
-
# Remove the token after successful verification
|
913 |
del user_tokens[int(user_id)]
|
|
|
|
|
|
|
|
|
|
|
|
|
914 |
|
915 |
|
916 |
demo = gr.Blocks()
|
@@ -954,7 +943,7 @@ with demo:
|
|
954 |
with gr.Row():
|
955 |
login_button = gr.LoginButton()
|
956 |
m1 = gr.Markdown()
|
957 |
-
demo.load(
|
958 |
|
959 |
def check_login_status():
|
960 |
try:
|
|
|
843 |
return loop.run_until_complete(get_member_async(user_id, server))
|
844 |
|
845 |
|
846 |
+
async def verify_button(profile: gr.OAuthProfile | None, request: gr.Request) -> str:
|
847 |
url_str = str(request.url)
|
848 |
query_params = parse_qs(urlparse(url_str).query)
|
849 |
user_id = query_params.get('user_id', [None])[0]
|
|
|
850 |
token = query_params.get('token', [None])[0]
|
|
|
|
|
|
|
851 |
|
852 |
if user_id is None or token is None:
|
853 |
return "# β Invalid link. Generate a new link [here](https://discord.com/channels/879548962464493619/900125909984624713) !"
|
|
|
859 |
return f"# β Not logged in with Hugging Face yet."
|
860 |
|
861 |
server = bot.get_guild(879548962464493619)
|
|
|
862 |
role = server.get_role(900063512829755413)
|
863 |
|
864 |
+
member = await server.fetch_member(user_id)
|
865 |
+
|
|
|
|
|
866 |
verified_date = datetime.now().strftime("%m/%d/%Y, %H:%M:%S")
|
867 |
likes = 0
|
868 |
models = 0
|
|
|
872 |
papers = 0
|
873 |
upvotes = 0
|
874 |
|
|
|
875 |
if role in member.roles:
|
876 |
return (f" β {member} already has has the '{role}' role! To change discord accounts or HF accounts, contact @lunarflu on discord or [email protected]")
|
877 |
|
|
|
|
|
878 |
if profile.username in global_df['hf_user_name'].values:
|
879 |
return (f"The HF account {profile.username} is already verified! To change discord accounts or HF accounts, contact @lunarflu or [email protected]")
|
880 |
|
|
|
881 |
lunar = bot.get_user(811235357663297546)
|
882 |
altered_member_id = "L" + str(member.id) + "L"
|
883 |
if altered_member_id in global_df['discord_user_id'].values:
|
|
|
884 |
hf_user_name = global_df.loc[global_df['discord_user_id'] == altered_member_id, 'hf_user_name'].iloc[0]
|
885 |
|
886 |
if pd.isnull(hf_user_name) or hf_user_name == 'n/a':
|
|
|
887 |
global_df.loc[global_df['discord_user_id'] == altered_member_id, 'hf_user_name'] = profile.username
|
888 |
global_df.loc[global_df['discord_user_id'] == altered_member_id, 'verified_date'] = verified_date
|
889 |
+
await member.add_roles(role)
|
890 |
if role in member.roles:
|
891 |
+
await lunar.send(f"Verification successful! [{member} <---> {profile.username}] π€ {invite_message}\n{org_link} ")
|
892 |
+
return (f" β
Verification successful! [{member} <---> {profile.username}] π€\n{invite_message}\n{org_link} ")
|
|
|
|
|
893 |
else:
|
894 |
+
return (f" β The Discord account {member} is already verified! To change discord accounts or HF accounts, contact @lunarflu or [email protected]")
|
|
|
895 |
|
|
|
896 |
del user_tokens[int(user_id)]
|
897 |
+
return "# β An unexpected error occurred."
|
898 |
+
|
899 |
+
|
900 |
+
async def gradio_verify_button(profile: gr.OAuthProfile | None, request: gr.Request) -> str:
|
901 |
+
return await verify_button(profile, request)
|
902 |
+
|
903 |
|
904 |
|
905 |
demo = gr.Blocks()
|
|
|
943 |
with gr.Row():
|
944 |
login_button = gr.LoginButton()
|
945 |
m1 = gr.Markdown()
|
946 |
+
demo.load(gradio_verify_button, inputs=None, outputs=m1)
|
947 |
|
948 |
def check_login_status():
|
949 |
try:
|