File size: 8,900 Bytes
103a61f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
import gradio as gr
import pandas as pd
from datasets import load_dataset
from huggingface_hub import login
import os
import logging
import re

# 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"

# Cache for dataset to avoid repeated loading
_cached_df = None
_cache_timestamp = None

def load_registration_data(force_refresh=False):
    """Load dataset with simple caching"""
    global _cached_df, _cache_timestamp
    import time
    
    # Refresh cache every 5 minutes
    if not force_refresh and _cached_df is not None and _cache_timestamp:
        if time.time() - _cache_timestamp < 300:
            return _cached_df
    
    try:
        dataset = load_dataset(DATASET_NAME, split="train")
        _cached_df = dataset.to_pandas()
        _cache_timestamp = time.time()
        logger.info(f"Loaded dataset with {len(_cached_df)} registrations")
        return _cached_df
    except Exception as e:
        logger.error(f"Failed to load dataset: {e}")
        return None

def verify_email(email):
    """
    Verify if an email is registered in the hackathon
    Returns simple confirmation without exposing other user details
    """
    try:
        # Validate input
        if not email or not email.strip():
            return "❌ Please enter an email address"
        
        email = email.strip().lower()
        
        # Basic email format validation
        email_pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
        if not re.match(email_pattern, email):
            return "❌ Please enter a valid email address format"
        
        logger.info(f"Verification attempt for email: {email}")
        
        # Load dataset
        df = load_registration_data()
        if df is None:
            return "❌ Unable to verify at this time. Please try again later."
        
        # Check if email exists
        match = df[df['email'].str.lower() == email]
        
        if len(match) > 0:
            registration = match.iloc[0]
            # Parse timestamp for registration date
            try:
                timestamp = pd.to_datetime(registration['timestamp'])
                reg_date = timestamp.strftime("%B %d, %Y")
            except:
                reg_date = "N/A"
            
            return f"""## βœ… Email Verified!

This email is registered for **MCP's 1st Birthday Hackathon**.

- **Registered On:** {reg_date}
- **HF Username:** {registration['hf_username']}

If this is you, you're all set! πŸŽ‰"""
        else:
            return """## ❌ Email Not Found

This email is not registered for the hackathon.

**Want to participate?** 
Register at: [MCP Birthday Registration](https://huggingface.co/spaces/MCP-1st-Birthday/gradio-hackathon-registration-winter25)"""
        
    except Exception as e:
        logger.error(f"Error during verification: {e}")
        return f"❌ An error occurred: {str(e)}"

def bulk_verify_emails(emails_text):
    """
    Verify multiple emails at once (comma or newline separated)
    Useful for sponsors to verify lists
    """
    if not emails_text or not emails_text.strip():
        return "❌ Please enter at least one email address"
    
    # Parse emails (support comma, semicolon, newline, space separation)
    emails = re.split(r'[,;\n\s]+', emails_text.strip())
    emails = [e.strip().lower() for e in emails if e.strip()]
    
    if not emails:
        return "❌ No valid emails found in input"
    
    if len(emails) > 100:
        return "❌ Please limit to 100 emails at a time"
    
    # Load dataset
    df = load_registration_data()
    if df is None:
        return "❌ Unable to verify at this time. Please try again later."
    
    registered_emails = set(df['email'].str.lower())
    
    verified = []
    not_found = []
    
    for email in emails:
        if email in registered_emails:
            verified.append(email)
        else:
            not_found.append(email)
    
    result = f"""## Bulk Verification Results

**Total Checked:** {len(emails)}
**βœ… Registered:** {len(verified)}
**❌ Not Found:** {len(not_found)}

---

"""
    
    if verified:
        result += "### βœ… Registered Emails\n"
        result += "\n".join([f"- {e}" for e in verified])
        result += "\n\n"
    
    if not_found:
        result += "### ❌ Not Found\n"
        result += "\n".join([f"- {e}" for e in not_found])
    
    return result

# Custom CSS
custom_css = """
.gradio-container {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}
#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;
}
#bulk-btn {
    background: #000000 !important;
    border: 2px solid #C8DDD7 !important;
    color: #C8DDD7 !important;
    font-weight: 600 !important;
    font-size: 16px !important;
    padding: 12px 24px !important;
    border-radius: 8px !important;
    transition: all 0.3s ease !important;
}
#bulk-btn:hover {
    transform: translateY(-2px) !important;
    background: #1a1a1a !important;
}
"""

# Create the Gradio interface
with gr.Blocks(title="MCP Birthday - Email Verification", css=custom_css, theme="ocean") as demo:
    
    gr.Markdown("""
    # πŸ“§ MCP's 1st Birthday - Email Verification
    
    **πŸ“… Event Dates:** November 14-30, 2025
    
    Quickly verify if an email is registered for the hackathon.
    """)
    
    gr.Markdown("---")
    
    with gr.Tabs():
        # Single Email Tab
        with gr.Tab("πŸ” Single Email"):
            with gr.Row():
                with gr.Column():
                    email_input = gr.Textbox(
                        label="Email Address",
                        placeholder="Enter email to verify",
                        max_lines=1
                    )
                    verify_btn = gr.Button("πŸ” Verify Email", variant="primary", size="lg", elem_id="verify-btn")
                
                with gr.Column():
                    gr.Markdown("""
                    ### Quick Verification
                    
                    Enter an email address to check if it's registered for the MCP Birthday Hackathon.
                    
                    This is useful for:
                    - Verifying your own registration
                    - Sponsors confirming participant eligibility
                    - Quick status checks
                    """)
            
            single_output = gr.Markdown()
            
            verify_btn.click(
                fn=verify_email,
                inputs=[email_input],
                outputs=single_output
            )
            
            # Also trigger on Enter key
            email_input.submit(
                fn=verify_email,
                inputs=[email_input],
                outputs=single_output
            )
        
        # Bulk Verification Tab
        with gr.Tab("πŸ“‹ Bulk Verify"):
            gr.Markdown("""
            ### Bulk Email Verification
            
            Verify multiple emails at once. Enter emails separated by commas, semicolons, or new lines.
            
            **Limit:** 100 emails per request
            """)
            
            bulk_input = gr.Textbox(
                label="Email List",
                placeholder="[email protected], [email protected]\[email protected]",
                lines=5
            )
            
            bulk_btn = gr.Button("πŸ“‹ Verify All Emails", variant="primary", size="lg", elem_id="bulk-btn")
            
            bulk_output = gr.Markdown()
            
            bulk_btn.click(
                fn=bulk_verify_emails,
                inputs=[bulk_input],
                outputs=bulk_output
            )
    
    # Footer
    gr.Markdown("""
    ---
    **πŸ”— Quick Links:**
    
    [Register for Hackathon](https://huggingface.co/spaces/MCP-1st-Birthday/gradio-hackathon-registration-winter25) | [Discord Community](https://discord.gg/92sEPT2Zhv) | [Hackathon Details](https://huggingface.co/MCP-1st-Birthday)
    """)

if __name__ == "__main__":
    demo.launch()