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()