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

✅ Evaluation Request Submitted!

Model: {model_name}

Email: {email}


Next Steps:

Thank you for contributing to the Mizan Leaderboard!

""" else: return """

❌ Submission Failed

Unable to connect to the evaluation service. Please try again later.

""" except Exception as e: logger.error(f"Error submitting evaluation: {e}") return f"""

❌ Error

An unexpected error occurred. Please try again later.

""" def build(self) -> None: """Build the submit tab UI.""" gr.Markdown("### Submit Model for Evaluation") gr.Markdown(""" Submit your Turkish embedding model for evaluation on the Mizan benchmark. **Authentication with Hugging Face is required to submit evaluations.** """) # OAuth login button self.login_button = gr.LoginButton(value="Sign in with Hugging Face") self.model_input = gr.Textbox( label="Model Name", placeholder="sentence-transformers/your-model", info="HuggingFace model identifier (e.g., sentence-transformers/your-model-name)" ) self.email_input = gr.Textbox( label="Email Address", placeholder="your.email@example.com", info="Email for notifications about evaluation status and results" ) self.submit_btn = gr.Button( "Submit", variant="primary", size="lg" ) # Result output self.result_output = gr.HTML(label="Status") # Wire up submit button self.submit_btn.click( fn=self._handle_submit, inputs=[self.model_input, self.email_input, self.login_button], outputs=[self.result_output] ) # Information about the evaluation process gr.Markdown(""" ### Evaluation Process: 1. **Sign In**: First, sign in with your Hugging Face account using the button above 2. **Submit Request**: Fill out the form with your model details and email 3. **Admin Review**: Your request will be reviewed by administrators 4. **Evaluation**: If approved, your model will be evaluated on Mizan benchmark 5. **Results**: You'll receive email notifications and results will appear on the leaderboard ### Important Notes: - **Authentication Required**: You must be logged in with Hugging Face to submit evaluations - You'll receive email updates about your request status - Make sure your model is publicly available on HuggingFace - Valid email address is required for receiving results """)