mfarre HF staff commited on
Commit
fd5705b
·
1 Parent(s): d0b22d2
Files changed (2) hide show
  1. app.py +117 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ 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"))
11
+ DATASET_REPO = "HuggingFaceTB/smolvlm2-iphone-waitlist"
12
+ MAX_RETRIES = 3
13
+
14
+ def commit_signup(username: str, email: str, current_data: pd.DataFrame) -> Optional[str]:
15
+ """Attempt to commit new signup atomically"""
16
+
17
+ # Add new user with timestamp
18
+ new_row = pd.DataFrame([{
19
+ 'userid': username,
20
+ 'email': email,
21
+ 'joined_at': datetime.utcnow().isoformat()
22
+ }])
23
+ updated_data = pd.concat([current_data, new_row], ignore_index=True)
24
+
25
+ # Save to temp file
26
+ with tempfile.NamedTemporaryFile(mode='w', suffix='.csv', delete=False) as tmp:
27
+ updated_data.to_csv(tmp.name, index=False)
28
+
29
+ # Create commit operation
30
+ operation = CommitOperationAdd(
31
+ path_in_repo="waitlist.csv",
32
+ path_or_fileobj=tmp.name,
33
+ commit_message=f"Add user {username} to waitlist"
34
+ )
35
+
36
+ try:
37
+ # Try to create commit
38
+ create_commit(
39
+ repo_id=DATASET_REPO,
40
+ repo_type="dataset",
41
+ operations=[operation],
42
+ commit_message=f"Add user {username} to waitlist"
43
+ )
44
+ os.unlink(tmp.name)
45
+ return None # Success
46
+ except Exception as e:
47
+ os.unlink(tmp.name)
48
+ return str(e) # Return error message
49
+
50
+ def join_waitlist(
51
+ token: gr.OAuthToken | None,
52
+ profile: gr.OAuthProfile | None,
53
+ ) -> str:
54
+ """Add user to the SmolVLM2 iPhone waitlist with retry logic for concurrent updates"""
55
+
56
+ if token is None or profile is None:
57
+ gr.Warning("Please log in to Hugging Face first!")
58
+ return None
59
+
60
+ for attempt in range(MAX_RETRIES):
61
+ try:
62
+ # Get current waitlist state
63
+ try:
64
+ current_data = pd.read_csv(
65
+ f"https://huggingface.co/datasets/{DATASET_REPO}/raw/main/waitlist.csv"
66
+ )
67
+ except:
68
+ current_data = pd.DataFrame(columns=['userid', 'email', 'joined_at'])
69
+
70
+ # Check if user already registered
71
+ if profile.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(profile.username, profile.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."
79
+
80
+ # If we got a conflict error, retry
81
+ if "Conflict" in str(error) and attempt < MAX_RETRIES - 1:
82
+ continue
83
+
84
+ # Other error or last attempt
85
+ gr.Error(f"An error occurred: {str(error)}")
86
+ return "Sorry, something went wrong. Please try again later."
87
+
88
+ except Exception as e:
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() as demo:
95
+ gr.Markdown("""
96
+ # Join SmolVLM2 iPhone Waitlist 📱
97
+ Sign up to be notified when the SmolVLM2 iPhone app and source code are released.
98
+
99
+ By joining the waitlist, you'll get:
100
+ - Early access to the SmolVLM2 iPhone app
101
+ - Updates on development progress
102
+ - First look at the source code when available
103
+ """)
104
+
105
+ with gr.Row():
106
+ gr.LoginButton()
107
+
108
+ join_button = gr.Button("Join Waitlist", variant="primary")
109
+ output = gr.Markdown(visible=False)
110
+
111
+ join_button.click(
112
+ fn=join_waitlist,
113
+ outputs=output,
114
+ )
115
+
116
+ if __name__ == "__main__":
117
+ demo.launch(auth_required=True)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ huggingface-hub
3
+ pandas