""" Submit Tab Component Model evaluation submission with HuggingFace authentication. """ import logging import re from typing import Optional, Tuple import gradio as gr from ..api import EvaluationApiClient logger = logging.getLogger(__name__) class SubmitTab: """ Submit evaluation tab component. Provides: - HuggingFace OAuth login - Model submission form - Email notification setup """ def __init__(self): self.api_client = EvaluationApiClient() # UI components (will be set during build) self.model_input: Optional[gr.Textbox] = None self.email_input: Optional[gr.Textbox] = None self.submit_btn: Optional[gr.Button] = None self.login_button: Optional[gr.LoginButton] = None self.result_output: Optional[gr.HTML] = None def _validate_model_name(self, model_name: str) -> Optional[str]: """Validate model name format.""" if not model_name or not model_name.strip(): return "Model name cannot be empty!" model_name = model_name.strip() if len(model_name) < 3: return "Model name too short!" if len(model_name) > 256: return "Model name too long (maximum 256 characters)!" if '/' not in model_name: return "Invalid format! Must include organization (e.g., organization/model-name)" if not re.match(r'^[a-zA-Z0-9._-]+/[a-zA-Z0-9._-]+$', model_name): return "Invalid format! Use format: organization/model-name" return None def _validate_email(self, email: str) -> Optional[str]: """Validate email format.""" if not email or not email.strip(): return "Email address cannot be empty!" email = email.strip() if len(email) > 254: return "Email address too long!" email_pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' if not re.match(email_pattern, email): return "Invalid email address format!" return None def _handle_submit(self, model_name: str, email: str, profile) -> str: """Handle evaluation submission.""" # Authentication check if profile is None: return "
⚠️ Authentication required. Please log in with your Hugging Face account.
" # Check for local dev mock auth if isinstance(profile, str) and profile == "Sign in with Hugging Face": return "⚠️ HF authentication required.
" # Validate model name model_error = self._validate_model_name(model_name) if model_error: return f"❌ {model_error}
" # Validate email email_error = self._validate_email(email) if email_error: return f"❌ {email_error}
" # Submit to API model_name = model_name.strip() email = email.strip() try: success = self.api_client.submit_evaluation(model_name, email) if success: return f"""Model: {model_name}
Email: {email}
Next Steps:
Thank you for contributing to the Mizan Leaderboard!
Unable to connect to the evaluation service. Please try again later.
An unexpected error occurred. Please try again later.