File size: 690 Bytes
3e25ded
 
5f72bf5
3e25ded
 
 
 
 
 
 
 
 
ef0dc4f
5f72bf5
 
 
 
ef0dc4f
 
3e25ded
884bd75
3e25ded
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import gradio as gr
from huggingface_hub import whoami
from requests.exceptions import HTTPError


from blossomtune_gradio import config as cfg


def is_space_owner(profile: gr.OAuthProfile | None, oauth_token: gr.OAuthToken | None):
    """Check if the user is the owner. Always returns True for local development."""
    if cfg.SPACE_OWNER is None:
        return True
    if oauth_token:
        try:
            org_names = [org["name"] for org in whoami(oauth_token.token)["orgs"]]
        except HTTPError:
            return False
    else:
        org_names = []
    return profile is not None and (
        profile.username == cfg.SPACE_OWNER or cfg.SPACE_OWNER in org_names
    )