File size: 6,696 Bytes
b4f925b 5de25f1 b4f925b 5de25f1 b4f925b 5de25f1 b4f925b 5de25f1 b4f925b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
import gradio as gr
import pandas as pd
from datasets import load_dataset
from huggingface_hub import login
import os
import logging
# Setup logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# Authenticate with Hugging Face
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
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:
# Validate inputs
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}")
# Load dataset
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."
# Search for exact match (both email AND username must match)
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:
# Check if email exists with different username
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 found - format the details
registration = match.iloc[0]
# Parse timestamp
try:
timestamp = pd.to_datetime(registration['timestamp'])
reg_date = timestamp.strftime("%B %d, %Y at %I:%M %p UTC")
except:
reg_date = registration['timestamp']
# Format track interests
track_interest = registration['track_interest']
if isinstance(track_interest, str):
# Clean up the string representation of list
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 for MCP theme
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;
}
"""
# Create the Gradio interface
with gr.Blocks(title="MCP Birthday Party - Registration Verification", css=custom_css, theme="ocean") as demo:
# Header
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()
# Verification click event
verify_btn.click(
fn=verify_registration,
inputs=[verify_email, verify_hf_username],
outputs=verify_output
)
# Footer
gr.Markdown("""
---
**π Quick Links:**
[Discord Community](https://discord.gg/92sEPT2Zhv) | [Hackathon Details & Rules](https://huggingface.co/MCP-1st-Birthday)
""")
if __name__ == "__main__":
demo.launch() |