edbeeching commited on
Commit
ba02fde
Β·
1 Parent(s): 588fd75

fix sign in

Browse files
Files changed (1) hide show
  1. app.py +25 -14
app.py CHANGED
@@ -291,8 +291,8 @@ def main():
291
  login_button = gr.LoginButton(value="πŸ”‘ Sign in", size="sm")
292
  gr.Markdown("") # Empty space for alignment
293
 
294
- pro_message = gr.Markdown(visible=False)
295
- main_interface = gr.Column(visible=True)
296
 
297
  # Store the current oauth token for use in submit_request
298
  current_oauth_token = gr.State(None)
@@ -538,31 +538,42 @@ def main():
538
  return "πŸ‘€ **Free User**: You can generate up to 100 samples per request. [Upgrade to PRO](http://huggingface.co/subscribe/pro?source=synthetic-data-universe) for 10,000 samples."
539
 
540
  def control_access(profile: Optional[gr.OAuthProfile] = None, oauth_token: Optional[gr.OAuthToken] = None):
541
- # Always show the interface, whether user is logged in or not
542
- limit_msg = update_user_limits(oauth_token)
543
-
544
- # Update slider maximum based on user tier
545
  if oauth_token is None:
546
- max_samples = MAX_SAMPLES_FREE
547
- button_text = "πŸ”‘ Sign in for PRO benefits"
 
 
 
 
 
 
 
548
  else:
 
 
549
  is_pro = verify_pro_status(oauth_token)
550
  max_samples = MAX_SAMPLES_PRO if is_pro else MAX_SAMPLES_FREE
 
551
  if is_pro:
552
  button_text = f"✨ Signed in as PRO ({profile.name if profile else 'User'})"
553
  else:
554
  button_text = f"πŸ‘€ Signed in as {profile.name if profile else 'User'}"
555
-
556
- slider_update = gr.update(maximum=max_samples)
557
- button_update = gr.update(value=button_text)
558
-
559
- return gr.update(visible=True), gr.update(visible=False), oauth_token, limit_msg, slider_update, button_update
 
 
 
 
560
 
561
 
562
  # Handle login state changes - LoginButton automatically handles auth state changes
563
  # The demo.load will handle both initial load and auth changes
564
 
565
- demo.load(control_access, inputs=None, outputs=[main_interface, pro_message, current_oauth_token, user_limit_info, num_output_samples, login_button])
566
  demo.queue(max_size=None, default_concurrency_limit=None).launch(show_error=True)
567
 
568
  if __name__ == "__main__":
 
291
  login_button = gr.LoginButton(value="πŸ”‘ Sign in", size="sm")
292
  gr.Markdown("") # Empty space for alignment
293
 
294
+ signin_message = gr.Markdown("## πŸ”‘ Sign In Required\n\nPlease sign in with your Hugging Face account to access the synthetic data generation service. Click the **Sign in** button above to continue.", visible=True)
295
+ main_interface = gr.Column(visible=False)
296
 
297
  # Store the current oauth token for use in submit_request
298
  current_oauth_token = gr.State(None)
 
538
  return "πŸ‘€ **Free User**: You can generate up to 100 samples per request. [Upgrade to PRO](http://huggingface.co/subscribe/pro?source=synthetic-data-universe) for 10,000 samples."
539
 
540
  def control_access(profile: Optional[gr.OAuthProfile] = None, oauth_token: Optional[gr.OAuthToken] = None):
541
+ # Require users to be signed in
 
 
 
542
  if oauth_token is None:
543
+ # User is not signed in - show sign-in prompt, hide main interface
544
+ return (
545
+ gr.update(visible=False), # main_interface
546
+ gr.update(visible=True), # signin_message
547
+ oauth_token, # current_oauth_token
548
+ "", # user_limit_info (empty when not signed in)
549
+ gr.update(), # num_output_samples (no change)
550
+ gr.update(value="πŸ”‘ Sign in") # login_button
551
+ )
552
  else:
553
+ # User is signed in - show main interface, hide sign-in prompt
554
+ limit_msg = update_user_limits(oauth_token)
555
  is_pro = verify_pro_status(oauth_token)
556
  max_samples = MAX_SAMPLES_PRO if is_pro else MAX_SAMPLES_FREE
557
+
558
  if is_pro:
559
  button_text = f"✨ Signed in as PRO ({profile.name if profile else 'User'})"
560
  else:
561
  button_text = f"πŸ‘€ Signed in as {profile.name if profile else 'User'}"
562
+
563
+ return (
564
+ gr.update(visible=True), # main_interface
565
+ gr.update(visible=False), # signin_message
566
+ oauth_token, # current_oauth_token
567
+ limit_msg, # user_limit_info
568
+ gr.update(maximum=max_samples), # num_output_samples
569
+ gr.update(value=button_text) # login_button
570
+ )
571
 
572
 
573
  # Handle login state changes - LoginButton automatically handles auth state changes
574
  # The demo.load will handle both initial load and auth changes
575
 
576
+ demo.load(control_access, inputs=None, outputs=[main_interface, signin_message, current_oauth_token, user_limit_info, num_output_samples, login_button])
577
  demo.queue(max_size=None, default_concurrency_limit=None).launch(show_error=True)
578
 
579
  if __name__ == "__main__":