Miquel Farré commited on
Commit
9d0662a
·
1 Parent(s): d879b66
Files changed (1) hide show
  1. app.py +24 -19
app.py CHANGED
@@ -4,7 +4,7 @@ from huggingface_hub import HfApi, CommitOperationAdd, create_commit
4
  import pandas as pd
5
  from datetime import datetime
6
  import tempfile
7
- from typing import Optional
8
 
9
  # Initialize Hugging Face client
10
  hf_api = HfApi(token=os.getenv("HF_TOKEN"))
@@ -47,16 +47,15 @@ def commit_signup(username: str, email: str, current_data: pd.DataFrame) -> Opti
47
  os.unlink(tmp.name)
48
  return str(e) # Return error message
49
 
50
- def join_waitlist(user: dict) -> str:
 
 
 
51
  """Add user to the SmolVLM2 iPhone waitlist with retry logic for concurrent updates"""
52
 
53
- if not user or not user.get("username"):
54
- gr.Warning("Please log in to Hugging Face first!")
55
  return "Please log in with your Hugging Face account first!"
56
 
57
- username = user["username"]
58
- email = user.get("email", "")
59
-
60
  for attempt in range(MAX_RETRIES):
61
  try:
62
  # Get current waitlist state
@@ -68,11 +67,11 @@ def join_waitlist(user: dict) -> str:
68
  current_data = pd.DataFrame(columns=['userid', 'email', 'joined_at'])
69
 
70
  # Check if user already registered
71
- if username in current_data['userid'].values:
72
  return "You're already on the waitlist! We'll keep you updated."
73
 
74
  # Try to commit the update
75
- error = commit_signup(username, email, current_data)
76
 
77
  if error is None: # Success
78
  return "Thanks for joining the waitlist! We'll keep you updated on SmolVLM2 iPhone app and source code release."
@@ -89,6 +88,12 @@ def join_waitlist(user: dict) -> str:
89
  if attempt == MAX_RETRIES - 1: # Last attempt
90
  gr.Error(f"An error occurred: {str(e)}")
91
  return "Sorry, something went wrong. Please try again later."
 
 
 
 
 
 
92
 
93
  # Create the interface
94
  with gr.Blocks(title="SmolVLM2 Waitlist") as demo:
@@ -102,16 +107,16 @@ with gr.Blocks(title="SmolVLM2 Waitlist") as demo:
102
  - First look at the source code when available
103
  """)
104
 
105
- user = gr.State(value=None)
106
-
107
  join_button = gr.Button("Join Waitlist", variant="primary")
108
- output = gr.Markdown(visible=False)
109
-
110
- join_button.click(
111
- fn=join_waitlist,
112
- inputs=user,
113
- outputs=output,
114
- )
115
 
116
  if __name__ == "__main__":
117
- demo.queue().launch(auth=True, auth_message="Please login to join the waitlist")
 
4
  import pandas as pd
5
  from datetime import datetime
6
  import tempfile
7
+ from typing import Optional, Tuple
8
 
9
  # Initialize Hugging Face client
10
  hf_api = HfApi(token=os.getenv("HF_TOKEN"))
 
47
  os.unlink(tmp.name)
48
  return str(e) # Return error message
49
 
50
+ def join_waitlist(
51
+ profile: gr.OAuthProfile | None,
52
+ oauth_token: gr.OAuthToken | None
53
+ ) -> str:
54
  """Add user to the SmolVLM2 iPhone waitlist with retry logic for concurrent updates"""
55
 
56
+ if profile is None or oauth_token is None:
 
57
  return "Please log in with your Hugging Face account first!"
58
 
 
 
 
59
  for attempt in range(MAX_RETRIES):
60
  try:
61
  # Get current waitlist state
 
67
  current_data = pd.DataFrame(columns=['userid', 'email', 'joined_at'])
68
 
69
  # Check if user already registered
70
+ if profile.username in current_data['userid'].values:
71
  return "You're already on the waitlist! We'll keep you updated."
72
 
73
  # Try to commit the update
74
+ error = commit_signup(profile.username, profile.email or "", current_data)
75
 
76
  if error is None: # Success
77
  return "Thanks for joining the waitlist! We'll keep you updated on SmolVLM2 iPhone app and source code release."
 
88
  if attempt == MAX_RETRIES - 1: # Last attempt
89
  gr.Error(f"An error occurred: {str(e)}")
90
  return "Sorry, something went wrong. Please try again later."
91
+
92
+ def show_welcome(profile: gr.OAuthProfile | None) -> str:
93
+ """Show welcome message based on login status"""
94
+ if profile is None:
95
+ return "Please sign in with your Hugging Face account to join the waitlist."
96
+ return f"Welcome {profile.name}! Click the button below to join the waitlist."
97
 
98
  # Create the interface
99
  with gr.Blocks(title="SmolVLM2 Waitlist") as demo:
 
107
  - First look at the source code when available
108
  """)
109
 
110
+ gr.LoginButton()
111
+ welcome_msg = gr.Markdown()
112
  join_button = gr.Button("Join Waitlist", variant="primary")
113
+ status_msg = gr.Markdown()
114
+
115
+ # Show welcome message on load and auth change
116
+ demo.load(show_welcome, None, welcome_msg)
117
+
118
+ # Handle join button click
119
+ join_button.click(join_waitlist, None, status_msg)
120
 
121
  if __name__ == "__main__":
122
+ demo.queue().launch()