|
|
import gradio as gr |
|
|
import pandas as pd |
|
|
from datasets import load_dataset |
|
|
from huggingface_hub import login |
|
|
import os |
|
|
import logging |
|
|
|
|
|
|
|
|
logging.basicConfig(level=logging.INFO) |
|
|
logger = logging.getLogger(__name__) |
|
|
|
|
|
|
|
|
HF_TOKEN = os.environ.get("HF_TOKEN") |
|
|
if HF_TOKEN: |
|
|
login(token=HF_TOKEN) |
|
|
logger.info("β
Authenticated with Hugging Face") |
|
|
else: |
|
|
logger.warning("β οΈ HF_TOKEN not found - running without authentication") |
|
|
|
|
|
|
|
|
DATASET_NAME = "ysharma/gradio-hackathon-registrations-winter-2025" |
|
|
|
|
|
def verify_registration(email, hf_username): |
|
|
""" |
|
|
Verify if a user is registered by checking both email and HF username |
|
|
Returns registration details if both match |
|
|
""" |
|
|
try: |
|
|
|
|
|
if not email or not email.strip(): |
|
|
return "β Please enter your email address" |
|
|
|
|
|
if not hf_username or not hf_username.strip(): |
|
|
return "β Please enter your Hugging Face username" |
|
|
|
|
|
logger.info(f"Verification attempt for email: {email}") |
|
|
|
|
|
|
|
|
try: |
|
|
dataset = load_dataset(DATASET_NAME, split="train") |
|
|
df = dataset.to_pandas() |
|
|
logger.info(f"Loaded dataset with {len(df)} registrations") |
|
|
except Exception as load_error: |
|
|
logger.error(f"Failed to load dataset: {load_error}") |
|
|
return "β Unable to verify registration at this time. Please try again later." |
|
|
|
|
|
|
|
|
email_lower = email.strip().lower() |
|
|
username_lower = hf_username.strip().lower() |
|
|
|
|
|
match = df[ |
|
|
(df['email'].str.lower() == email_lower) & |
|
|
(df['hf_username'].str.lower() == username_lower) |
|
|
] |
|
|
|
|
|
if len(match) == 0: |
|
|
|
|
|
email_exists = df[df['email'].str.lower() == email_lower] |
|
|
username_exists = df[df['hf_username'].str.lower() == username_lower] |
|
|
|
|
|
if len(email_exists) > 0 and len(username_exists) == 0: |
|
|
return "β Email found but Hugging Face username doesn't match. Please check your username." |
|
|
elif len(username_exists) > 0 and len(email_exists) == 0: |
|
|
return "β Hugging Face username found but email doesn't match. Please check your email." |
|
|
else: |
|
|
return "β No registration found with this email and Hugging Face username combination." |
|
|
|
|
|
|
|
|
registration = match.iloc[0] |
|
|
|
|
|
|
|
|
try: |
|
|
timestamp = pd.to_datetime(registration['timestamp']) |
|
|
reg_date = timestamp.strftime("%B %d, %Y at %I:%M %p UTC") |
|
|
except: |
|
|
reg_date = registration['timestamp'] |
|
|
|
|
|
|
|
|
track_interest = registration['track_interest'] |
|
|
if isinstance(track_interest, str): |
|
|
|
|
|
track_interest = track_interest.strip("[]'\"").replace("'", "") |
|
|
|
|
|
result = f""" |
|
|
## β
Registration Confirmed! |
|
|
|
|
|
**Participant Details:** |
|
|
- **Full Name:** {registration['full_name']} |
|
|
- **Email:** {registration['email']} |
|
|
- **Hugging Face Username:** {registration['hf_username']} |
|
|
- **Registered On:** {reg_date} |
|
|
""" |
|
|
|
|
|
logger.info(f"β
Verification successful for {email}") |
|
|
return result |
|
|
|
|
|
except Exception as e: |
|
|
logger.error(f"Error during verification: {e}") |
|
|
import traceback |
|
|
traceback.print_exc() |
|
|
return f"β An error occurred during verification: {str(e)}" |
|
|
|
|
|
|
|
|
custom_css = """ |
|
|
.gradio-container { |
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif; |
|
|
} |
|
|
|
|
|
/* Verify button styling - MCP theme */ |
|
|
#verify-btn { |
|
|
background: #C8DDD7 !important; |
|
|
border: 2px solid #000000 !important; |
|
|
color: #000000 !important; |
|
|
font-weight: 600 !important; |
|
|
font-size: 18px !important; |
|
|
padding: 16px 32px !important; |
|
|
border-radius: 12px !important; |
|
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important; |
|
|
transition: all 0.3s ease !important; |
|
|
} |
|
|
|
|
|
#verify-btn:hover { |
|
|
transform: translateY(-2px) !important; |
|
|
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25) !important; |
|
|
background: #B8CEC7 !important; |
|
|
} |
|
|
|
|
|
#verify-btn:active { |
|
|
transform: translateY(0px) !important; |
|
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2) !important; |
|
|
} |
|
|
""" |
|
|
|
|
|
|
|
|
with gr.Blocks(title="MCP Birthday Party - Registration Verification", css=custom_css, theme="ocean") as demo: |
|
|
|
|
|
|
|
|
gr.Markdown(""" |
|
|
# π MCP's 1st Birthday - Registration Verification |
|
|
|
|
|
**π
Event Dates:** November 14-30, 2025 |
|
|
|
|
|
Enter your email address and Hugging Face username to verify your registration and view your details. |
|
|
""") |
|
|
|
|
|
gr.Markdown("---") |
|
|
|
|
|
with gr.Row(): |
|
|
with gr.Column(): |
|
|
verify_email = gr.Textbox( |
|
|
label="Email Address", |
|
|
placeholder="Enter your registered email", |
|
|
max_lines=1 |
|
|
) |
|
|
|
|
|
verify_hf_username = gr.Textbox( |
|
|
label="Hugging Face Username", |
|
|
placeholder="Enter your registered HF username", |
|
|
max_lines=1 |
|
|
) |
|
|
|
|
|
verify_btn = gr.Button("π Check Registration Status", variant="primary", size="lg", elem_id="verify-btn") |
|
|
|
|
|
with gr.Column(): |
|
|
gr.Markdown(""" |
|
|
### Important Notes |
|
|
|
|
|
- Make sure you enter the **exact** email and username you used during registration |
|
|
- Both fields are **case-insensitive** but must match your registration |
|
|
- Both email AND username must match for security purposes |
|
|
- If you can't find your registration, try registering at the [main registration page](https://huggingface.co/spaces/MCP-1st-Birthday/gradio-hackathon-registration-winter25) |
|
|
""") |
|
|
|
|
|
verify_output = gr.Markdown() |
|
|
|
|
|
|
|
|
verify_btn.click( |
|
|
fn=verify_registration, |
|
|
inputs=[verify_email, verify_hf_username], |
|
|
outputs=verify_output |
|
|
) |
|
|
|
|
|
|
|
|
gr.Markdown(""" |
|
|
--- |
|
|
**π Quick Links:** |
|
|
|
|
|
[Discord Community](https://discord.gg/92sEPT2Zhv) | [Hackathon Details & Rules](https://huggingface.co/MCP-1st-Birthday) |
|
|
""") |
|
|
|
|
|
if __name__ == "__main__": |
|
|
demo.launch() |