Abhishek Thakur
commited on
Commit
·
b2c9521
1
Parent(s):
2331047
update
Browse files- competitions/create.py +6 -5
- 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,13 +86,14 @@ 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 |
return_msg = None
|
| 90 |
-
|
| 91 |
-
user_info = token_information(user_token)
|
| 92 |
-
except Exception as e:
|
| 93 |
-
logger.error(e)
|
| 94 |
return_msg = "Invalid token. You can find your HF token here: https://huggingface.co/settings/tokens"
|
| 95 |
|
|
|
|
|
|
|
|
|
|
| 96 |
if return_msg is not None:
|
| 97 |
return gr.Dropdown()
|
| 98 |
|
|
|
|
| 5 |
from huggingface_hub import HfApi
|
| 6 |
from loguru import logger
|
| 7 |
|
| 8 |
+
from competitions.utils import user_authentication_create
|
| 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 = user_authentication_create(user_token, return_raw=True)
|
| 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 |
|
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_create(token, return_raw=False):
|
| 98 |
if token.startswith("hf_oauth"):
|
| 99 |
_api_url = HF_URL + "/oauth/userinfo"
|
| 100 |
else:
|