Claude commited on
Commit
201c14d
·
unverified ·
1 Parent(s): 0c23cd2

refactor: Remove unused list_organizations and simplify OAuth

Browse files

- Remove list_organizations function (not used in UI)
- Remove whoami import (no longer needed)
- Simplify OAuth scopes to only inference-api (for LLM calls)
- Remove read-repos scope (not needed)
- Session identification uses profile.name from OAuth

This simplifies the login experience for users.

Files changed (3) hide show
  1. README.md +0 -1
  2. app.py +1 -13
  3. tests/test_app.py +0 -48
README.md CHANGED
@@ -13,7 +13,6 @@ suggested_hardware: zero-a10g
13
  suggested_storage: small
14
  hf_oauth: true
15
  hf_oauth_scopes:
16
- - read-repos
17
  - inference-api
18
  hf_oauth_expiration_minutes: 480
19
  tags:
 
13
  suggested_storage: small
14
  hf_oauth: true
15
  hf_oauth_scopes:
 
16
  - inference-api
17
  hf_oauth_expiration_minutes: 480
18
  tags:
app.py CHANGED
@@ -11,7 +11,7 @@ import cv2
11
  import gradio as gr
12
  import torch
13
  import yt_dlp
14
- from huggingface_hub import InferenceClient, whoami
15
  from PIL import Image
16
  from sentence_transformers import SentenceTransformer
17
  from transformers import BlipForConditionalGeneration, BlipProcessor, pipeline
@@ -86,18 +86,6 @@ def hello(profile: gr.OAuthProfile | None) -> str:
86
  return f"Hello {profile.name}!"
87
 
88
 
89
- def list_organizations(oauth_token: gr.OAuthToken | None) -> str:
90
- if oauth_token is None:
91
- return ""
92
- try:
93
- org_names = [org["name"] for org in whoami(oauth_token.token)["orgs"]]
94
- if org_names:
95
- return f"You belong to: {', '.join(org_names)}"
96
- return "You don't belong to any organizations."
97
- except Exception:
98
- return ""
99
-
100
-
101
  def get_device():
102
  return "cuda" if torch.cuda.is_available() else "cpu"
103
 
 
11
  import gradio as gr
12
  import torch
13
  import yt_dlp
14
+ from huggingface_hub import InferenceClient
15
  from PIL import Image
16
  from sentence_transformers import SentenceTransformer
17
  from transformers import BlipForConditionalGeneration, BlipProcessor, pipeline
 
86
  return f"Hello {profile.name}!"
87
 
88
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  def get_device():
90
  return "cuda" if torch.cuda.is_available() else "cpu"
91
 
tests/test_app.py CHANGED
@@ -107,54 +107,6 @@ class TestHello:
107
  assert result == "Hello TestUser!"
108
 
109
 
110
- class TestListOrganizations:
111
- """Tests for the list_organizations function."""
112
-
113
- def test_no_token_returns_empty_string(self):
114
- """Test returns empty string when oauth_token is None."""
115
- from app import list_organizations
116
-
117
- result = list_organizations(None)
118
- assert result == ""
119
-
120
- def test_with_organizations(self):
121
- """Test returns organization list when user has orgs."""
122
- with patch("app.whoami") as mock_whoami:
123
- mock_whoami.return_value = {"orgs": [{"name": "Org1"}, {"name": "Org2"}]}
124
- from app import list_organizations
125
-
126
- mock_token = MagicMock()
127
- mock_token.token = "test_token"
128
-
129
- result = list_organizations(mock_token)
130
- assert "Org1" in result
131
- assert "Org2" in result
132
-
133
- def test_no_organizations(self):
134
- """Test returns appropriate message when user has no orgs."""
135
- with patch("app.whoami") as mock_whoami:
136
- mock_whoami.return_value = {"orgs": []}
137
- from app import list_organizations
138
-
139
- mock_token = MagicMock()
140
- mock_token.token = "test_token"
141
-
142
- result = list_organizations(mock_token)
143
- assert result == "You don't belong to any organizations."
144
-
145
- def test_api_error_returns_empty_string(self):
146
- """Test returns empty string when API call fails."""
147
- with patch("app.whoami") as mock_whoami:
148
- mock_whoami.side_effect = Exception("API Error")
149
- from app import list_organizations
150
-
151
- mock_token = MagicMock()
152
- mock_token.token = "test_token"
153
-
154
- result = list_organizations(mock_token)
155
- assert result == ""
156
-
157
-
158
  class TestTranscribeAudio:
159
  """Tests for the transcribe_audio function."""
160
 
 
107
  assert result == "Hello TestUser!"
108
 
109
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  class TestTranscribeAudio:
111
  """Tests for the transcribe_audio function."""
112