File size: 11,754 Bytes
be92860
3f01bc9
be92860
 
3f01bc9
 
be92860
 
3f01bc9
 
be92860
3f01bc9
 
be92860
3f01bc9
 
 
 
be92860
3f01bc9
 
be92860
 
3f01bc9
 
be92860
 
3f01bc9
 
 
 
be92860
3f01bc9
 
 
 
 
 
 
 
 
be92860
3f01bc9
 
 
 
 
 
 
 
 
 
 
 
 
be92860
 
3f01bc9
 
 
 
 
 
 
be92860
3f01bc9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
be92860
3f01bc9
 
 
 
 
 
be92860
3f01bc9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
be92860
3f01bc9
 
 
 
 
 
be92860
3f01bc9
 
 
 
be92860
3f01bc9
 
 
be92860
3f01bc9
 
 
be92860
3f01bc9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
"""
Ultra Supreme Flux Optimizer - Main Gradio Interface
"""

import gradio as gr
import torch
import gc
import logging
import warnings
import os

from optimizer import UltraSupremeOptimizer
from constants import SCORE_GRADES

# Configure warnings and environment
warnings.filterwarnings("ignore", category=FutureWarning)
warnings.filterwarnings("ignore", category=UserWarning)
os.environ["TOKENIZERS_PARALLELISM"] = "false"

# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

# Initialize the optimizer globally
optimizer = UltraSupremeOptimizer()


def process_ultra_supreme_analysis(image):
    """Process image and generate ultra supreme analysis"""
    try:
        prompt, info, score, breakdown = optimizer.generate_ultra_supreme_prompt(image)
        
        # Find appropriate grade based on score
        grade_info = None
        for threshold, grade_data in sorted(SCORE_GRADES.items(), reverse=True):
            if score >= threshold:
                grade_info = grade_data
                break
        
        if not grade_info:
            grade_info = SCORE_GRADES[0]  # Default to lowest grade
            
        score_html = f'''
        <div style="text-align: center; padding: 2rem; background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%); border: 3px solid {grade_info["color"]}; border-radius: 16px; margin: 1rem 0; box-shadow: 0 8px 25px -5px rgba(0, 0, 0, 0.1);">
            <div style="font-size: 3rem; font-weight: 800; color: {grade_info["color"]}; margin: 0; text-shadow: 0 2px 4px rgba(0,0,0,0.1);">{score}</div>
            <div style="font-size: 1.25rem; color: #15803d; margin: 0.5rem 0; text-transform: uppercase; letter-spacing: 0.1em; font-weight: 700;">{grade_info["grade"]}</div>
            <div style="font-size: 1rem; color: #15803d; margin: 0; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 500;">Ultra Supreme Intelligence Score</div>
        </div>
        '''
        
        return prompt, info, score_html
        
    except Exception as e:
        logger.error(f"Ultra supreme wrapper error: {e}")
        return "❌ Processing failed", f"Error: {str(e)}", '<div style="text-align: center; color: red;">Error</div>'


def clear_outputs():
    """Clear all outputs and free memory"""
    gc.collect()
    if torch.cuda.is_available():
        torch.cuda.empty_cache()
    return "", "", '<div style="text-align: center; padding: 1rem;"><div style="font-size: 2rem; color: #ccc;">--</div><div style="font-size: 0.875rem; color: #999;">Ultra Supreme Score</div></div>'


def create_interface():
    """Create the Gradio interface"""
    
    css = """
    @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap');
    
    .gradio-container {
        max-width: 1600px !important;
        margin: 0 auto !important;
        font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif !important;
        background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%) !important;
    }
    
    /* FIX CRÍTICO PARA TEXTO BLANCO SOBRE BLANCO */
    .markdown-text, .markdown-text *, 
    .prose, .prose *,
    .gr-markdown, .gr-markdown *,
    div[class*="markdown"], div[class*="markdown"] * {
        color: #1f2937 !important;
    }
    
    .markdown-text h1, .markdown-text h2, .markdown-text h3, 
    .prose h1, .prose h2, .prose h3,
    .gr-markdown h1, .gr-markdown h2, .gr-markdown h3 {
        color: #111827 !important;
        font-weight: 700 !important;
    }
    
    .markdown-text p, .markdown-text li, .markdown-text ul, .markdown-text ol,
    .prose p, .prose li, .prose ul, .prose ol,
    .gr-markdown p, .gr-markdown li, .gr-markdown ul, .gr-markdown ol {
        color: #374151 !important;
    }
    
    .markdown-text strong, .prose strong, .gr-markdown strong {
        color: #111827 !important;
        font-weight: 700 !important;
    }
    
    /* Asegurar que las listas sean visibles */
    ul, ol {
        color: #374151 !important;
    }
    
    li {
        color: #374151 !important;
    }
    
    /* Bullets de listas */
    ul li::marker {
        color: #374151 !important;
    }
    
    .main-header {
        text-align: center;
        padding: 3rem 0 4rem 0;
        background: linear-gradient(135deg, #0c0a09 0%, #1c1917 30%, #292524 60%, #44403c 100%);
        color: white;
        margin: -2rem -2rem 3rem -2rem;
        border-radius: 0 0 32px 32px;
        box-shadow: 0 20px 50px -10px rgba(0, 0, 0, 0.25);
        position: relative;
        overflow: hidden;
    }
    
    .main-header::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: linear-gradient(45deg, rgba(59, 130, 246, 0.1) 0%, rgba(147, 51, 234, 0.1) 50%, rgba(236, 72, 153, 0.1) 100%);
        z-index: 1;
    }
    
    .main-title {
        font-size: 4rem !important;
        font-weight: 900 !important;
        margin: 0 0 1rem 0 !important;
        letter-spacing: -0.05em !important;
        background: linear-gradient(135deg, #60a5fa 0%, #3b82f6 25%, #8b5cf6 50%, #a855f7 75%, #ec4899 100%);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-clip: text;
        position: relative;
        z-index: 2;
    }
    
    .subtitle {
        font-size: 1.5rem !important;
        font-weight: 500 !important;
        opacity: 0.95 !important;
        margin: 0 !important;
        position: relative;
        z-index: 2;
        color: #ffffff !important;
    }
    
    .prompt-output {
        font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace !important;
        font-size: 15px !important;
        line-height: 1.8 !important;
        background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%) !important;
        border: 2px solid #e2e8f0 !important;
        border-radius: 20px !important;
        padding: 2.5rem !important;
        box-shadow: 0 20px 50px -10px rgba(0, 0, 0, 0.1) !important;
        transition: all 0.3s ease !important;
        color: #1f2937 !important;
    }
    
    .prompt-output:hover {
        box-shadow: 0 25px 60px -5px rgba(0, 0, 0, 0.15) !important;
        transform: translateY(-2px) !important;
    }
    
    /* Fix para el output de información */
    .gr-textbox label {
        color: #374151 !important;
    }
    
    /* Fix para footer */
    footer, .footer, [class*="footer"] {
        color: #374151 !important;
    }
    
    footer *, .footer *, [class*="footer"] * {
        color: #374151 !important;
    }
    
    footer a, .footer a, [class*="footer"] a {
        color: #3b82f6 !important;
        text-decoration: underline;
    }
    
    footer a:hover, .footer a:hover, [class*="footer"] a:hover {
        color: #2563eb !important;
    }
    
    /* Botones */
    .gr-button-primary {
        background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%) !important;
        border: none !important;
        color: white !important;
    }
    
    .gr-button-primary:hover {
        background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%) !important;
        transform: translateY(-1px);
        box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
    }
    
    /* Asegurar que TODOS los elementos de texto sean visibles */
    * {
        -webkit-text-fill-color: initial !important;
    }
    
    /* Solo el título principal mantiene su gradiente */
    .main-title {
        -webkit-text-fill-color: transparent !important;
    }
    """
    
    with gr.Blocks(
        theme=gr.themes.Soft(),
        title="🚀 Ultra Supreme Flux Optimizer",
        css=css
    ) as interface:
        
        gr.HTML("""
        <div class="main-header">
            <div class="main-title">🚀 ULTRA SUPREME FLUX OPTIMIZER</div>
            <div class="subtitle">Maximum Absolute Intelligence • Triple CLIP Analysis • Zero Compromise • Research Supremacy</div>
        </div>
        """)
        
        with gr.Row():
            with gr.Column(scale=1):
                gr.Markdown("## 🧠 Ultra Supreme Analysis Engine")
                
                image_input = gr.Image(
                    label="Upload image for MAXIMUM intelligence analysis",
                    type="pil",
                    height=500
                )
                
                analyze_btn = gr.Button(
                    "🚀 ULTRA SUPREME ANALYSIS",
                    variant="primary",
                    size="lg"
                )
                
                gr.Markdown("""
                ### 🔬 Maximum Absolute Intelligence
                
                **🚀 Triple CLIP Interrogation:**
                • Fast analysis for broad contextual mapping
                • Classic analysis for detailed feature extraction  
                • Best analysis for maximum depth intelligence
                
                **🧠 Ultra Deep Feature Extraction:**
                • Micro-age detection with confidence scoring
                • Cultural/religious context with semantic analysis
                • Facial micro-features and expression mapping
                • Emotional state and micro-expression detection
                • Environmental lighting and atmospheric analysis
                • Body language and pose interpretation
                • Technical photography optimization
                
                **⚡ Absolute Maximum Intelligence** - No configuration, no limits, no compromise.
                """)
            
            with gr.Column(scale=1):
                gr.Markdown("## ⚡ Ultra Supreme Result")
                
                prompt_output = gr.Textbox(
                    label="🚀 Ultra Supreme Optimized Flux Prompt",
                    placeholder="Upload an image to witness absolute maximum intelligence analysis...",
                    lines=12,
                    max_lines=20,
                    elem_classes=["prompt-output"],
                    show_copy_button=True
                )
                
                score_output = gr.HTML(
                    value='<div style="text-align: center; padding: 1rem;"><div style="font-size: 2rem; color: #ccc;">--</div><div style="font-size: 0.875rem; color: #999;">Ultra Supreme Score</div></div>'
                )
                
                info_output = gr.Markdown(value="")
                
                clear_btn = gr.Button("🗑️ Clear Ultra Analysis", size="sm")
        
        # Event handlers
        analyze_btn.click(
            fn=process_ultra_supreme_analysis,
            inputs=[image_input],
            outputs=[prompt_output, info_output, score_output]
        )
        
        clear_btn.click(
            fn=clear_outputs,
            outputs=[prompt_output, info_output, score_output]
        )
        
        gr.Markdown("""
        ---
        ### 🏆 Ultra Supreme Research Foundation
        
        This system represents the **absolute pinnacle** of image analysis and Flux prompt optimization. Using triple CLIP interrogation, 
        ultra-deep feature extraction, cultural context awareness, and emotional intelligence mapping, it achieves maximum possible 
        understanding and applies research-validated Flux rules with supreme intelligence.
        
        **🔬 Pariente AI Research Laboratory** • **🚀 Ultra Supreme Intelligence Engine**
        """)
    
    return interface


# Main execution
if __name__ == "__main__":
    demo = create_interface()
    demo.launch(
        server_name="0.0.0.0",
        server_port=7860,
        share=True,
        show_error=True
    )