Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,13 +16,24 @@ if not GOOGLE_API_KEY:
|
|
| 16 |
client = genai.Client(api_key=os.environ.get("GOOGLE_API_KEY"))
|
| 17 |
GEMINI_MODEL_NAME = 'gemini-2.5-flash-image-preview'
|
| 18 |
|
| 19 |
-
def verify_pro_status(token: Optional[gr.OAuthToken]) -> bool:
|
| 20 |
"""Verifies if the user is a Hugging Face PRO user or part of an enterprise org."""
|
| 21 |
if not token:
|
| 22 |
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
try:
|
| 24 |
-
user_info = whoami(token=
|
| 25 |
-
return
|
|
|
|
|
|
|
|
|
|
| 26 |
except Exception as e:
|
| 27 |
print(f"Could not verify user's PRO/Enterprise status: {e}")
|
| 28 |
return False
|
|
|
|
| 16 |
client = genai.Client(api_key=os.environ.get("GOOGLE_API_KEY"))
|
| 17 |
GEMINI_MODEL_NAME = 'gemini-2.5-flash-image-preview'
|
| 18 |
|
| 19 |
+
def verify_pro_status(token: Optional[Union[gr.OAuthToken, str]]) -> bool:
|
| 20 |
"""Verifies if the user is a Hugging Face PRO user or part of an enterprise org."""
|
| 21 |
if not token:
|
| 22 |
return False
|
| 23 |
+
|
| 24 |
+
if isinstance(token, gr.OAuthToken):
|
| 25 |
+
token_str = token.token
|
| 26 |
+
elif isinstance(token, str):
|
| 27 |
+
token_str = token
|
| 28 |
+
else:
|
| 29 |
+
return False
|
| 30 |
+
|
| 31 |
try:
|
| 32 |
+
user_info = whoami(token=token_str)
|
| 33 |
+
return (
|
| 34 |
+
user_info.get("isPro", False) or
|
| 35 |
+
any(org.get("isEnterprise", False) for org in user_info.get("orgs", []))
|
| 36 |
+
)
|
| 37 |
except Exception as e:
|
| 38 |
print(f"Could not verify user's PRO/Enterprise status: {e}")
|
| 39 |
return False
|