Ar4ikov commited on
Commit
f8fd37e
·
1 Parent(s): e3aac54

Enhance token handling in Gradio app

Browse files

- Updated _describe_token_source function to accept gr.OAuthProfile for improved user identification.
- Modified transcribe_audio function to include profile parameter for better token source description.
- Added hf_oauth_scopes to README.md for clarity on OAuth permissions.

Files changed (2) hide show
  1. README.md +3 -0
  2. app.py +8 -3
README.md CHANGED
@@ -10,6 +10,9 @@ pinned: false
10
  license: mit
11
  short_description: Interactive Gradio Space demonstrating ai-sage/GigaAM-v3 ASR
12
  hf_oauth: true
 
 
 
13
  ---
14
 
15
  # GigaAM-v3 Gradio demo
 
10
  license: mit
11
  short_description: Interactive Gradio Space demonstrating ai-sage/GigaAM-v3 ASR
12
  hf_oauth: true
13
+ hf_oauth_scopes:
14
+ - read-repos
15
+
16
  ---
17
 
18
  # GigaAM-v3 Gradio demo
app.py CHANGED
@@ -137,10 +137,14 @@ def _temporary_token(token: Optional[str]):
137
  os.environ["HUGGINGFACEHUB_API_TOKEN"] = previous_hub
138
 
139
 
140
- def _describe_token_source(oauth_token: gr.OAuthToken | None) -> str:
 
 
 
141
  """Describe where the HF token came from."""
142
  if _extract_token_from_oauth(oauth_token):
143
- return "user (OAuth)"
 
144
  if DEFAULT_HF_TOKEN:
145
  return "space secret"
146
  return "not configured"
@@ -217,6 +221,7 @@ def transcribe_audio(
217
  audio_path: Optional[str],
218
  variant: str,
219
  mode_label: str,
 
220
  oauth_token: gr.OAuthToken | None,
221
  ) -> tuple[str, List[List[float | str]], str]:
222
  if not audio_path or not os.path.exists(audio_path):
@@ -294,7 +299,7 @@ def transcribe_audio(
294
  f"- **Transcription mode:** {mode_description}",
295
  f"- **Audio duration:** {_format_seconds(duration)} @ {sample_rate} Hz",
296
  f"- **Latency:** {_format_seconds(latency)} on `{DEVICE}`",
297
- f"- **Token source:** {_describe_token_source(oauth_token)}",
298
  ]
299
 
300
  return transcription_text, segments, "\n".join(metadata_lines)
 
137
  os.environ["HUGGINGFACEHUB_API_TOKEN"] = previous_hub
138
 
139
 
140
+ def _describe_token_source(
141
+ profile: gr.OAuthProfile | None,
142
+ oauth_token: gr.OAuthToken | None,
143
+ ) -> str:
144
  """Describe where the HF token came from."""
145
  if _extract_token_from_oauth(oauth_token):
146
+ username = profile.username if profile else "user"
147
+ return f"{username} (OAuth)"
148
  if DEFAULT_HF_TOKEN:
149
  return "space secret"
150
  return "not configured"
 
221
  audio_path: Optional[str],
222
  variant: str,
223
  mode_label: str,
224
+ profile: gr.OAuthProfile | None,
225
  oauth_token: gr.OAuthToken | None,
226
  ) -> tuple[str, List[List[float | str]], str]:
227
  if not audio_path or not os.path.exists(audio_path):
 
299
  f"- **Transcription mode:** {mode_description}",
300
  f"- **Audio duration:** {_format_seconds(duration)} @ {sample_rate} Hz",
301
  f"- **Latency:** {_format_seconds(latency)} on `{DEVICE}`",
302
+ f"- **Token source:** {_describe_token_source(profile, oauth_token)}",
303
  ]
304
 
305
  return transcription_text, segments, "\n".join(metadata_lines)