Spaces:
Running
Running
Download src/components/submit.py from newmindai/Mizan: direct link, hf CLI and curl.
- Browser
- Download file 7.76 kB
-
https://huggingface.co/spaces/newmindai/Mizan/resolve/main/src/components/submit.py
- Command line
-
hf download hf://spaces/newmindai/Mizan/src/components/submit.py
-
curl -L -o submit.py https://huggingface.co/spaces/newmindai/Mizan/resolve/main/src/components/submit.py
7.76 kB
| """ | |
| 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 "<p style='color: red; font-weight: bold;'>⚠️ Authentication required. Please log in with your Hugging Face account.</p>" | |
| # Check for local dev mock auth | |
| if isinstance(profile, str) and profile == "Sign in with Hugging Face": | |
| return "<p style='color: orange; font-weight: bold;'>⚠️ HF authentication required.</p>" | |
| # Validate model name | |
| model_error = self._validate_model_name(model_name) | |
| if model_error: | |
| return f"<p style='color: red; font-weight: bold;'>❌ {model_error}</p>" | |
| # Validate email | |
| email_error = self._validate_email(email) | |
| if email_error: | |
| return f"<p style='color: red; font-weight: bold;'>❌ {email_error}</p>" | |
| # 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""" | |
| <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.** | |
| """) | |
| # 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 | |
| """) | |