Miquel Farré
commited on
Commit
·
1f8ef74
1
Parent(s):
5921b80
update
Browse files
app.py
CHANGED
|
@@ -48,11 +48,11 @@ def commit_signup(username: str, current_data: pd.DataFrame) -> Optional[str]:
|
|
| 48 |
def join_waitlist(
|
| 49 |
profile: gr.OAuthProfile | None,
|
| 50 |
oauth_token: gr.OAuthToken | None
|
| 51 |
-
) ->
|
| 52 |
"""Add user to the SmolVLM2 iPhone waitlist with retry logic for concurrent updates"""
|
| 53 |
|
| 54 |
if profile is None or oauth_token is None:
|
| 55 |
-
return "Please log in with your Hugging Face account first!"
|
| 56 |
|
| 57 |
for attempt in range(MAX_RETRIES):
|
| 58 |
try:
|
|
@@ -66,13 +66,19 @@ def join_waitlist(
|
|
| 66 |
|
| 67 |
# Check if user already registered
|
| 68 |
if profile.username in current_data['userid'].values:
|
| 69 |
-
return
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
# Try to commit the update
|
| 72 |
error = commit_signup(profile.username, current_data)
|
| 73 |
|
| 74 |
if error is None: # Success
|
| 75 |
-
return
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
# If we got a conflict error, retry
|
| 78 |
if "Conflict" in str(error) and attempt < MAX_RETRIES - 1:
|
|
@@ -80,25 +86,37 @@ def join_waitlist(
|
|
| 80 |
|
| 81 |
# Other error or last attempt
|
| 82 |
gr.Error(f"An error occurred: {str(error)}")
|
| 83 |
-
return
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
except Exception as e:
|
| 86 |
if attempt == MAX_RETRIES - 1: # Last attempt
|
| 87 |
gr.Error(f"An error occurred: {str(e)}")
|
| 88 |
-
return
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
-
def update_ui(profile: gr.OAuthProfile | None) -> Tuple[
|
| 91 |
"""Update UI elements based on login status"""
|
| 92 |
if profile is None:
|
| 93 |
return (
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
| 97 |
)
|
| 98 |
return (
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
| 102 |
)
|
| 103 |
|
| 104 |
# Create the interface
|
|
|
|
| 48 |
def join_waitlist(
|
| 49 |
profile: gr.OAuthProfile | None,
|
| 50 |
oauth_token: gr.OAuthToken | None
|
| 51 |
+
) -> gr.update:
|
| 52 |
"""Add user to the SmolVLM2 iPhone waitlist with retry logic for concurrent updates"""
|
| 53 |
|
| 54 |
if profile is None or oauth_token is None:
|
| 55 |
+
return gr.update(value="Please log in with your Hugging Face account first!")
|
| 56 |
|
| 57 |
for attempt in range(MAX_RETRIES):
|
| 58 |
try:
|
|
|
|
| 66 |
|
| 67 |
# Check if user already registered
|
| 68 |
if profile.username in current_data['userid'].values:
|
| 69 |
+
return gr.update(
|
| 70 |
+
value="## 😎 You're already on the waitlist! We'll keep you updated.",
|
| 71 |
+
visible=True
|
| 72 |
+
)
|
| 73 |
|
| 74 |
# Try to commit the update
|
| 75 |
error = commit_signup(profile.username, current_data)
|
| 76 |
|
| 77 |
if error is None: # Success
|
| 78 |
+
return gr.update(
|
| 79 |
+
value="## 🎉 Thanks for joining the waitlist! We'll keep you updated on SmolVLM2 iPhone app.",
|
| 80 |
+
visible=True
|
| 81 |
+
)
|
| 82 |
|
| 83 |
# If we got a conflict error, retry
|
| 84 |
if "Conflict" in str(error) and attempt < MAX_RETRIES - 1:
|
|
|
|
| 86 |
|
| 87 |
# Other error or last attempt
|
| 88 |
gr.Error(f"An error occurred: {str(error)}")
|
| 89 |
+
return gr.update(
|
| 90 |
+
value="## 🫠 Sorry, something went wrong. Please try again later.",
|
| 91 |
+
visible=True
|
| 92 |
+
)
|
| 93 |
|
| 94 |
except Exception as e:
|
| 95 |
if attempt == MAX_RETRIES - 1: # Last attempt
|
| 96 |
gr.Error(f"An error occurred: {str(e)}")
|
| 97 |
+
return gr.update(
|
| 98 |
+
value="## 🫠 Sorry, something went wrong. Please try again later.",
|
| 99 |
+
visible=True
|
| 100 |
+
)
|
| 101 |
|
| 102 |
+
def update_ui(profile: gr.OAuthProfile | None) -> Tuple[gr.update, gr.update, gr.update]:
|
| 103 |
"""Update UI elements based on login status"""
|
| 104 |
if profile is None:
|
| 105 |
return (
|
| 106 |
+
gr.update(
|
| 107 |
+
value="## Please sign in with your Hugging Face account to join the waitlist.",
|
| 108 |
+
visible=True
|
| 109 |
+
),
|
| 110 |
+
gr.update(visible=False),
|
| 111 |
+
gr.update(visible=False)
|
| 112 |
)
|
| 113 |
return (
|
| 114 |
+
gr.update(
|
| 115 |
+
value=f"## Welcome {profile.name} 👋 Click the button below 👇 to receive any updates related with the SmolVLM2 iPhone application",
|
| 116 |
+
visible=True
|
| 117 |
+
),
|
| 118 |
+
gr.update(visible=True),
|
| 119 |
+
gr.update(visible=False)
|
| 120 |
)
|
| 121 |
|
| 122 |
# Create the interface
|