Abhishek Thakur
commited on
Commit
·
7f36990
1
Parent(s):
b2c9521
fix
Browse files- competitions/create.py +5 -30
- competitions/utils.py +1 -1
competitions/create.py
CHANGED
|
@@ -5,7 +5,7 @@ import gradio as gr
|
|
| 5 |
from huggingface_hub import HfApi
|
| 6 |
from loguru import logger
|
| 7 |
|
| 8 |
-
from competitions.utils import
|
| 9 |
|
| 10 |
|
| 11 |
COMPETITION_DESC = """Sample competition description"""
|
|
@@ -86,40 +86,15 @@ def check_if_user_can_create_competition(user_token):
|
|
| 86 |
:param user_token: the user's token
|
| 87 |
:return: True if the user can create a competition, False otherwise
|
| 88 |
"""
|
| 89 |
-
user_info =
|
| 90 |
-
return_msg = None
|
| 91 |
-
if "error" in user_info:
|
| 92 |
-
return_msg = "Invalid token. You can find your HF token here: https://huggingface.co/settings/tokens"
|
| 93 |
-
|
| 94 |
-
elif user_info["auth"]["accessToken"]["role"] not in ("write", "fineGrained"):
|
| 95 |
-
return_msg = "Please provide a token with write access"
|
| 96 |
-
|
| 97 |
-
if return_msg is not None:
|
| 98 |
-
return gr.Dropdown()
|
| 99 |
-
|
| 100 |
valid_orgs = user_info["orgs"]
|
| 101 |
|
| 102 |
-
if len(valid_orgs) == 0:
|
| 103 |
-
return_msg = """You are not a member of any organization with a valid payment method.
|
| 104 |
-
Please add a valid payment method for your organization in order to create competitions."""
|
| 105 |
-
return gr.Dropdown()
|
| 106 |
-
|
| 107 |
-
valid_orgs = [org for org in valid_orgs if org["roleInOrg"] in ("admin", "write")]
|
| 108 |
-
|
| 109 |
-
if len(valid_orgs) == 0:
|
| 110 |
-
return_msg = """You dont have write access for any organization.
|
| 111 |
-
Please contact your organization's admin to add you as a member with write privilages."""
|
| 112 |
-
return gr.Dropdown()
|
| 113 |
-
|
| 114 |
-
valid_entities = {org["name"]: org["id"] for org in valid_orgs}
|
| 115 |
-
|
| 116 |
return gr.Dropdown(
|
| 117 |
-
choices=
|
| 118 |
visible=True,
|
| 119 |
-
value=
|
| 120 |
)
|
| 121 |
-
|
| 122 |
-
|
| 123 |
def _create_readme(competition_name):
|
| 124 |
_readme = "---\n"
|
| 125 |
_readme += f"title: {competition_name}\n"
|
|
|
|
| 5 |
from huggingface_hub import HfApi
|
| 6 |
from loguru import logger
|
| 7 |
|
| 8 |
+
from competitions.utils import token_information
|
| 9 |
|
| 10 |
|
| 11 |
COMPETITION_DESC = """Sample competition description"""
|
|
|
|
| 86 |
:param user_token: the user's token
|
| 87 |
:return: True if the user can create a competition, False otherwise
|
| 88 |
"""
|
| 89 |
+
user_info = token_information(user_token)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
valid_orgs = user_info["orgs"]
|
| 91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
return gr.Dropdown(
|
| 93 |
+
choices=valid_orgs,
|
| 94 |
visible=True,
|
| 95 |
+
value=valid_orgs[0],
|
| 96 |
)
|
| 97 |
+
a
|
|
|
|
| 98 |
def _create_readme(competition_name):
|
| 99 |
_readme = "---\n"
|
| 100 |
_readme += f"title: {competition_name}\n"
|
competitions/utils.py
CHANGED
|
@@ -94,7 +94,7 @@ def user_authentication(request: Request):
|
|
| 94 |
return None
|
| 95 |
|
| 96 |
|
| 97 |
-
def
|
| 98 |
if token.startswith("hf_oauth"):
|
| 99 |
_api_url = HF_URL + "/oauth/userinfo"
|
| 100 |
else:
|
|
|
|
| 94 |
return None
|
| 95 |
|
| 96 |
|
| 97 |
+
def user_authentication_dep(token, return_raw=False):
|
| 98 |
if token.startswith("hf_oauth"):
|
| 99 |
_api_url = HF_URL + "/oauth/userinfo"
|
| 100 |
else:
|