|
|
""" |
|
|
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() |
|
|
|
|
|
|
|
|
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.""" |
|
|
|
|
|
if profile is None: |
|
|
return "<p style='color: red; font-weight: bold;'>⚠️ Authentication required. Please log in with your Hugging Face account.</p>" |
|
|
|
|
|
|
|
|
if isinstance(profile, str) and profile == "Sign in with Hugging Face": |
|
|
return "<p style='color: orange; font-weight: bold;'>⚠️ HF authentication required.</p>" |
|
|
|
|
|
|
|
|
model_error = self._validate_model_name(model_name) |
|
|
if model_error: |
|
|
return f"<p style='color: red; font-weight: bold;'>❌ {model_error}</p>" |
|
|
|
|
|
|
|
|
email_error = self._validate_email(email) |
|
|
if email_error: |
|
|
return f"<p style='color: red; font-weight: bold;'>❌ {email_error}</p>" |
|
|
|
|
|
|
|
|
model_name = model_name.strip() |
|
|
email = email.strip() |
|
|
|
|
|
try: |
|
|
success = self.api_client.submit_evaluation(model_name, email) |
|
|
|
|
|
if success: |
|
|
return f""" |
|
|
<div style='padding: 16px; background: #d4edda; border-radius: 8px; border: 1px solid #c3e6cb; color: #155724;'> |
|
|
<h3 style='color: #155724; margin: 0 0 12px 0;'>✅ Evaluation Request Submitted!</h3> |
|
|
<p style='color: #155724; margin: 4px 0;'><strong style='color: #155724;'>Model:</strong> {model_name}</p> |
|
|
<p style='color: #155724; margin: 4px 0;'><strong style='color: #155724;'>Email:</strong> {email}</p> |
|
|
<hr style='margin: 12px 0; border-color: #c3e6cb;'> |
|
|
<p style='color: #155724; margin: 4px 0;'><strong style='color: #155724;'>Next Steps:</strong></p> |
|
|
<ul style='color: #155724; margin: 8px 0; padding-left: 20px;'> |
|
|
<li style='color: #155724;'>Your request will be reviewed by our system</li> |
|
|
<li style='color: #155724;'>You will receive email notifications about the status</li> |
|
|
<li style='color: #155724;'>Results will appear on the leaderboard when complete</li> |
|
|
</ul> |
|
|
<p style='color: #155724; margin-top: 12px; font-style: italic;'>Thank you for contributing to the Mizan Leaderboard!</p> |
|
|
</div> |
|
|
""" |
|
|
else: |
|
|
return """ |
|
|
<div style='padding: 16px; background: #f8d7da; border-radius: 8px; border: 1px solid #f5c6cb;'> |
|
|
<h3 style='color: #721c24; margin: 0 0 8px 0;'>❌ Submission Failed</h3> |
|
|
<p>Unable to connect to the evaluation service. Please try again later.</p> |
|
|
</div> |
|
|
""" |
|
|
except Exception as e: |
|
|
logger.error(f"Error submitting evaluation: {e}") |
|
|
return f""" |
|
|
<div style='padding: 16px; background: #f8d7da; border-radius: 8px; border: 1px solid #f5c6cb;'> |
|
|
<h3 style='color: #721c24; margin: 0 0 8px 0;'>❌ Error</h3> |
|
|
<p>An unexpected error occurred. Please try again later.</p> |
|
|
</div> |
|
|
""" |
|
|
|
|
|
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.** |
|
|
""") |
|
|
|
|
|
|
|
|
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" |
|
|
) |
|
|
|
|
|
|
|
|
self.result_output = gr.HTML(label="Status") |
|
|
|
|
|
|
|
|
self.submit_btn.click( |
|
|
fn=self._handle_submit, |
|
|
inputs=[self.model_input, self.email_input, self.login_button], |
|
|
outputs=[self.result_output] |
|
|
) |
|
|
|
|
|
|
|
|
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 |
|
|
""") |
|
|
|