Malaji71 commited on
Commit
02c3790
·
verified ·
1 Parent(s): 3293852

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +224 -205
app.py CHANGED
@@ -1,96 +1,109 @@
1
  """
2
- Ultra Supreme Flux Optimizer - Main Gradio Interface
 
3
  """
4
 
5
  import gradio as gr
6
- import torch
7
- import gc
8
  import logging
9
  import warnings
10
  import os
 
11
 
12
- from optimizer import UltraSupremeOptimizer
13
- from constants import SCORE_GRADES
 
14
 
15
- # Configure warnings and environment
16
  warnings.filterwarnings("ignore", category=FutureWarning)
17
  warnings.filterwarnings("ignore", category=UserWarning)
18
  os.environ["TOKENIZERS_PARALLELISM"] = "false"
19
 
20
- # Configure logging
21
- logging.basicConfig(level=logging.INFO)
22
  logger = logging.getLogger(__name__)
23
 
24
- # NO inicializar el optimizer globalmente
25
- optimizer = None
26
 
27
-
28
- def get_optimizer():
29
- """Get or create optimizer instance"""
30
- global optimizer
31
- if optimizer is None:
32
- optimizer = UltraSupremeOptimizer()
33
- return optimizer
34
-
35
-
36
- def process_ultra_supreme_analysis(image):
37
- """Process image and generate ultra supreme analysis"""
38
- try:
39
- # Obtener optimizer (lazy initialization)
40
- opt = get_optimizer()
41
-
42
- prompt, info, score, breakdown = opt.generate_ultra_supreme_prompt(image)
43
 
44
- # Find appropriate grade based on score
45
- grade_info = None
46
- for threshold, grade_data in sorted(SCORE_GRADES.items(), reverse=True):
47
- if score >= threshold:
48
- grade_info = grade_data
49
- break
 
 
 
 
50
 
51
- if not grade_info:
52
- grade_info = SCORE_GRADES[0] # Default to lowest grade
53
-
54
- score_html = f'''
55
- <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);">
56
- <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>
57
- <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>
58
- <div style="font-size: 1rem; color: #15803d; margin: 0; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 500;">Ultra Supreme Intelligence Score</div>
59
- </div>
60
- '''
61
 
62
- return prompt, info, score_html
63
 
64
  except Exception as e:
65
- logger.error(f"Ultra supreme wrapper error: {e}", exc_info=True)
66
- error_msg = str(e)
67
- if "GPU" in error_msg:
68
- error_msg = "GPU processing failed. The system will automatically retry with CPU."
69
- return "❌ Processing failed", f"Error: {error_msg}", '<div style="text-align: center; color: red;">Error</div>'
 
 
 
70
 
71
 
72
- def clear_outputs():
73
- """Clear all outputs and free memory"""
74
- gc.collect()
75
- if torch.cuda.is_available():
76
- torch.cuda.empty_cache()
77
- 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>'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
 
79
 
80
  def create_interface():
81
- """Create the Gradio interface"""
82
 
 
83
  css = """
84
- @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap');
85
 
86
  .gradio-container {
87
- max-width: 1600px !important;
88
  margin: 0 auto !important;
89
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif !important;
90
  background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%) !important;
91
  }
92
 
93
- /* FIX CRÍTICO PARA TEXTO BLANCO SOBRE BLANCO */
94
  .markdown-text, .markdown-text *,
95
  .prose, .prose *,
96
  .gr-markdown, .gr-markdown *,
@@ -102,246 +115,252 @@ def create_interface():
102
  .prose h1, .prose h2, .prose h3,
103
  .gr-markdown h1, .gr-markdown h2, .gr-markdown h3 {
104
  color: #111827 !important;
105
- font-weight: 700 !important;
106
  }
107
 
108
- .markdown-text p, .markdown-text li, .markdown-text ul, .markdown-text ol,
109
- .prose p, .prose li, .prose ul, .prose ol,
110
- .gr-markdown p, .gr-markdown li, .gr-markdown ul, .gr-markdown ol {
111
  color: #374151 !important;
112
  }
113
 
114
  .markdown-text strong, .prose strong, .gr-markdown strong {
115
  color: #111827 !important;
116
- font-weight: 700 !important;
117
- }
118
-
119
- /* Asegurar que las listas sean visibles */
120
- ul, ol {
121
- color: #374151 !important;
122
- }
123
-
124
- li {
125
- color: #374151 !important;
126
- }
127
-
128
- /* Bullets de listas */
129
- ul li::marker {
130
- color: #374151 !important;
131
  }
132
 
 
133
  .main-header {
134
  text-align: center;
135
- padding: 3rem 0 4rem 0;
136
- background: linear-gradient(135deg, #0c0a09 0%, #1c1917 30%, #292524 60%, #44403c 100%);
137
  color: white;
138
- margin: -2rem -2rem 3rem -2rem;
139
- border-radius: 0 0 32px 32px;
140
- box-shadow: 0 20px 50px -10px rgba(0, 0, 0, 0.25);
141
- position: relative;
142
- overflow: hidden;
143
- }
144
-
145
- .main-header::before {
146
- content: '';
147
- position: absolute;
148
- top: 0;
149
- left: 0;
150
- right: 0;
151
- bottom: 0;
152
- 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%);
153
- z-index: 1;
154
  }
155
 
156
  .main-title {
157
- font-size: 4rem !important;
158
- font-weight: 900 !important;
159
- margin: 0 0 1rem 0 !important;
160
- letter-spacing: -0.05em !important;
161
- background: linear-gradient(135deg, #60a5fa 0%, #3b82f6 25%, #8b5cf6 50%, #a855f7 75%, #ec4899 100%);
162
- -webkit-background-clip: text;
163
- -webkit-text-fill-color: transparent;
164
- background-clip: text;
165
- position: relative;
166
- z-index: 2;
167
  }
168
 
169
  .subtitle {
170
- font-size: 1.5rem !important;
171
- font-weight: 500 !important;
172
- opacity: 0.95 !important;
173
  margin: 0 !important;
174
- position: relative;
175
- z-index: 2;
176
- color: #ffffff !important;
177
  }
178
 
 
179
  .prompt-output {
180
- font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace !important;
181
- font-size: 15px !important;
182
- line-height: 1.8 !important;
183
  background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%) !important;
184
  border: 2px solid #e2e8f0 !important;
185
- border-radius: 20px !important;
186
- padding: 2.5rem !important;
187
- box-shadow: 0 20px 50px -10px rgba(0, 0, 0, 0.1) !important;
188
  transition: all 0.3s ease !important;
189
  color: #1f2937 !important;
190
  }
191
 
192
  .prompt-output:hover {
193
- box-shadow: 0 25px 60px -5px rgba(0, 0, 0, 0.15) !important;
194
- transform: translateY(-2px) !important;
195
- }
196
-
197
- /* Fix para el output de información */
198
- .gr-textbox label {
199
- color: #374151 !important;
200
- }
201
-
202
- /* Fix para footer */
203
- footer, .footer, [class*="footer"] {
204
- color: #374151 !important;
205
- }
206
-
207
- footer *, .footer *, [class*="footer"] * {
208
- color: #374151 !important;
209
- }
210
-
211
- footer a, .footer a, [class*="footer"] a {
212
- color: #3b82f6 !important;
213
- text-decoration: underline;
214
  }
215
 
216
- footer a:hover, .footer a:hover, [class*="footer"] a:hover {
217
- color: #2563eb !important;
218
- }
219
-
220
- /* Botones */
221
  .gr-button-primary {
222
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%) !important;
223
  border: none !important;
224
  color: white !important;
 
 
 
 
225
  }
226
 
227
  .gr-button-primary:hover {
228
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%) !important;
229
- transform: translateY(-1px);
230
- box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
231
  }
232
 
233
- /* Asegurar que TODOS los elementos de texto sean visibles */
234
- * {
235
- -webkit-text-fill-color: initial !important;
 
 
 
236
  }
237
 
238
- /* Solo el título principal mantiene su gradiente */
239
- .main-title {
240
- -webkit-text-fill-color: transparent !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
241
  }
242
  """
243
 
244
  with gr.Blocks(
245
- theme=gr.themes.Soft(),
246
- title="🚀 Ultra Supreme Flux Optimizer",
 
 
 
 
247
  css=css
248
  ) as interface:
249
 
 
250
  gr.HTML("""
251
  <div class="main-header">
252
- <div class="main-title">🚀 ULTRA SUPREME FLUX OPTIMIZER</div>
253
- <div class="subtitle">Maximum Absolute Intelligence • Triple CLIP Analysis Zero Compromise • Research Supremacy</div>
254
  </div>
255
  """)
256
 
 
257
  with gr.Row():
 
258
  with gr.Column(scale=1):
259
- gr.Markdown("## 🧠 Ultra Supreme Analysis Engine")
260
 
261
  image_input = gr.Image(
262
- label="Upload image for MAXIMUM intelligence analysis",
263
  type="pil",
264
- height=500
265
  )
266
 
267
- analyze_btn = gr.Button(
268
- "🚀 ULTRA SUPREME ANALYSIS",
269
- variant="primary",
270
- size="lg"
271
- )
 
 
 
 
 
 
 
272
 
 
273
  gr.Markdown("""
274
- ### 🔬 Maximum Absolute Intelligence
275
 
276
- **🚀 Triple CLIP Interrogation:**
277
- • Fast analysis for broad contextual mapping
278
- • Classic analysis for detailed feature extraction
279
- • Best analysis for maximum depth intelligence
280
 
281
- **🧠 Ultra Deep Feature Extraction:**
282
- • Micro-age detection with confidence scoring
283
- • Cultural/religious context with semantic analysis
284
- • Facial micro-features and expression mapping
285
- • Emotional state and micro-expression detection
286
- • Environmental lighting and atmospheric analysis
287
- • Body language and pose interpretation
288
- • Technical photography optimization
289
 
290
- **⚡ Absolute Maximum Intelligence** - No configuration, no limits, no compromise.
 
 
291
  """)
 
 
 
 
 
 
 
 
 
 
292
 
 
293
  with gr.Column(scale=1):
294
- gr.Markdown("## ⚡ Ultra Supreme Result")
 
 
 
 
 
295
 
 
296
  prompt_output = gr.Textbox(
297
- label="🚀 Ultra Supreme Optimized Flux Prompt",
298
- placeholder="Upload an image to witness absolute maximum intelligence analysis...",
299
- lines=12,
300
- max_lines=20,
301
  elem_classes=["prompt-output"],
302
  show_copy_button=True
303
  )
304
 
305
- score_output = gr.HTML(
306
- 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>'
307
- )
308
-
309
- info_output = gr.Markdown(value="")
310
-
311
- clear_btn = gr.Button("🗑️ Clear Ultra Analysis", size="sm")
312
 
313
  # Event handlers
314
  analyze_btn.click(
315
- fn=process_ultra_supreme_analysis,
316
  inputs=[image_input],
317
  outputs=[prompt_output, info_output, score_output]
318
  )
319
 
320
  clear_btn.click(
321
- fn=clear_outputs,
322
  outputs=[prompt_output, info_output, score_output]
323
  )
324
 
 
325
  gr.Markdown("""
326
  ---
327
- ### 🏆 Ultra Supreme Research Foundation
328
-
329
- This system represents the **absolute pinnacle** of image analysis and Flux prompt optimization. Using triple CLIP interrogation,
330
- ultra-deep feature extraction, cultural context awareness, and emotional intelligence mapping, it achieves maximum possible
331
- understanding and applies research-validated Flux rules with supreme intelligence.
332
 
333
- **🔬 Pariente AI Research Laboratory** **�� Ultra Supreme Intelligence Engine**
 
 
334
  """)
335
 
336
  return interface
337
 
338
 
339
- # Main execution
340
- if __name__ == "__main__":
 
 
 
341
  demo = create_interface()
342
- demo.launch(
343
- server_name="0.0.0.0",
344
- server_port=7860,
345
- share=True,
346
- show_error=True
347
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  """
2
+ Frame 0 Laboratory for MIA - Main Gradio Interface
3
+ FLUX Prompt Optimizer with clean, professional interface
4
  """
5
 
6
  import gradio as gr
 
 
7
  import logging
8
  import warnings
9
  import os
10
+ from typing import Tuple
11
 
12
+ from config import APP_CONFIG, ENVIRONMENT
13
+ from processor import process_image_simple, flux_optimizer
14
+ from utils import setup_logging, clean_memory
15
 
16
+ # Configure environment
17
  warnings.filterwarnings("ignore", category=FutureWarning)
18
  warnings.filterwarnings("ignore", category=UserWarning)
19
  os.environ["TOKENIZERS_PARALLELISM"] = "false"
20
 
21
+ # Setup logging
22
+ setup_logging(ENVIRONMENT["log_level"])
23
  logger = logging.getLogger(__name__)
24
 
 
 
25
 
26
+ def process_image_interface(image) -> Tuple[str, str, str]:
27
+ """
28
+ Main interface function for image processing
29
+
30
+ Args:
31
+ image: Input image from Gradio interface
 
 
 
 
 
 
 
 
 
 
32
 
33
+ Returns:
34
+ Tuple of (prompt, analysis_report, score_html)
35
+ """
36
+ try:
37
+ if image is None:
38
+ return (
39
+ "Please upload an image to analyze",
40
+ "No image provided for analysis.",
41
+ '<div style="text-align: center; padding: 1rem;"><div style="font-size: 2rem; color: #ccc;">--</div><div style="font-size: 0.875rem; color: #999;">Quality Score</div></div>'
42
+ )
43
 
44
+ logger.info("Processing image through interface")
45
+ prompt, report, score_html = process_image_simple(image)
 
 
 
 
 
 
 
 
46
 
47
+ return prompt, report, score_html
48
 
49
  except Exception as e:
50
+ logger.error(f"Interface processing error: {e}", exc_info=True)
51
+ error_msg = f"Processing failed: {str(e)}"
52
+
53
+ return (
54
+ "❌ Processing failed",
55
+ f"**Error:** {error_msg}\n\nPlease try again with a different image.",
56
+ '<div style="text-align: center; padding: 1rem; color: red;"><div style="font-size: 2rem;">0</div><div style="font-size: 0.875rem;">Error</div></div>'
57
+ )
58
 
59
 
60
+ def clear_interface() -> Tuple[str, str, str]:
61
+ """Clear all interface outputs and free memory"""
62
+ clean_memory()
63
+ logger.info("Interface cleared")
64
+
65
+ return (
66
+ "",
67
+ "",
68
+ '<div style="text-align: center; padding: 1rem;"><div style="font-size: 2rem; color: #ccc;">--</div><div style="font-size: 0.875rem; color: #999;">Quality Score</div></div>'
69
+ )
70
+
71
+
72
+ def get_stats_info() -> str:
73
+ """Get current processing statistics"""
74
+ try:
75
+ stats = flux_optimizer.get_stats()
76
+
77
+ stats_text = f"""**Processing Statistics:**
78
+ • **Total Images:** {stats['total_processed']}
79
+ • **Successful:** {stats['successful_analyses']}
80
+ • **Failed:** {stats['failed_analyses']}
81
+ • **Success Rate:** {stats['success_rate']:.1%}
82
+ • **Average Time:** {stats['average_processing_time']:.1f}s
83
+ • **Device:** {stats['device_info']['device'].upper()}
84
+ """
85
+ return stats_text
86
+
87
+ except Exception as e:
88
+ logger.error(f"Stats retrieval error: {e}")
89
+ return "Statistics unavailable"
90
 
91
 
92
  def create_interface():
93
+ """Create the main Gradio interface"""
94
 
95
+ # Custom CSS for clean, professional look
96
  css = """
97
+ @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');
98
 
99
  .gradio-container {
100
+ max-width: 1400px !important;
101
  margin: 0 auto !important;
102
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif !important;
103
  background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%) !important;
104
  }
105
 
106
+ /* Text visibility fixes */
107
  .markdown-text, .markdown-text *,
108
  .prose, .prose *,
109
  .gr-markdown, .gr-markdown *,
 
115
  .prose h1, .prose h2, .prose h3,
116
  .gr-markdown h1, .gr-markdown h2, .gr-markdown h3 {
117
  color: #111827 !important;
118
+ font-weight: 600 !important;
119
  }
120
 
121
+ .markdown-text p, .markdown-text li,
122
+ .prose p, .prose li,
123
+ .gr-markdown p, .gr-markdown li {
124
  color: #374151 !important;
125
  }
126
 
127
  .markdown-text strong, .prose strong, .gr-markdown strong {
128
  color: #111827 !important;
129
+ font-weight: 600 !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  }
131
 
132
+ /* Header styling */
133
  .main-header {
134
  text-align: center;
135
+ padding: 2.5rem 0 3rem 0;
136
+ background: linear-gradient(135deg, #1e293b 0%, #334155 50%, #475569 100%);
137
  color: white;
138
+ margin: -2rem -2rem 2rem -2rem;
139
+ border-radius: 0 0 24px 24px;
140
+ box-shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.2);
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  }
142
 
143
  .main-title {
144
+ font-size: 2.5rem !important;
145
+ font-weight: 700 !important;
146
+ margin: 0 0 0.5rem 0 !important;
147
+ letter-spacing: -0.025em !important;
148
+ color: #ffffff !important;
 
 
 
 
 
149
  }
150
 
151
  .subtitle {
152
+ font-size: 1.125rem !important;
153
+ font-weight: 400 !important;
154
+ opacity: 0.9 !important;
155
  margin: 0 !important;
156
+ color: #cbd5e1 !important;
 
 
157
  }
158
 
159
+ /* Prompt output styling */
160
  .prompt-output {
161
+ font-family: 'SF Mono', 'Monaco', 'Consolas', monospace !important;
162
+ font-size: 14px !important;
163
+ line-height: 1.6 !important;
164
  background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%) !important;
165
  border: 2px solid #e2e8f0 !important;
166
+ border-radius: 12px !important;
167
+ padding: 1.5rem !important;
168
+ box-shadow: 0 4px 15px -2px rgba(0, 0, 0, 0.08) !important;
169
  transition: all 0.3s ease !important;
170
  color: #1f2937 !important;
171
  }
172
 
173
  .prompt-output:hover {
174
+ box-shadow: 0 8px 25px -5px rgba(0, 0, 0, 0.12) !important;
175
+ transform: translateY(-1px) !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
  }
177
 
178
+ /* Button styling */
 
 
 
 
179
  .gr-button-primary {
180
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%) !important;
181
  border: none !important;
182
  color: white !important;
183
+ font-weight: 500 !important;
184
+ padding: 0.75rem 1.5rem !important;
185
+ border-radius: 8px !important;
186
+ transition: all 0.2s ease !important;
187
  }
188
 
189
  .gr-button-primary:hover {
190
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%) !important;
191
+ transform: translateY(-1px) !important;
192
+ box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3) !important;
193
  }
194
 
195
+ .gr-button-secondary {
196
+ background: #f1f5f9 !important;
197
+ border: 1px solid #cbd5e1 !important;
198
+ color: #475569 !important;
199
+ font-weight: 500 !important;
200
+ border-radius: 8px !important;
201
  }
202
 
203
+ .gr-button-secondary:hover {
204
+ background: #e2e8f0 !important;
205
+ border-color: #94a3b8 !important;
206
+ }
207
+
208
+ /* Image upload area */
209
+ .gr-file-upload {
210
+ border: 2px dashed #cbd5e1 !important;
211
+ border-radius: 12px !important;
212
+ background: #f8fafc !important;
213
+ }
214
+
215
+ /* Info boxes */
216
+ .info-box {
217
+ background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
218
+ border: 1px solid #0284c7;
219
+ border-radius: 12px;
220
+ padding: 1rem;
221
+ margin: 1rem 0;
222
  }
223
  """
224
 
225
  with gr.Blocks(
226
+ theme=gr.themes.Soft(
227
+ primary_hue="blue",
228
+ secondary_hue="slate",
229
+ neutral_hue="slate"
230
+ ),
231
+ title="Frame 0 Laboratory for MIA",
232
  css=css
233
  ) as interface:
234
 
235
+ # Header
236
  gr.HTML("""
237
  <div class="main-header">
238
+ <div class="main-title">Frame 0 Laboratory for MIA</div>
239
+ <div class="subtitle">Advanced Image Analysis & FLUX Prompt Optimization</div>
240
  </div>
241
  """)
242
 
243
+ # Main interface
244
  with gr.Row():
245
+ # Left column - Input
246
  with gr.Column(scale=1):
247
+ gr.Markdown("## Image Analysis")
248
 
249
  image_input = gr.Image(
250
+ label="Upload Image for Analysis",
251
  type="pil",
252
+ height=400
253
  )
254
 
255
+ with gr.Row():
256
+ analyze_btn = gr.Button(
257
+ "🔍 Analyze Image",
258
+ variant="primary",
259
+ size="lg"
260
+ )
261
+
262
+ clear_btn = gr.Button(
263
+ "🗑️ Clear",
264
+ variant="secondary",
265
+ size="lg"
266
+ )
267
 
268
+ # Information panel
269
  gr.Markdown("""
270
+ ### How it works:
271
 
272
+ **1. Image Analysis:** Advanced AI models analyze your image to understand content, composition, and style.
 
 
 
273
 
274
+ **2. FLUX Optimization:** Applies proven rules for FLUX image generation including camera settings, lighting, and technical parameters.
 
 
 
 
 
 
 
275
 
276
+ **3. Quality Scoring:** Evaluates the optimized prompt across multiple dimensions for best results.
277
+
278
+ **Supported formats:** JPG, PNG, WebP up to 1024px
279
  """)
280
+
281
+ # Statistics (collapsible)
282
+ with gr.Accordion("📊 Processing Stats", open=False):
283
+ stats_output = gr.Markdown(value="No processing completed yet.")
284
+
285
+ refresh_stats_btn = gr.Button("Refresh Stats", size="sm")
286
+ refresh_stats_btn.click(
287
+ fn=get_stats_info,
288
+ outputs=stats_output
289
+ )
290
 
291
+ # Right column - Output
292
  with gr.Column(scale=1):
293
+ gr.Markdown("## Results")
294
+
295
+ # Score display
296
+ score_output = gr.HTML(
297
+ value='<div style="text-align: center; padding: 1rem;"><div style="font-size: 2rem; color: #ccc;">--</div><div style="font-size: 0.875rem; color: #999;">Quality Score</div></div>'
298
+ )
299
 
300
+ # Optimized prompt
301
  prompt_output = gr.Textbox(
302
+ label="🎯 Optimized FLUX Prompt",
303
+ placeholder="Upload an image to generate an optimized prompt...",
304
+ lines=8,
305
+ max_lines=15,
306
  elem_classes=["prompt-output"],
307
  show_copy_button=True
308
  )
309
 
310
+ # Analysis report
311
+ with gr.Accordion("📋 Detailed Analysis", open=True):
312
+ info_output = gr.Markdown(value="")
 
 
 
 
313
 
314
  # Event handlers
315
  analyze_btn.click(
316
+ fn=process_image_interface,
317
  inputs=[image_input],
318
  outputs=[prompt_output, info_output, score_output]
319
  )
320
 
321
  clear_btn.click(
322
+ fn=clear_interface,
323
  outputs=[prompt_output, info_output, score_output]
324
  )
325
 
326
+ # Footer
327
  gr.Markdown("""
328
  ---
329
+ **Frame 0 Laboratory for MIA** • Advanced AI Research & Development
 
 
 
 
330
 
331
+ This tool uses state-of-the-art vision-language models to analyze images and generate optimized prompts
332
+ for FLUX image generation. The system applies proven optimization rules including camera configurations,
333
+ lighting setups, and technical parameters for best results.
334
  """)
335
 
336
  return interface
337
 
338
 
339
+ def main():
340
+ """Main application entry point"""
341
+ logger.info("Starting Frame 0 Laboratory for MIA")
342
+
343
+ # Create and launch interface
344
  demo = create_interface()
345
+
346
+ # Launch configuration
347
+ launch_config = {
348
+ "server_name": "0.0.0.0",
349
+ "server_port": 7860,
350
+ "show_error": True,
351
+ "show_tips": True,
352
+ "enable_queue": True
353
+ }
354
+
355
+ # Add share option for Spaces
356
+ if ENVIRONMENT["is_spaces"]:
357
+ launch_config["share"] = False # Spaces handles sharing
358
+ else:
359
+ launch_config["share"] = True # Enable sharing for local
360
+
361
+ logger.info(f"Launching on port {launch_config['server_port']}")
362
+ demo.launch(**launch_config)
363
+
364
+
365
+ if __name__ == "__main__":
366
+ main()