Miquel Farré commited on
Commit ·
5921b80
1
Parent(s): e50e776
update
Browse files
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"))
|
|
@@ -66,13 +66,13 @@ def join_waitlist(
|
|
| 66 |
|
| 67 |
# Check if user already registered
|
| 68 |
if profile.username in current_data['userid'].values:
|
| 69 |
-
return "You're already on the waitlist! We'll keep you updated."
|
| 70 |
|
| 71 |
# Try to commit the update
|
| 72 |
error = commit_signup(profile.username, current_data)
|
| 73 |
|
| 74 |
if error is None: # Success
|
| 75 |
-
return "Thanks for joining the waitlist! We'll keep you updated on SmolVLM2 iPhone app
|
| 76 |
|
| 77 |
# If we got a conflict error, retry
|
| 78 |
if "Conflict" in str(error) and attempt < MAX_RETRIES - 1:
|
|
@@ -80,39 +80,45 @@ def join_waitlist(
|
|
| 80 |
|
| 81 |
# Other error or last attempt
|
| 82 |
gr.Error(f"An error occurred: {str(error)}")
|
| 83 |
-
return "Sorry, something went wrong. Please try again later."
|
| 84 |
|
| 85 |
except Exception as e:
|
| 86 |
-
print(str(e))
|
| 87 |
if attempt == MAX_RETRIES - 1: # Last attempt
|
| 88 |
gr.Error(f"An error occurred: {str(e)}")
|
| 89 |
-
return "Sorry, something went wrong. Please try again later."
|
| 90 |
-
|
| 91 |
-
def
|
| 92 |
-
"""
|
| 93 |
if profile is None:
|
| 94 |
-
return
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
# Create the interface
|
| 98 |
with gr.Blocks(title="SmolVLM2 Waitlist") as demo:
|
| 99 |
gr.Markdown("""
|
| 100 |
# Join SmolVLM2 iPhone Waitlist 📱
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
By joining the waitlist, you'll get:
|
| 104 |
-
- Early access to the SmolVLM2 iPhone app
|
| 105 |
-
- Updates on development progress
|
| 106 |
-
- First look at the source code when available
|
| 107 |
""")
|
| 108 |
|
| 109 |
gr.LoginButton()
|
| 110 |
-
welcome_msg = gr.Markdown()
|
| 111 |
-
join_button = gr.Button("Join Waitlist", variant="primary")
|
| 112 |
-
status_msg = gr.Markdown()
|
| 113 |
|
| 114 |
-
#
|
| 115 |
-
demo.load(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
# Handle join button click
|
| 118 |
join_button.click(join_waitlist, None, status_msg)
|
|
|
|
| 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"))
|
|
|
|
| 66 |
|
| 67 |
# Check if user already registered
|
| 68 |
if profile.username in current_data['userid'].values:
|
| 69 |
+
return "## 😎 You're already on the waitlist! We'll keep you updated."
|
| 70 |
|
| 71 |
# Try to commit the update
|
| 72 |
error = commit_signup(profile.username, current_data)
|
| 73 |
|
| 74 |
if error is None: # Success
|
| 75 |
+
return "## 🎉 Thanks for joining the waitlist! We'll keep you updated on SmolVLM2 iPhone app."
|
| 76 |
|
| 77 |
# If we got a conflict error, retry
|
| 78 |
if "Conflict" in str(error) and attempt < MAX_RETRIES - 1:
|
|
|
|
| 80 |
|
| 81 |
# Other error or last attempt
|
| 82 |
gr.Error(f"An error occurred: {str(error)}")
|
| 83 |
+
return "## 🫠 Sorry, something went wrong. Please try again later."
|
| 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 "## 🫠 Sorry, something went wrong. Please try again later."
|
| 89 |
+
|
| 90 |
+
def update_ui(profile: gr.OAuthProfile | None) -> Tuple[str, bool, bool]:
|
| 91 |
+
"""Update UI elements based on login status"""
|
| 92 |
if profile is None:
|
| 93 |
+
return (
|
| 94 |
+
"## Please sign in with your Hugging Face account to join the waitlist.", # welcome message
|
| 95 |
+
False, # hide join button
|
| 96 |
+
False, # hide status message
|
| 97 |
+
)
|
| 98 |
+
return (
|
| 99 |
+
f"## Welcome {profile.name} 👋 Click the button below 👇 to receive any updates related with the SmolVLM2 iPhone application", # welcome message
|
| 100 |
+
True, # show join button
|
| 101 |
+
True, # show status message
|
| 102 |
+
)
|
| 103 |
|
| 104 |
# Create the interface
|
| 105 |
with gr.Blocks(title="SmolVLM2 Waitlist") as demo:
|
| 106 |
gr.Markdown("""
|
| 107 |
# Join SmolVLM2 iPhone Waitlist 📱
|
| 108 |
+
## Please log-in using your Hugging Face Id to continue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
""")
|
| 110 |
|
| 111 |
gr.LoginButton()
|
| 112 |
+
welcome_msg = gr.Markdown(visible=True)
|
| 113 |
+
join_button = gr.Button("Join Waitlist", variant="primary", visible=False)
|
| 114 |
+
status_msg = gr.Markdown(visible=False)
|
| 115 |
|
| 116 |
+
# Update UI elements on load and auth change
|
| 117 |
+
demo.load(
|
| 118 |
+
fn=update_ui,
|
| 119 |
+
inputs=None,
|
| 120 |
+
outputs=[welcome_msg, join_button, status_msg]
|
| 121 |
+
)
|
| 122 |
|
| 123 |
# Handle join button click
|
| 124 |
join_button.click(join_waitlist, None, status_msg)
|