macayaven commited on
Commit
47be4de
·
verified ·
1 Parent(s): c712312

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -4
app.py CHANGED
@@ -3,6 +3,8 @@ Re-frame: Cognitive Reframing Assistant
3
  A Gradio-based CBT tool for identifying and reframing cognitive distortions
4
  """
5
 
 
 
6
  import hashlib
7
  import json
8
  import os
@@ -1035,7 +1037,7 @@ def create_app(language='en'):
1035
  def admin_refresh():
1036
  return _summarize_metrics_md()
1037
 
1038
- def _profile_username(profile: "gr.OAuthProfile | None") -> str:
1039
  try:
1040
  for key in ("preferred_username", "username", "login", "name", "sub", "id"):
1041
  if hasattr(profile, key):
@@ -1048,13 +1050,25 @@ def create_app(language='en'):
1048
  pass
1049
  return "unknown"
1050
 
1051
- def identity_refresh(profile: "gr.OAuthProfile | None"):
 
1052
  visible = _owner_is(profile)
 
 
 
 
 
 
 
 
 
 
1053
  return (
1054
- f"Logged in as: `{_profile_username(profile)}`\n\n"
1055
  f"OWNER_USER: `{(os.getenv('OWNER_USER') or '').strip()}`\n"
1056
  f"SPACE_AUTHOR_NAME: `{(os.getenv('SPACE_AUTHOR_NAME') or '').strip()}`\n"
1057
- f"Owner match: {'yes' if visible else 'no'}"
 
1058
  )
1059
 
1060
  def storage_check():
 
3
  A Gradio-based CBT tool for identifying and reframing cognitive distortions
4
  """
5
 
6
+ from __future__ import annotations
7
+
8
  import hashlib
9
  import json
10
  import os
 
1037
  def admin_refresh():
1038
  return _summarize_metrics_md()
1039
 
1040
+ def _profile_username(profile: gr.OAuthProfile | None) -> str:
1041
  try:
1042
  for key in ("preferred_username", "username", "login", "name", "sub", "id"):
1043
  if hasattr(profile, key):
 
1050
  pass
1051
  return "unknown"
1052
 
1053
+ def identity_refresh(profile: gr.OAuthProfile | None):
1054
+ viewer = _profile_username(profile)
1055
  visible = _owner_is(profile)
1056
+ token_info = ""
1057
+ try:
1058
+ from huggingface_hub import whoami as _hf_whoami # local import
1059
+ info = _hf_whoami()
1060
+ uname = info.get("name") or info.get("fullname") or "?"
1061
+ ttype = info.get("type", "?")
1062
+ orgs = ", ".join([o.get("name", "?") for o in info.get("orgs", [])])
1063
+ token_info = f"Token user: `{uname}` (type: {ttype}); orgs: [{orgs}]"
1064
+ except Exception as e:
1065
+ token_info = f"Token whoami failed: {e}"
1066
  return (
1067
+ f"Logged in as (OAuth): `{viewer}`\n\n"
1068
  f"OWNER_USER: `{(os.getenv('OWNER_USER') or '').strip()}`\n"
1069
  f"SPACE_AUTHOR_NAME: `{(os.getenv('SPACE_AUTHOR_NAME') or '').strip()}`\n"
1070
+ f"Owner match: {'yes' if visible else 'no'}\n\n"
1071
+ f"{token_info}"
1072
  )
1073
 
1074
  def storage_check():