Spaces:
Running
Running
| import asyncio | |
| import gradio as gr | |
| from backend.api import submit_model | |
| from frontend.leaderboard import parse_parameter_count | |
| def handle_submission( | |
| model_name, | |
| hf_space_tag, | |
| model_description, | |
| organization, | |
| model_size, | |
| pretrained, | |
| pretraining_data, | |
| publication_title, | |
| publication_link, | |
| zero_shot, | |
| few_shot, | |
| n_shot | |
| ): | |
| """Handle model submission from the form.""" | |
| # Basic validation | |
| if not model_name or not hf_space_tag or not model_description or not organization or not model_size or not pretrained or not publication_title or not publication_link or not zero_shot or not few_shot: | |
| return "<div style='color: red;'>Please fill in all required fields (*)</div>" | |
| if "/" not in hf_space_tag: | |
| return "<div style='color: red;'>HuggingFace space tag should be in format 'username/space-name'</div>" | |
| # Parse and validate model_size | |
| parsed_model_size = parse_parameter_count(model_size) | |
| if model_size and parsed_model_size is None: | |
| return "<div style='color: red;'>Invalid model size format. Use raw numbers (e.g., 120000000) or human-readable format (e.g., 120M, 0.12B)</div>" | |
| # Process submission | |
| try: | |
| result = asyncio.run(submit_model( | |
| model_name=model_name, | |
| hf_space_tag=hf_space_tag, | |
| model_description=model_description, | |
| organization=organization or "", | |
| model_size=parsed_model_size, | |
| pretrained = pretrained, | |
| pretraining_data = pretraining_data or "", | |
| publication_title=publication_title or "", | |
| publication_link=publication_link or "", | |
| zero_shot = zero_shot, | |
| few_shot = few_shot, | |
| n_shot = n_shot, | |
| )) | |
| return "<div style='color: green;'> Success! Your model has been submitted for evaluation. Results pending approval.</div>" | |
| except Exception as e: | |
| return f"<div style='color: red;'>L Error: {str(e)}</div>" |