Spaces:
Paused
Paused
| #!/usr/bin/env python3 | |
| """ | |
| Integration script for advanced training interface | |
| Shows how to add comprehensive parameter controls to the main Gradio app | |
| """ | |
| import gradio as gr | |
| import sys | |
| import os | |
| # Add parent directory to path to find ui module | |
| sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
| from ui.advanced_training import create_advanced_training_interface, start_advanced_training, start_simple_training | |
| def create_enhanced_app(): | |
| """Create the main app with advanced training controls integrated.""" | |
| with gr.Blocks(title="Dressify - Enhanced Outfit Recommendation", fill_height=True) as app: | |
| gr.Markdown("## π Dressify β Advanced Outfit Recommendation System\n*Research-grade, self-contained outfit recommendation with comprehensive training controls*") | |
| with gr.Tabs(): | |
| # Main recommendation tab | |
| with gr.Tab("π¨ Recommend"): | |
| gr.Markdown("### Upload wardrobe images and generate outfit recommendations") | |
| # ... your existing recommendation interface | |
| pass | |
| # Advanced training tab | |
| with gr.Tab("π¬ Advanced Training"): | |
| # Create the advanced training interface | |
| training_interface, components = create_advanced_training_interface() | |
| # Set up event handlers for the training interface | |
| components['start_btn'].click( | |
| fn=start_simple_training, | |
| inputs=[components['resnet_epochs'], components['vit_epochs']], | |
| outputs=components['train_log'] | |
| ) | |
| components['start_advanced_btn'].click( | |
| fn=start_advanced_training, | |
| inputs=[ | |
| # ResNet parameters | |
| components['resnet_epochs'], components['resnet_batch_size'], components['resnet_lr'], | |
| components['resnet_optimizer'], components['resnet_weight_decay'], components['resnet_triplet_margin'], | |
| components['resnet_embedding_dim'], components['resnet_backbone'], components['resnet_use_pretrained'], | |
| components['resnet_dropout'], | |
| # ViT parameters | |
| components['vit_epochs'], components['vit_batch_size'], components['vit_lr'], | |
| components['vit_optimizer'], components['vit_weight_decay'], components['vit_triplet_margin'], | |
| components['vit_embedding_dim'], components['vit_num_layers'], components['vit_num_heads'], | |
| components['vit_ff_multiplier'], components['vit_dropout'], | |
| # Advanced parameters | |
| components['use_mixed_precision'], components['channels_last'], components['gradient_clip'], | |
| components['warmup_epochs'], components['scheduler_type'], components['early_stopping_patience'], | |
| components['mining_strategy'], components['augmentation_level'], components['seed'] | |
| ], | |
| outputs=components['train_log'] | |
| ) | |
| # Simple training tab | |
| with gr.Tab("π Simple Training"): | |
| gr.Markdown("### Quick training with default parameters") | |
| epochs_res = gr.Slider(1, 50, value=10, step=1, label="ResNet epochs") | |
| epochs_vit = gr.Slider(1, 100, value=20, step=1, label="ViT epochs") | |
| train_log = gr.Textbox(label="Training Log", lines=10) | |
| start_btn = gr.Button("Start Training") | |
| start_btn.click(fn=start_simple_training, inputs=[epochs_res, epochs_vit], outputs=train_log) | |
| # Other tabs... | |
| with gr.Tab("π Embed (Debug)"): | |
| gr.Markdown("### Debug image embeddings") | |
| # ... your existing embed interface | |
| pass | |
| with gr.Tab("π₯ Downloads"): | |
| gr.Markdown("### Download trained models and artifacts") | |
| # ... your existing downloads interface | |
| pass | |
| with gr.Tab("π Status"): | |
| gr.Markdown("### System status and monitoring") | |
| # ... your existing status interface | |
| pass | |
| return app | |
| def create_minimal_integration(): | |
| """Minimal integration example - just add the advanced training tab to existing app.""" | |
| # This shows how to add just the advanced training interface to your existing app.py | |
| # 1. Import the advanced training functions | |
| from advanced_training_ui import create_advanced_training_interface, start_advanced_training | |
| # 2. In your existing app.py, add this tab: | |
| """ | |
| with gr.Tab("π¬ Advanced Training"): | |
| # Create the advanced training interface | |
| training_interface, components = create_advanced_training_interface() | |
| # Set up event handlers | |
| components['start_advanced_btn'].click( | |
| fn=start_advanced_training, | |
| inputs=[ | |
| components['resnet_epochs'], components['resnet_batch_size'], components['resnet_lr'], | |
| components['resnet_optimizer'], components['resnet_weight_decay'], components['resnet_triplet_margin'], | |
| components['resnet_embedding_dim'], components['resnet_backbone'], components['resnet_use_pretrained'], | |
| components['resnet_dropout'], components['vit_epochs'], components['vit_batch_size'], components['vit_lr'], | |
| components['vit_optimizer'], components['vit_weight_decay'], components['vit_triplet_margin'], | |
| components['vit_embedding_dim'], components['vit_num_layers'], components['vit_num_heads'], | |
| components['vit_ff_multiplier'], components['vit_dropout'], components['use_mixed_precision'], | |
| components['channels_last'], components['gradient_clip'], components['warmup_epochs'], | |
| components['scheduler_type'], components['early_stopping_patience'], components['mining_strategy'], | |
| components['augmentation_level'], components['seed'] | |
| ], | |
| outputs=components['train_log'] | |
| ) | |
| """ | |
| print("β Advanced training interface ready for integration!") | |
| print("π Copy the code above into your existing app.py") | |
| def show_parameter_examples(): | |
| """Show examples of different parameter combinations.""" | |
| examples = { | |
| "Quick Experiment": { | |
| "resnet_epochs": 5, | |
| "vit_epochs": 10, | |
| "batch_size": 16, | |
| "learning_rate": 1e-3, | |
| "description": "Fast training for parameter testing" | |
| }, | |
| "Balanced Training": { | |
| "resnet_epochs": 20, | |
| "vit_epochs": 30, | |
| "batch_size": 64, | |
| "learning_rate": 1e-3, | |
| "description": "Standard quality training (default)" | |
| }, | |
| "High Quality": { | |
| "resnet_epochs": 50, | |
| "vit_epochs": 100, | |
| "batch_size": 32, | |
| "learning_rate": 5e-4, | |
| "description": "Production-quality models" | |
| }, | |
| "Research Mode": { | |
| "resnet_backbone": "resnet101", | |
| "embedding_dim": 768, | |
| "transformer_layers": 8, | |
| "attention_heads": 12, | |
| "mining_strategy": "hardest", | |
| "description": "Maximum model capacity" | |
| } | |
| } | |
| print("π― Parameter Combination Examples:") | |
| print("=" * 50) | |
| for name, params in examples.items(): | |
| print(f"\nπ {name}:") | |
| for key, value in params.items(): | |
| if key != "description": | |
| print(f" {key}: {value}") | |
| print(f" π‘ {params['description']}") | |
| if __name__ == "__main__": | |
| print("π Dressify Advanced Training Integration") | |
| print("=" * 50) | |
| print("\n1οΈβ£ Create enhanced app with all features:") | |
| print(" enhanced_app = create_enhanced_app()") | |
| print("\n2οΈβ£ Minimal integration into existing app:") | |
| create_minimal_integration() | |
| print("\n3οΈβ£ Parameter combination examples:") | |
| show_parameter_examples() | |
| print("\nβ Integration complete! Your app now has comprehensive training controls.") | |
| print("\nπ See TRAINING_PARAMETERS.md for detailed parameter explanations.") | |
| print("π§ Use the advanced training interface to experiment with different configurations.") | |