File size: 8,681 Bytes
8bcf79a
 
 
 
 
 
 
72af8c3
 
 
 
 
 
 
8bcf79a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/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.")