mgbam commited on
Commit
185e6e8
Β·
verified Β·
1 Parent(s): e8a79f3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +824 -1149
app.py CHANGED
@@ -2,19 +2,19 @@ import os
2
  import uuid
3
  import base64
4
  import tempfile
5
- from typing import Dict, List, Optional, Tuple, Union
6
 
7
  import gradio as gr
8
 
9
- # Import all our modules
10
  from config import (
11
  AVAILABLE_MODELS, DEFAULT_MODEL, THEME_CONFIGS, DEMO_LIST,
12
- HTML_SYSTEM_PROMPT, get_saved_theme, save_theme_preference, get_gradio_language
13
  )
14
  from utils import (
15
  get_inference_client, remove_code_block, extract_text_from_file,
16
  create_multimodal_message, apply_search_replace_changes,
17
- cleanup_all_temp_media, reap_old_media, process_image_for_model
18
  )
19
  from web_utils import extract_website_content, enhance_query_with_search
20
  from media_generation import (
@@ -29,1206 +29,881 @@ from code_processing import (
29
  validate_and_autofix_files, inline_multipage_into_single_preview,
30
  apply_generated_media_to_html
31
  )
 
 
32
 
33
  # Initialize theme
34
  current_theme_name = get_saved_theme()
35
  current_theme = THEME_CONFIGS[current_theme_name]["theme"]
36
 
37
- class AnyCoder:
38
- """Main AnyCoder application class"""
39
-
40
- def __init__(self):
41
- self.setup_cleanup()
 
 
 
 
 
 
 
 
42
 
43
- def setup_cleanup(self):
44
- """Setup cleanup handlers"""
45
- cleanup_all_temp_media()
46
- reap_old_media()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
 
48
- def create_advanced_ui(self):
49
- """Create the advanced professional UI"""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
- with gr.Blocks(
52
- title="AnyCoder - Professional AI Development Suite",
53
- theme=current_theme,
54
- css=self.get_custom_css(),
55
- head=self.get_head_html()
56
- ) as app:
57
- # State management
58
- history = gr.State([])
59
- setting = gr.State({"system": HTML_SYSTEM_PROMPT})
60
- current_model = gr.State(DEFAULT_MODEL)
61
- session_state = gr.State({})
62
-
63
- # Header
64
- with gr.Row(elem_classes=["header-row"]):
65
- with gr.Column(scale=3):
66
- gr.HTML("""
67
- <div class="app-header">
68
- <div class="header-content">
69
- <div class="logo-section">
70
- <div class="logo">⚑</div>
71
- <div class="app-title">
72
- <h1>AnyCoder</h1>
73
- <p>Professional AI Development Suite</p>
74
- </div>
75
- </div>
76
- <div class="status-indicators">
77
- <div class="status-item">
78
- <span class="status-dot active"></span>
79
- <span>AI Models Ready</span>
80
- </div>
81
- <div class="status-item">
82
- <span class="status-dot active"></span>
83
- <span>Web Search Available</span>
84
- </div>
85
- </div>
86
- </div>
87
- </div>
88
- """)
89
-
90
- with gr.Column(scale=1, min_width=200):
91
- with gr.Row():
92
- login_button = gr.LoginButton(scale=1, size="sm")
93
- theme_selector = gr.Dropdown(
94
- choices=list(THEME_CONFIGS.keys()),
95
- value=current_theme_name,
96
- label="Theme",
97
- scale=1,
98
- container=False
99
- )
100
-
101
- # Main interface
102
- with gr.Row():
103
- # Left sidebar - Controls
104
- with gr.Column(scale=1, elem_classes=["sidebar"]):
105
- self.create_sidebar(current_model, session_state)
106
-
107
- # Main content area
108
- with gr.Column(scale=3, elem_classes=["main-content"]):
109
- self.create_main_content(history, current_model)
110
-
111
- # Connect all the event handlers
112
- self.setup_event_handlers(app, history, setting, current_model, session_state)
113
 
114
- return app
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
 
116
- def create_sidebar(self, current_model, session_state):
117
- """Create the professional sidebar"""
118
-
119
- # Model Selection
120
- with gr.Group(elem_classes=["control-group"]):
121
- gr.HTML('<div class="group-title">πŸ€– AI Model</div>')
122
-
123
- model_dropdown = gr.Dropdown(
124
- choices=[f"{model['name']} ({model['category']})" for model in AVAILABLE_MODELS],
125
- value=f"{DEFAULT_MODEL['name']} ({DEFAULT_MODEL['category']})",
126
- label="Select Model",
127
- container=False
128
- )
129
-
130
- # Model info display
131
- model_info = gr.HTML(self.get_model_info_html(DEFAULT_MODEL))
132
-
133
- # Web Search Toggle
134
- with gr.Group(elem_classes=["control-group"]):
135
- search_toggle = gr.Checkbox(
136
- label="πŸ” Web search",
137
- value=False,
138
- info="Include generated images in your outputs using Qwen image model",
139
- container=False
140
- )
141
-
142
- # Media Generation Controls
143
- with gr.Group(elem_classes=["control-group"]):
144
- gr.HTML('<div class="group-title">🎨 Media Generation</div>')
145
-
146
- enable_images = gr.Checkbox(
147
- label="πŸ–ΌοΈ Generate Images (text β†’ image)",
148
- value=False,
149
- info="Include generated images in your outputs using Qwen image model",
150
- container=False
151
- )
152
-
153
- enable_image_to_image = gr.Checkbox(
154
- label="πŸ–ΌοΈ Image to Image (uses input image)",
155
- value=False,
156
- info="Transform your uploaded image using Qwen image/edit",
157
- container=False
158
- )
159
-
160
- enable_image_to_video = gr.Checkbox(
161
- label="🎬 Image to Video (uses input image)",
162
- value=False,
163
- info="Generate a short video from your uploaded image using Lightricks LTX-Video",
164
- container=False
165
- )
166
-
167
- enable_text_to_video = gr.Checkbox(
168
- label="🎬 Generate Video (text β†’ video)",
169
- value=False,
170
- info="Generate a short video directly from your prompt using WanAi/Wan2.2-TIZV-S8",
171
- container=False
172
- )
173
-
174
- enable_music = gr.Checkbox(
175
- label="🎡 Generate Music (text β†’ music)",
176
- value=False,
177
- info="Compose short music from your prompt using ElevenLabs Music",
178
- container=False
179
- )
180
-
181
- # Model Information
182
- with gr.Group(elem_classes=["control-group"]):
183
- model_display = gr.HTML(
184
- '<div class="model-name">Qwen3-Coder-4800-A535-Instruc</div>',
185
- elem_classes=["model-display"]
186
- )
187
-
188
- # Quick Start Examples
189
- with gr.Group(elem_classes=["control-group"]):
190
- gr.HTML('<div class="group-title">πŸš€ Quick Start</div>')
191
-
192
- # Create buttons for each demo instead of gallery
193
- quick_start_buttons = []
194
- for demo in DEMO_LIST[:6]:
195
- btn = gr.Button(
196
- demo["title"],
197
- variant="secondary",
198
- size="sm",
199
- elem_classes=["quick-start-btn"]
200
- )
201
- quick_start_buttons.append(btn)
202
-
203
- # Project Configuration
204
- with gr.Group(elem_classes=["control-group"]):
205
- gr.HTML('<div class="group-title">βš™οΈ Project Settings</div>')
206
-
207
- language_dropdown = gr.Dropdown(
208
- choices=[
209
- ("Static HTML", "html"),
210
- ("Streamlit App", "streamlit"),
211
- ("Gradio App", "gradio"),
212
- ("Transformers.js", "transformers.js"),
213
- ("Svelte App", "svelte"),
214
- ("Python Script", "python"),
215
- ("JavaScript", "javascript"),
216
- ("CSS Styles", "css"),
217
- ("Other", "other")
218
- ],
219
- value="html",
220
- label="Project Type",
221
- container=False
222
- )
223
-
224
- advanced_mode = gr.Checkbox(
225
- label="Advanced Mode",
226
- value=False,
227
- info="Show advanced options",
228
- container=False
229
- )
230
-
231
- # Input Sources
232
- with gr.Group(elem_classes=["control-group"]):
233
- gr.HTML('<div class="group-title">πŸ“ Input Sources</div>')
234
-
235
- file_input = gr.File(
236
- label="Upload Reference File",
237
- file_types=[".pdf", ".txt", ".md", ".csv", ".docx", ".jpg", ".jpeg", ".png"],
238
- container=False
239
- )
240
-
241
- website_url_input = gr.Textbox(
242
- label="Website URL (for redesign)",
243
- placeholder="https://example.com",
244
- container=False
245
- )
246
-
247
- image_input = gr.Image(
248
- label="Design Reference Image",
249
- container=False
250
- )
251
-
252
- # Advanced Controls (initially hidden)
253
- with gr.Group(elem_classes=["control-group"], visible=False) as advanced_controls:
254
- gr.HTML('<div class="group-title">πŸ”§ Advanced Options</div>')
255
-
256
- media_prompts = gr.Textbox(
257
- label="Media Generation Prompts",
258
- placeholder="Describe media to generate...",
259
- lines=2,
260
- container=False
261
- )
262
-
263
- # Project Import
264
- with gr.Group(elem_classes=["control-group"]):
265
- gr.HTML('<div class="group-title">πŸ“₯ Import Project</div>')
266
-
267
- import_url = gr.Textbox(
268
- label="GitHub/HuggingFace URL",
269
- placeholder="https://github.com/user/repo or https://huggingface.co/spaces/user/space",
270
- container=False
271
- )
272
-
273
- with gr.Row():
274
- import_btn = gr.Button("Import", variant="secondary", size="sm")
275
- import_status = gr.HTML("", visible=False)
276
-
277
- # Store sidebar components for event handling
278
- self.sidebar_components = {
279
- 'model_dropdown': model_dropdown,
280
- 'model_info': model_info,
281
- 'model_display': model_display,
282
- 'language_dropdown': language_dropdown,
283
- 'search_toggle': search_toggle,
284
- 'advanced_mode': advanced_mode,
285
- 'file_input': file_input,
286
- 'website_url_input': website_url_input,
287
- 'image_input': image_input,
288
- 'advanced_controls': advanced_controls,
289
- 'enable_images': enable_images,
290
- 'enable_image_to_image': enable_image_to_image,
291
- 'enable_image_to_video': enable_image_to_video,
292
- 'enable_text_to_video': enable_text_to_video,
293
- 'enable_music': enable_music,
294
- 'media_prompts': media_prompts,
295
- 'quick_start_buttons': quick_start_buttons,
296
- 'import_url': import_url,
297
- 'import_btn': import_btn,
298
- 'import_status': import_status
299
- }
300
-
301
- # Setup sidebar event handlers
302
- self.setup_sidebar_events(session_state)
303
 
304
- def setup_sidebar_events(self, session_state):
305
- """Setup sidebar-specific event handlers"""
306
-
307
- # Show advanced controls when enabled
308
- self.sidebar_components['advanced_mode'].change(
309
- lambda checked: gr.update(visible=checked),
310
- inputs=[self.sidebar_components['advanced_mode']],
311
- outputs=[self.sidebar_components['advanced_controls']]
312
- )
313
-
314
- # Show media prompts when any media generation is enabled
315
- media_checkboxes = [
316
- self.sidebar_components['enable_images'],
317
- self.sidebar_components['enable_image_to_image'],
318
- self.sidebar_components['enable_image_to_video'],
319
- self.sidebar_components['enable_text_to_video'],
320
- self.sidebar_components['enable_music']
321
- ]
322
-
323
- for checkbox in media_checkboxes:
324
- checkbox.change(
325
- lambda *args: gr.update(visible=any(args)),
326
- inputs=media_checkboxes,
327
- outputs=[self.sidebar_components['media_prompts']]
328
- )
329
-
330
- # Update session state when media options change
331
- for i, checkbox in enumerate(media_checkboxes):
332
- checkbox.change(
333
- self.update_media_settings,
334
- inputs=[checkbox],
335
- outputs=[session_state]
336
- )
337
 
338
- def update_media_settings(self, *checkbox_values):
339
- """Update media generation settings in session state"""
340
- settings = {
341
- 'enable_images': checkbox_values[0] if len(checkbox_values) > 0 else False,
342
- 'enable_image_to_image': checkbox_values[1] if len(checkbox_values) > 1 else False,
343
- 'enable_image_to_video': checkbox_values[2] if len(checkbox_values) > 2 else False,
344
- 'enable_text_to_video': checkbox_values[3] if len(checkbox_values) > 3 else False,
345
- 'enable_music': checkbox_values[4] if len(checkbox_values) > 4 else False
346
- }
347
- return settings
 
 
 
 
 
 
 
 
 
 
 
 
 
348
 
349
- def create_main_content(self, history, current_model):
350
- """Create the main content area"""
351
-
352
- # Input area
353
- with gr.Group(elem_classes=["input-group"]):
354
- input_textbox = gr.Textbox(
355
- label="What would you like to build?",
356
- placeholder="Describe your application in detail... (e.g., 'Create a modern dashboard with charts and user management')",
357
- lines=4,
358
- container=False,
359
- elem_classes=["main-input"]
360
- )
361
-
362
- with gr.Row():
363
- generate_btn = gr.Button(
364
- "πŸš€ Generate Application",
365
- variant="primary",
366
- scale=3,
367
- size="lg",
368
- elem_classes=["generate-btn"]
369
- )
370
- clear_btn = gr.Button(
371
- "πŸ—‘οΈ Clear",
372
- variant="secondary",
373
- scale=1,
374
- size="lg"
375
- )
376
-
377
- # Output area with professional tabs
378
- with gr.Tabs(elem_classes=["output-tabs"]):
379
-
380
- # Preview Tab
381
- with gr.Tab("πŸ–₯️ Live Preview", elem_classes=["preview-tab"]):
382
- with gr.Group():
383
- preview_controls = gr.HTML("""
384
- <div class="preview-controls">
385
- <div class="preview-info">
386
- <span class="info-item">πŸ“± Responsive Design</span>
387
- <span class="info-item">⚑ Real-time Updates</span>
388
- <span class="info-item">πŸ”’ Sandboxed Environment</span>
 
389
  </div>
390
  </div>
391
- """)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
392
 
393
- sandbox = gr.HTML(
394
- label="Application Preview",
395
- elem_classes=["preview-container"]
 
396
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
397
 
398
- # Code Tab
399
- with gr.Tab("πŸ’» Source Code", elem_classes=["code-tab"]):
400
- with gr.Row():
401
- with gr.Column(scale=4):
402
- code_output = gr.Code(
403
- language="html",
404
- lines=30,
405
- interactive=True,
406
- label="Generated Code",
407
- elem_classes=["code-editor"]
 
 
 
 
 
 
 
 
 
 
408
  )
 
 
 
 
 
 
 
 
 
409
 
410
- with gr.Column(scale=1, elem_classes=["code-sidebar"]):
411
- # Code actions
412
- with gr.Group():
413
- gr.HTML('<div class="group-title">πŸ”§ Code Actions</div>')
414
-
415
- copy_btn = gr.Button("πŸ“‹ Copy Code", size="sm")
416
- download_btn = gr.Button("πŸ’Ύ Download", size="sm")
417
- format_btn = gr.Button("✨ Format", size="sm")
 
 
 
418
 
419
- # Code stats
420
- with gr.Group():
421
- gr.HTML('<div class="group-title">πŸ“Š Code Stats</div>')
422
- code_stats = gr.HTML(
423
- '<div class="code-stats">Ready to generate...</div>',
424
- elem_classes=["code-stats"]
425
- )
426
-
427
- # Deployment Tab
428
- with gr.Tab("πŸš€ Deploy", elem_classes=["deploy-tab"]):
429
- with gr.Row():
430
- with gr.Column(scale=2):
431
- with gr.Group():
432
- gr.HTML('<div class="group-title">🌐 Deployment Options</div>')
433
-
434
- deploy_platform = gr.Dropdown(
435
- choices=[
436
- ("Hugging Face Spaces", "hf_spaces"),
437
- ("Vercel", "vercel"),
438
- ("Netlify", "netlify"),
439
- ("GitHub Pages", "github_pages")
440
- ],
441
- value="hf_spaces",
442
- label="Platform",
443
- container=False
444
- )
445
-
446
- app_name = gr.Textbox(
447
- label="Application Name",
448
- placeholder="my-awesome-app",
449
- container=False
450
- )
451
-
452
- deploy_btn = gr.Button(
453
- "πŸš€ Deploy Now",
454
- variant="primary",
455
- size="lg"
456
- )
457
-
458
- with gr.Column(scale=1):
459
- deployment_status = gr.HTML(
460
- '<div class="deployment-status">Ready to deploy</div>',
461
- elem_classes=["deployment-status"]
462
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
463
 
464
- # Generation status
465
- generation_status = gr.HTML(
466
- visible=False,
467
- elem_classes=["generation-status"]
 
468
  )
469
 
470
- # Store main content components
471
- self.main_components = {
472
- 'input_textbox': input_textbox,
473
- 'generate_btn': generate_btn,
474
- 'clear_btn': clear_btn,
475
- 'sandbox': sandbox,
476
- 'code_output': code_output,
477
- 'code_stats': code_stats,
478
- 'copy_btn': copy_btn,
479
- 'download_btn': download_btn,
480
- 'format_btn': format_btn,
481
- 'deploy_platform': deploy_platform,
482
- 'app_name': app_name,
483
- 'deploy_btn': deploy_btn,
484
- 'deployment_status': deployment_status,
485
- 'generation_status': generation_status
486
- }
487
-
488
- def setup_event_handlers(self, app, history, setting, current_model, session_state):
489
- """Setup all event handlers for the application"""
490
 
491
  # Generation handler
492
- self.main_components['generate_btn'].click(
493
- self.handle_generation,
494
  inputs=[
495
- self.main_components['input_textbox'],
496
- self.sidebar_components['file_input'],
497
- self.sidebar_components['website_url_input'],
498
- self.sidebar_components['image_input'],
499
- self.sidebar_components['language_dropdown'],
500
- self.sidebar_components['search_toggle'],
501
- current_model,
502
  history,
503
- session_state
 
 
 
 
 
 
 
 
 
 
 
 
 
504
  ],
505
- outputs=[
506
- self.main_components['code_output'],
507
- self.main_components['sandbox'],
508
- self.main_components['code_stats'],
509
- history
510
- ]
511
  )
512
 
513
- # Model selection handler
514
- self.sidebar_components['model_dropdown'].change(
515
- self.handle_model_change,
516
- inputs=[self.sidebar_components['model_dropdown']],
517
- outputs=[current_model, self.sidebar_components['model_info']]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
518
  )
519
 
520
  # Clear handler
521
- self.main_components['clear_btn'].click(
522
- self.handle_clear,
523
- outputs=[
524
- self.main_components['input_textbox'],
525
- self.main_components['code_output'],
526
- self.main_components['sandbox'],
527
- self.main_components['code_stats'],
528
- history
529
- ]
 
530
  )
531
 
532
  # Quick start button handlers
533
- for i, btn in enumerate(self.sidebar_components['quick_start_buttons']):
534
  if i < len(DEMO_LIST):
535
  btn.click(
536
  lambda demo_idx=i: DEMO_LIST[demo_idx]['description'],
537
- outputs=[self.main_components['input_textbox']]
538
- )
539
-
540
- def handle_generation(self, prompt, file, website_url, image, language,
541
- enable_search, current_model_state, history_state, session_state):
542
- """Handle code generation with advanced features"""
543
-
544
- if not prompt.strip():
545
- return (
546
- gr.update(),
547
- "<div class='error-message'>Please enter a description of what you'd like to build.</div>",
548
- "<div class='code-stats error'>No input provided</div>",
549
- history_state
550
- )
551
-
552
- try:
553
- # Setup session
554
- session_id = session_state.get('session_id', str(uuid.uuid4()))
555
- session_state['session_id'] = session_id
556
-
557
- # Enhance prompt with file content
558
- enhanced_prompt = prompt
559
- if file:
560
- file_content = extract_text_from_file(file.name)
561
- if file_content:
562
- enhanced_prompt = f"{prompt}\n\n[Reference file content]\n{file_content[:5000]}"
563
-
564
- # Enhance with website content
565
- if website_url and website_url.strip():
566
- website_content = extract_website_content(website_url.strip())
567
- if website_content and not website_content.startswith("Error"):
568
- enhanced_prompt = f"{enhanced_prompt}\n\n[Website content to redesign]\n{website_content[:8000]}"
569
-
570
- # Enhance with web search if enabled
571
- if enable_search:
572
- enhanced_prompt = enhance_query_with_search(enhanced_prompt, True)
573
-
574
- # Generate code using selected model
575
- generated_code = self.generate_code_with_model(
576
- enhanced_prompt, current_model_state, language, image
577
- )
578
-
579
- # Process the generated code
580
- processed_code = remove_code_block(generated_code)
581
-
582
- # Apply media generation if enabled
583
- if any([
584
- session_state.get('enable_images', False),
585
- session_state.get('enable_image_to_image', False),
586
- session_state.get('enable_image_to_video', False),
587
- session_state.get('enable_text_to_video', False),
588
- session_state.get('enable_music', False)
589
- ]):
590
- processed_code = apply_generated_media_to_html(
591
- processed_code,
592
- prompt,
593
- enable_text_to_image=session_state.get('enable_images', False),
594
- enable_image_to_image=session_state.get('enable_image_to_image', False),
595
- enable_image_to_video=session_state.get('enable_image_to_video', False),
596
- enable_text_to_video=session_state.get('enable_text_to_video', False),
597
- enable_text_to_music=session_state.get('enable_music', False),
598
- session_id=session_id
599
  )
600
-
601
- # Generate preview
602
- preview_html = self.generate_preview(processed_code, language)
603
-
604
- # Update code stats
605
- stats_html = self.generate_code_stats(processed_code, language)
606
-
607
- # Update history
608
- history_state.append([prompt, processed_code])
609
-
610
- return (
611
- gr.update(value=processed_code, language=get_gradio_language(language)),
612
- preview_html,
613
- stats_html,
614
- history_state
615
- )
616
-
617
- except Exception as e:
618
- error_html = f"<div class='error-message'>Generation Error: {str(e)}</div>"
619
- return (
620
- gr.update(value=f"// Error: {str(e)}"),
621
- error_html,
622
- "<div class='code-stats error'>Generation failed</div>",
623
- history_state
624
- )
625
-
626
- def generate_code_with_model(self, prompt, model_state, language, image):
627
- """Generate code using the selected model"""
628
 
629
- try:
630
- client = get_inference_client(model_state['id'], "auto")
631
-
632
- # Select appropriate system prompt based on language
633
- system_prompts = {
634
- 'html': HTML_SYSTEM_PROMPT,
635
- 'streamlit': "You are an expert Streamlit developer. Create modern, interactive Streamlit applications with clean code and professional UI.",
636
- 'gradio': "You are an expert Gradio developer. Create modern, interactive Gradio applications with clean interfaces and robust functionality.",
637
- 'transformers.js': "You are an expert in Transformers.js. Create modern web applications using Transformers.js for AI/ML functionality.",
638
- 'svelte': "You are an expert Svelte developer. Create modern, reactive Svelte applications with TypeScript and clean architecture."
639
- }
640
-
641
- system_prompt = system_prompts.get(language, HTML_SYSTEM_PROMPT)
642
-
643
- # Prepare messages
644
- messages = [
645
- {"role": "system", "content": system_prompt}
646
- ]
647
-
648
- if image:
649
- messages.append(create_multimodal_message(prompt, image))
650
- else:
651
- messages.append({"role": "user", "content": prompt})
652
-
653
- # Generate with streaming for better UX
654
- if hasattr(client, 'chat') and hasattr(client.chat, 'completions'):
655
- completion = client.chat.completions.create(
656
- model=model_state['id'],
657
- messages=messages,
658
- max_tokens=16384,
659
- temperature=0.7,
660
- stream=False # For simplicity in this demo
661
- )
662
-
663
- return completion.choices[0].message.content
664
- else:
665
- # Fallback for different client types
666
- return "Generated code would appear here..."
667
-
668
- except Exception as e:
669
- raise Exception(f"Model generation failed: {str(e)}")
670
-
671
- def generate_preview(self, code, language):
672
- """Generate HTML preview for the code"""
673
-
674
- try:
675
- if language == "html":
676
- # Handle multi-page HTML
677
- files = parse_multipage_html_output(code)
678
- if files and files.get('index.html'):
679
- files = validate_and_autofix_files(files)
680
- preview_code = inline_multipage_into_single_preview(files)
681
- else:
682
- preview_code = extract_html_document(code)
683
-
684
- return self.send_to_sandbox(preview_code)
685
-
686
- elif language == "transformers.js":
687
- files = parse_transformers_js_output(code)
688
- if files['index.html'] and files['index.js'] and files['style.css']:
689
- merged_html = build_transformers_inline_html(files)
690
- return self.send_to_sandbox(merged_html)
691
- else:
692
- return "<div class='preview-message'>⏳ Generating Transformers.js application...</div>"
693
-
694
- elif language == "streamlit":
695
- if is_streamlit_code(code):
696
- return self.send_streamlit_to_stlite(code)
697
- else:
698
- return "<div class='preview-message'>Add <code>import streamlit as st</code> to enable preview</div>"
699
-
700
- elif language == "gradio":
701
- if is_gradio_code(code):
702
- return self.send_gradio_to_lite(code)
703
- else:
704
- return "<div class='preview-message'>Add <code>import gradio as gr</code> to enable preview</div>"
705
-
706
- else:
707
- return f"<div class='preview-message'>πŸ’» {language.upper()} code generated successfully. Preview not available for this language.</div>"
708
-
709
- except Exception as e:
710
- return f"<div class='error-message'>Preview Error: {str(e)}</div>"
711
-
712
- def send_to_sandbox(self, html_code):
713
- """Send HTML to sandboxed iframe"""
714
- if not html_code.strip():
715
- return "<div class='preview-message'>No content to preview</div>"
716
-
717
- try:
718
- encoded_html = base64.b64encode(html_code.encode('utf-8')).decode('utf-8')
719
- data_uri = f"data:text/html;charset=utf-8;base64,{encoded_html}"
720
- iframe = f'''
721
- <iframe
722
- src="{data_uri}"
723
- width="100%"
724
- height="800px"
725
- sandbox="allow-scripts allow-same-origin allow-forms allow-popups allow-modals"
726
- style="border: 1px solid #e5e7eb; border-radius: 8px; background: white;"
727
- allow="display-capture">
728
- </iframe>
729
- '''
730
- return iframe
731
- except Exception as e:
732
- return f"<div class='error-message'>Sandbox Error: {str(e)}</div>"
733
-
734
- def send_streamlit_to_stlite(self, code):
735
- """Send Streamlit code to stlite preview"""
736
- html_doc = f"""
737
- <!doctype html>
738
- <html>
739
- <head>
740
- <meta charset="UTF-8" />
741
- <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
742
- <title>Streamlit Preview</title>
743
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@stlite/browser@0.86.0/build/stlite.css" />
744
- <script type="module" src="https://cdn.jsdelivr.net/npm/@stlite/browser@0.86.0/build/stlite.js"></script>
745
- </head>
746
- <body>
747
- <streamlit-app>{code}</streamlit-app>
748
- </body>
749
- </html>
750
- """
751
- return self.send_to_sandbox(html_doc)
752
-
753
- def send_gradio_to_lite(self, code):
754
- """Send Gradio code to gradio-lite preview"""
755
- html_doc = f"""
756
- <!doctype html>
757
- <html>
758
- <head>
759
- <meta charset="UTF-8" />
760
- <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
761
- <title>Gradio Preview</title>
762
- <script type="module" crossorigin src="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.js"></script>
763
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.css" />
764
- </head>
765
- <body>
766
- <gradio-lite>{code}</gradio-lite>
767
- </body>
768
- </html>
769
- """
770
- return self.send_to_sandbox(html_doc)
771
-
772
- def generate_code_stats(self, code, language):
773
- """Generate code statistics"""
774
- if not code:
775
- return "<div class='code-stats'>No code generated</div>"
776
-
777
- try:
778
- lines = len(code.split('\n'))
779
- chars = len(code)
780
- words = len(code.split())
781
-
782
- # Language-specific analysis
783
- if language == "html":
784
- tags = len([m for m in code.split('<') if m.strip()])
785
- stats_content = f"""
786
- <div class='stats-grid'>
787
- <div class='stat-item'>
788
- <span class='stat-number'>{lines}</span>
789
- <span class='stat-label'>Lines</span>
790
- </div>
791
- <div class='stat-item'>
792
- <span class='stat-number'>{tags}</span>
793
- <span class='stat-label'>HTML Tags</span>
794
- </div>
795
- <div class='stat-item'>
796
- <span class='stat-number'>{chars}</span>
797
- <span class='stat-label'>Characters</span>
798
- </div>
799
- <div class='stat-item'>
800
- <span class='stat-number'>{round(chars/1024, 1)}KB</span>
801
- <span class='stat-label'>Size</span>
802
- </div>
803
- </div>
804
- """
805
- else:
806
- stats_content = f"""
807
- <div class='stats-grid'>
808
- <div class='stat-item'>
809
- <span class='stat-number'>{lines}</span>
810
- <span class='stat-label'>Lines</span>
811
- </div>
812
- <div class='stat-item'>
813
- <span class='stat-number'>{words}</span>
814
- <span class='stat-label'>Words</span>
815
- </div>
816
- <div class='stat-item'>
817
- <span class='stat-number'>{chars}</span>
818
- <span class='stat-label'>Characters</span>
819
- </div>
820
- <div class='stat-item'>
821
- <span class='stat-number'>{language.upper()}</span>
822
- <span class='stat-label'>Language</span>
823
- </div>
824
- </div>
825
- """
826
-
827
- return f"<div class='code-stats'>{stats_content}</div>"
828
-
829
- except Exception:
830
- return "<div class='code-stats'>Unable to analyze code</div>"
831
-
832
- def handle_model_change(self, model_selection):
833
- """Handle model selection change"""
834
- try:
835
- # Extract model name from selection
836
- model_name = model_selection.split(" (")[0]
837
-
838
- # Find the model
839
- selected_model = None
840
- for model in AVAILABLE_MODELS:
841
- if model['name'] == model_name:
842
- selected_model = model
843
- break
844
-
845
- if selected_model:
846
- model_info_html = self.get_model_info_html(selected_model)
847
- return selected_model, model_info_html
848
-
849
- return DEFAULT_MODEL, self.get_model_info_html(DEFAULT_MODEL)
850
-
851
- except Exception:
852
- return DEFAULT_MODEL, self.get_model_info_html(DEFAULT_MODEL)
853
-
854
- def handle_clear(self):
855
- """Handle clear button"""
856
- return (
857
- gr.update(value=""), # input_textbox
858
- gr.update(value="", language="html"), # code_output
859
- "<div class='preview-message'>Ready to generate your next application</div>", # sandbox
860
- "<div class='code-stats'>Ready to generate...</div>", # code_stats
861
- [] # history
862
  )
863
 
864
- def get_model_info_html(self, model):
865
- """Generate HTML for model information"""
866
- vision_badge = '<span class="feature-badge vision">πŸ‘οΈ Vision</span>' if model.get('supports_vision') else ''
867
- category_color = {
868
- 'General': '#3b82f6',
869
- 'Code Specialist': '#10b981',
870
- 'Vision-Language': '#f59e0b',
871
- 'Premium': '#8b5cf6'
872
- }.get(model.get('category', 'General'), '#6b7280')
873
-
874
- return f"""
875
- <div class="model-info">
876
- <div class="model-header">
877
- <div class="model-name">{model['name']}</div>
878
- <span class="category-badge" style="background-color: {category_color}">
879
- {model.get('category', 'General')}
880
- </span>
881
- </div>
882
- <div class="model-description">{model.get('description', '')}</div>
883
- <div class="model-features">
884
- {vision_badge}
885
- <span class="feature-badge">πŸš€ Latest</span>
886
- </div>
887
- </div>
888
- """
889
-
890
- def get_custom_css(self):
891
- """Get custom CSS for the application"""
892
- return """
893
- /* Modern Professional Styling */
894
- .gradio-container {
895
- max-width: none !important;
896
- padding: 0 !important;
897
- }
898
-
899
- .app-header {
900
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
901
- color: white;
902
- padding: 20px;
903
- border-radius: 0 0 16px 16px;
904
- margin-bottom: 20px;
905
- }
906
-
907
- .header-content {
908
- display: flex;
909
- justify-content: space-between;
910
- align-items: center;
911
- max-width: 1400px;
912
- margin: 0 auto;
913
- }
914
-
915
- .logo-section {
916
- display: flex;
917
- align-items: center;
918
- gap: 15px;
919
- }
920
-
921
- .logo {
922
- font-size: 2.5rem;
923
- font-weight: bold;
924
- }
925
-
926
- .app-title h1 {
927
- font-size: 2rem;
928
- margin: 0;
929
- font-weight: 700;
930
- }
931
-
932
- .app-title p {
933
- margin: 5px 0 0 0;
934
- opacity: 0.9;
935
- font-size: 1rem;
936
- }
937
-
938
- .status-indicators {
939
- display: flex;
940
- flex-direction: column;
941
- gap: 8px;
942
- }
943
-
944
- .status-item {
945
- display: flex;
946
- align-items: center;
947
- gap: 8px;
948
- font-size: 0.9rem;
949
- }
950
-
951
- .status-dot {
952
- width: 8px;
953
- height: 8px;
954
- border-radius: 50%;
955
- background: #10b981;
956
- }
957
-
958
- .status-dot.active {
959
- animation: pulse 2s infinite;
960
- }
961
-
962
- @keyframes pulse {
963
- 0%, 100% { opacity: 1; }
964
- 50% { opacity: 0.5; }
965
- }
966
-
967
- .sidebar {
968
- background: #f8fafc;
969
- padding: 20px;
970
- border-radius: 12px;
971
- border: 1px solid #e2e8f0;
972
- height: fit-content;
973
- }
974
-
975
- .main-content {
976
- padding-left: 20px;
977
- }
978
-
979
- .control-group {
980
- margin-bottom: 16px;
981
- background: white;
982
- padding: 16px;
983
- border-radius: 8px;
984
- border: 1px solid #e5e7eb;
985
- }
986
-
987
- .group-title {
988
- font-weight: 600;
989
- font-size: 0.95rem;
990
- color: #374151;
991
- margin-bottom: 12px;
992
- display: flex;
993
- align-items: center;
994
- gap: 8px;
995
- }
996
-
997
- .model-display {
998
- background: #f3f4f6;
999
- padding: 8px 12px;
1000
- border-radius: 6px;
1001
- border: 1px solid #d1d5db;
1002
- }
1003
-
1004
- .model-display .model-name {
1005
- font-family: 'Monaco', 'Consolas', monospace;
1006
- font-size: 0.85rem;
1007
- color: #374151;
1008
- }
1009
-
1010
- .quick-start-btn {
1011
- width: 100%;
1012
- margin-bottom: 4px;
1013
- text-align: left;
1014
- justify-content: flex-start;
1015
- }
1016
-
1017
- .input-group {
1018
- background: white;
1019
- padding: 24px;
1020
- border-radius: 12px;
1021
- border: 1px solid #e2e8f0;
1022
- margin-bottom: 20px;
1023
- box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
1024
- }
1025
-
1026
- .main-input textarea {
1027
- font-size: 16px !important;
1028
- line-height: 1.5 !important;
1029
- }
1030
-
1031
- .generate-btn {
1032
- background: linear-gradient(135deg, #10b981 0%, #059669 100%) !important;
1033
- border: none !important;
1034
- font-weight: 600 !important;
1035
- font-size: 1.1rem !important;
1036
- padding: 16px 32px !important;
1037
- }
1038
-
1039
- .generate-btn:hover {
1040
- transform: translateY(-1px);
1041
- box-shadow: 0 10px 25px rgba(16, 185, 129, 0.3) !important;
1042
- }
1043
-
1044
- .output-tabs .tab-nav {
1045
- background: #f8fafc;
1046
- border-radius: 8px 8px 0 0;
1047
- border-bottom: 1px solid #e2e8f0;
1048
- }
1049
-
1050
- .preview-container iframe {
1051
- border-radius: 8px;
1052
- box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
1053
- }
1054
-
1055
- .code-editor {
1056
- border-radius: 8px;
1057
- border: 1px solid #e2e8f0;
1058
- }
1059
-
1060
- .code-sidebar {
1061
- padding-left: 16px;
1062
- }
1063
-
1064
- .code-sidebar .control-group {
1065
- margin-bottom: 16px;
1066
- padding: 12px;
1067
- }
1068
-
1069
- .code-stats {
1070
- background: white;
1071
- padding: 16px;
1072
- border-radius: 8px;
1073
- border: 1px solid #e5e7eb;
1074
- }
1075
-
1076
- .stats-grid {
1077
- display: grid;
1078
- grid-template-columns: 1fr 1fr;
1079
- gap: 12px;
1080
- }
1081
-
1082
- .stat-item {
1083
- text-align: center;
1084
- padding: 8px;
1085
- background: #f8fafc;
1086
- border-radius: 6px;
1087
- }
1088
-
1089
- .stat-number {
1090
- display: block;
1091
- font-size: 1.25rem;
1092
- font-weight: 700;
1093
- color: #1f2937;
1094
- }
1095
-
1096
- .stat-label {
1097
- font-size: 0.75rem;
1098
- color: #6b7280;
1099
- text-transform: uppercase;
1100
- letter-spacing: 0.05em;
1101
- }
1102
-
1103
- .model-info {
1104
- background: white;
1105
- padding: 12px;
1106
- border-radius: 6px;
1107
- border: 1px solid #e5e7eb;
1108
- margin-top: 8px;
1109
- }
1110
-
1111
- .model-header {
1112
- display: flex;
1113
- justify-content: space-between;
1114
- align-items: center;
1115
- margin-bottom: 8px;
1116
- }
1117
-
1118
- .model-name {
1119
- font-weight: 600;
1120
- color: #1f2937;
1121
- }
1122
-
1123
- .category-badge {
1124
- padding: 2px 8px;
1125
- border-radius: 12px;
1126
- font-size: 0.75rem;
1127
- font-weight: 500;
1128
- color: white;
1129
- }
1130
-
1131
- .model-description {
1132
- font-size: 0.85rem;
1133
- color: #6b7280;
1134
- margin-bottom: 8px;
1135
- }
1136
-
1137
- .model-features {
1138
- display: flex;
1139
- gap: 4px;
1140
- }
1141
-
1142
- .feature-badge {
1143
- padding: 2px 6px;
1144
- border-radius: 8px;
1145
- font-size: 0.7rem;
1146
- font-weight: 500;
1147
- background: #f3f4f6;
1148
- color: #374151;
1149
- }
1150
-
1151
- .feature-badge.vision {
1152
- background: #fef3c7;
1153
- color: #92400e;
1154
- }
1155
-
1156
- .preview-message {
1157
- text-align: center;
1158
- padding: 40px 20px;
1159
- color: #6b7280;
1160
- background: #f9fafb;
1161
- border-radius: 8px;
1162
- border: 2px dashed #d1d5db;
1163
- }
1164
-
1165
- .error-message {
1166
- text-align: center;
1167
- padding: 20px;
1168
- color: #dc2626;
1169
- background: #fef2f2;
1170
- border: 1px solid #fecaca;
1171
- border-radius: 8px;
1172
- }
1173
-
1174
- .deployment-status {
1175
- background: white;
1176
- padding: 16px;
1177
- border-radius: 8px;
1178
- border: 1px solid #e5e7eb;
1179
- text-align: center;
1180
- color: #6b7280;
1181
- }
1182
-
1183
- /* Responsive design */
1184
- @media (max-width: 768px) {
1185
- .header-content {
1186
- flex-direction: column;
1187
- gap: 20px;
1188
- text-align: center;
1189
- }
1190
-
1191
- .stats-grid {
1192
- grid-template-columns: 1fr;
1193
- }
1194
-
1195
- .main-content {
1196
- padding-left: 0;
1197
- margin-top: 20px;
1198
- }
1199
- }
1200
- """
1201
-
1202
- def get_head_html(self):
1203
- """Get additional head HTML"""
1204
- return """
1205
- <meta name="description" content="AnyCoder - Professional AI Development Suite for creating modern applications">
1206
- <meta name="keywords" content="AI, code generation, web development, automation">
1207
- <meta name="author" content="AnyCoder">
1208
- <link rel="preconnect" href="https://fonts.googleapis.com">
1209
- <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
1210
- <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
1211
- <style>
1212
- body { font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }
1213
- </style>
1214
- """
1215
 
1216
  def main():
1217
  """Main application entry point"""
1218
  print("πŸš€ Starting AnyCoder Professional AI Development Suite...")
1219
 
1220
- # Initialize the application
1221
- app_instance = AnyCoder()
1222
- demo = app_instance.create_advanced_ui()
 
 
 
1223
 
1224
- # Launch with optimal settings
1225
  demo.queue(api_open=False, default_concurrency_limit=20).launch(
1226
  show_api=False,
1227
  share=False,
1228
- server_name="0.0.0.0",
1229
  server_port=7860,
1230
- show_error=True,
1231
- quiet=False
1232
  )
1233
 
1234
  if __name__ == "__main__":
 
2
  import uuid
3
  import base64
4
  import tempfile
5
+ from typing import Dict, List, Optional, Tuple
6
 
7
  import gradio as gr
8
 
9
+ # Import from our modularized files
10
  from config import (
11
  AVAILABLE_MODELS, DEFAULT_MODEL, THEME_CONFIGS, DEMO_LIST,
12
+ HTML_SYSTEM_PROMPT, get_saved_theme, save_theme_preference
13
  )
14
  from utils import (
15
  get_inference_client, remove_code_block, extract_text_from_file,
16
  create_multimodal_message, apply_search_replace_changes,
17
+ cleanup_all_temp_media, reap_old_media, get_gradio_language
18
  )
19
  from web_utils import extract_website_content, enhance_query_with_search
20
  from media_generation import (
 
29
  validate_and_autofix_files, inline_multipage_into_single_preview,
30
  apply_generated_media_to_html
31
  )
32
+ from sandbox import send_to_sandbox, send_streamlit_to_stlite, send_gradio_to_lite
33
+ from generation_engine import generation_code
34
 
35
  # Initialize theme
36
  current_theme_name = get_saved_theme()
37
  current_theme = THEME_CONFIGS[current_theme_name]["theme"]
38
 
39
+ # =============================================================================
40
+ # PROFESSIONAL UI FUNCTIONS
41
+ # =============================================================================
42
+
43
+ def get_model_info_html(model):
44
+ """Generate HTML for model information"""
45
+ vision_badge = '<span class="feature-badge vision">πŸ‘οΈ Vision</span>' if model.get('supports_vision') else ''
46
+ category_color = {
47
+ 'General': '#3b82f6',
48
+ 'Code Specialist': '#10b981',
49
+ 'Vision-Language': '#f59e0b',
50
+ 'Premium': '#8b5cf6'
51
+ }.get(model.get('category', 'General'), '#6b7280')
52
 
53
+ return f"""
54
+ <div class="model-info">
55
+ <div class="model-header">
56
+ <div class="model-name">{model['name']}</div>
57
+ <span class="category-badge" style="background-color: {category_color}">
58
+ {model.get('category', 'General')}
59
+ </span>
60
+ </div>
61
+ <div class="model-description">{model.get('description', '')}</div>
62
+ <div class="model-features">
63
+ {vision_badge}
64
+ <span class="feature-badge">πŸš€ Latest</span>
65
+ </div>
66
+ </div>
67
+ """
68
+
69
+ def generate_code_stats(code, language):
70
+ """Generate code statistics HTML"""
71
+ if not code:
72
+ return "<div class='code-stats'>No code generated</div>"
73
 
74
+ try:
75
+ lines = len(code.split('\n'))
76
+ chars = len(code)
77
+ words = len(code.split())
78
+
79
+ # Language-specific analysis
80
+ if language == "html":
81
+ tags = len([m for m in code.split('<') if m.strip()])
82
+ stats_content = f"""
83
+ <div class='stats-grid'>
84
+ <div class='stat-item'>
85
+ <span class='stat-number'>{lines}</span>
86
+ <span class='stat-label'>Lines</span>
87
+ </div>
88
+ <div class='stat-item'>
89
+ <span class='stat-number'>{tags}</span>
90
+ <span class='stat-label'>HTML Tags</span>
91
+ </div>
92
+ <div class='stat-item'>
93
+ <span class='stat-number'>{chars}</span>
94
+ <span class='stat-label'>Characters</span>
95
+ </div>
96
+ <div class='stat-item'>
97
+ <span class='stat-number'>{round(chars/1024, 1)}KB</span>
98
+ <span class='stat-label'>Size</span>
99
+ </div>
100
+ </div>
101
+ """
102
+ else:
103
+ stats_content = f"""
104
+ <div class='stats-grid'>
105
+ <div class='stat-item'>
106
+ <span class='stat-number'>{lines}</span>
107
+ <span class='stat-label'>Lines</span>
108
+ </div>
109
+ <div class='stat-item'>
110
+ <span class='stat-number'>{words}</span>
111
+ <span class='stat-label'>Words</span>
112
+ </div>
113
+ <div class='stat-item'>
114
+ <span class='stat-number'>{chars}</span>
115
+ <span class='stat-label'>Characters</span>
116
+ </div>
117
+ <div class='stat-item'>
118
+ <span class='stat-number'>{language.upper()}</span>
119
+ <span class='stat-label'>Language</span>
120
+ </div>
121
+ </div>
122
+ """
123
 
124
+ return f"<div class='code-stats'>{stats_content}</div>"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
 
126
+ except Exception:
127
+ return "<div class='code-stats'>Unable to analyze code</div>"
128
+
129
+ def handle_model_change(model_selection):
130
+ """Handle model selection change"""
131
+ try:
132
+ # Extract model name from selection
133
+ model_name = model_selection.split(" (")[0]
134
+
135
+ # Find the model
136
+ selected_model = None
137
+ for model in AVAILABLE_MODELS:
138
+ if model['name'] == model_name:
139
+ selected_model = model
140
+ break
141
+
142
+ if selected_model:
143
+ model_info_html = get_model_info_html(selected_model)
144
+ return selected_model, model_info_html
145
+
146
+ return DEFAULT_MODEL, get_model_info_html(DEFAULT_MODEL)
147
+
148
+ except Exception:
149
+ return DEFAULT_MODEL, get_model_info_html(DEFAULT_MODEL)
150
+
151
+ def update_image_input_visibility(model):
152
+ """Update image input visibility based on selected model"""
153
+ return gr.update(visible=model.get('supports_vision', False))
154
+
155
+ def clear_history():
156
+ """Clear all inputs and history"""
157
+ return [], [], None, "", ""
158
+
159
+ def demo_card_click(demo_index):
160
+ """Handle demo card click"""
161
+ if 0 <= demo_index < len(DEMO_LIST):
162
+ return DEMO_LIST[demo_index]['description']
163
+ return ""
164
+
165
+ # =============================================================================
166
+ # CUSTOM CSS
167
+ # =============================================================================
168
+
169
+ CUSTOM_CSS = """
170
+ /* Modern Professional Styling */
171
+ .gradio-container {
172
+ max-width: none !important;
173
+ padding: 0 !important;
174
+ font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
175
+ }
176
+
177
+ .app-header {
178
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
179
+ color: white;
180
+ padding: 24px;
181
+ border-radius: 0 0 16px 16px;
182
+ margin-bottom: 24px;
183
+ box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
184
+ }
185
+
186
+ .header-content {
187
+ display: flex;
188
+ justify-content: space-between;
189
+ align-items: center;
190
+ max-width: 1400px;
191
+ margin: 0 auto;
192
+ }
193
+
194
+ .logo-section {
195
+ display: flex;
196
+ align-items: center;
197
+ gap: 16px;
198
+ }
199
+
200
+ .logo {
201
+ font-size: 2.5rem;
202
+ font-weight: bold;
203
+ text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
204
+ }
205
+
206
+ .app-title h1 {
207
+ font-size: 2.2rem;
208
+ margin: 0;
209
+ font-weight: 700;
210
+ text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
211
+ }
212
+
213
+ .app-title p {
214
+ margin: 8px 0 0 0;
215
+ opacity: 0.9;
216
+ font-size: 1.1rem;
217
+ font-weight: 300;
218
+ }
219
+
220
+ .status-indicators {
221
+ display: flex;
222
+ flex-direction: column;
223
+ gap: 12px;
224
+ }
225
+
226
+ .status-item {
227
+ display: flex;
228
+ align-items: center;
229
+ gap: 10px;
230
+ font-size: 0.95rem;
231
+ font-weight: 500;
232
+ }
233
+
234
+ .status-dot {
235
+ width: 10px;
236
+ height: 10px;
237
+ border-radius: 50%;
238
+ background: #10b981;
239
+ box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.3);
240
+ }
241
+
242
+ .status-dot.active {
243
+ animation: pulse 2s infinite;
244
+ }
245
+
246
+ @keyframes pulse {
247
+ 0%, 100% {
248
+ opacity: 1;
249
+ transform: scale(1);
250
+ }
251
+ 50% {
252
+ opacity: 0.7;
253
+ transform: scale(1.1);
254
+ }
255
+ }
256
+
257
+ .sidebar {
258
+ background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
259
+ padding: 24px;
260
+ border-radius: 16px;
261
+ border: 1px solid #e2e8f0;
262
+ height: fit-content;
263
+ box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
264
+ }
265
+
266
+ .main-content {
267
+ padding-left: 24px;
268
+ }
269
+
270
+ .control-group {
271
+ margin-bottom: 20px;
272
+ background: white;
273
+ padding: 20px;
274
+ border-radius: 12px;
275
+ border: 1px solid #e5e7eb;
276
+ box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.05);
277
+ }
278
+
279
+ .group-title {
280
+ font-weight: 600;
281
+ font-size: 1rem;
282
+ color: #1f2937;
283
+ margin-bottom: 16px;
284
+ display: flex;
285
+ align-items: center;
286
+ gap: 8px;
287
+ border-bottom: 2px solid #f3f4f6;
288
+ padding-bottom: 8px;
289
+ }
290
+
291
+ .quick-start-btn {
292
+ width: 100%;
293
+ margin-bottom: 8px;
294
+ text-align: left;
295
+ justify-content: flex-start;
296
+ transition: all 0.2s ease;
297
+ border-radius: 8px;
298
+ }
299
+
300
+ .quick-start-btn:hover {
301
+ transform: translateX(4px);
302
+ background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
303
+ }
304
+
305
+ .input-group {
306
+ background: white;
307
+ padding: 28px;
308
+ border-radius: 16px;
309
+ border: 1px solid #e2e8f0;
310
+ margin-bottom: 24px;
311
+ box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
312
+ }
313
+
314
+ .main-input textarea {
315
+ font-size: 16px !important;
316
+ line-height: 1.6 !important;
317
+ border-radius: 12px !important;
318
+ border: 2px solid #e5e7eb !important;
319
+ transition: border-color 0.2s ease !important;
320
+ }
321
+
322
+ .main-input textarea:focus {
323
+ border-color: #3b82f6 !important;
324
+ box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1) !important;
325
+ }
326
+
327
+ .generate-btn {
328
+ background: linear-gradient(135deg, #10b981 0%, #059669 100%) !important;
329
+ border: none !important;
330
+ font-weight: 600 !important;
331
+ font-size: 1.1rem !important;
332
+ padding: 18px 36px !important;
333
+ border-radius: 12px !important;
334
+ transition: all 0.3s ease !important;
335
+ }
336
+
337
+ .generate-btn:hover {
338
+ transform: translateY(-2px) !important;
339
+ box-shadow: 0 12px 28px rgba(16, 185, 129, 0.35) !important;
340
+ background: linear-gradient(135deg, #059669 0%, #047857 100%) !important;
341
+ }
342
+
343
+ .output-tabs {
344
+ background: white;
345
+ border-radius: 16px;
346
+ overflow: hidden;
347
+ box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
348
+ border: 1px solid #e5e7eb;
349
+ }
350
+
351
+ .preview-container iframe {
352
+ border-radius: 12px;
353
+ box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
354
+ border: 1px solid #e5e7eb;
355
+ }
356
+
357
+ .code-editor {
358
+ border-radius: 12px !important;
359
+ border: 1px solid #e2e8f0 !important;
360
+ background: #fafafa !important;
361
+ }
362
+
363
+ .code-sidebar {
364
+ padding-left: 20px;
365
+ }
366
+
367
+ .code-stats {
368
+ background: white;
369
+ padding: 20px;
370
+ border-radius: 12px;
371
+ border: 1px solid #e5e7eb;
372
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
373
+ }
374
+
375
+ .stats-grid {
376
+ display: grid;
377
+ grid-template-columns: 1fr 1fr;
378
+ gap: 16px;
379
+ }
380
+
381
+ .stat-item {
382
+ text-align: center;
383
+ padding: 12px;
384
+ background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
385
+ border-radius: 8px;
386
+ border: 1px solid #e5e7eb;
387
+ }
388
+
389
+ .stat-number {
390
+ display: block;
391
+ font-size: 1.5rem;
392
+ font-weight: 700;
393
+ color: #1f2937;
394
+ margin-bottom: 4px;
395
+ }
396
+
397
+ .stat-label {
398
+ font-size: 0.75rem;
399
+ color: #6b7280;
400
+ text-transform: uppercase;
401
+ letter-spacing: 0.1em;
402
+ font-weight: 500;
403
+ }
404
+
405
+ .model-info {
406
+ background: white;
407
+ padding: 16px;
408
+ border-radius: 10px;
409
+ border: 1px solid #e5e7eb;
410
+ margin-top: 12px;
411
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
412
+ }
413
+
414
+ .model-header {
415
+ display: flex;
416
+ justify-content: space-between;
417
+ align-items: center;
418
+ margin-bottom: 12px;
419
+ }
420
+
421
+ .model-name {
422
+ font-weight: 600;
423
+ color: #1f2937;
424
+ font-size: 1rem;
425
+ }
426
+
427
+ .category-badge {
428
+ padding: 4px 12px;
429
+ border-radius: 16px;
430
+ font-size: 0.75rem;
431
+ font-weight: 600;
432
+ color: white;
433
+ text-transform: uppercase;
434
+ letter-spacing: 0.05em;
435
+ }
436
+
437
+ .model-description {
438
+ font-size: 0.9rem;
439
+ color: #6b7280;
440
+ margin-bottom: 12px;
441
+ line-height: 1.5;
442
+ }
443
+
444
+ .model-features {
445
+ display: flex;
446
+ gap: 6px;
447
+ flex-wrap: wrap;
448
+ }
449
+
450
+ .feature-badge {
451
+ padding: 3px 8px;
452
+ border-radius: 10px;
453
+ font-size: 0.7rem;
454
+ font-weight: 500;
455
+ background: #f3f4f6;
456
+ color: #374151;
457
+ }
458
+
459
+ .feature-badge.vision {
460
+ background: #fef3c7;
461
+ color: #92400e;
462
+ }
463
+
464
+ .preview-message {
465
+ text-align: center;
466
+ padding: 60px 24px;
467
+ color: #6b7280;
468
+ background: linear-gradient(135deg, #f9fafb 0%, #f3f4f6 100%);
469
+ border-radius: 12px;
470
+ border: 2px dashed #d1d5db;
471
+ font-size: 1.1rem;
472
+ font-weight: 500;
473
+ }
474
+
475
+ .error-message {
476
+ text-align: center;
477
+ padding: 24px;
478
+ color: #dc2626;
479
+ background: linear-gradient(135deg, #fef2f2 0%, #fee2e2 100%);
480
+ border: 1px solid #fecaca;
481
+ border-radius: 12px;
482
+ font-weight: 500;
483
+ }
484
+
485
+ .preview-controls {
486
+ background: #f8fafc;
487
+ padding: 12px 20px;
488
+ border-radius: 8px 8px 0 0;
489
+ border-bottom: 1px solid #e5e7eb;
490
+ }
491
+
492
+ .preview-info {
493
+ display: flex;
494
+ justify-content: center;
495
+ gap: 24px;
496
+ font-size: 0.85rem;
497
+ color: #6b7280;
498
+ }
499
+
500
+ .info-item {
501
+ display: flex;
502
+ align-items: center;
503
+ gap: 6px;
504
+ }
505
+
506
+ /* Responsive design */
507
+ @media (max-width: 768px) {
508
+ .header-content {
509
+ flex-direction: column;
510
+ gap: 20px;
511
+ text-align: center;
512
+ }
513
 
514
+ .stats-grid {
515
+ grid-template-columns: 1fr;
516
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
517
 
518
+ .main-content {
519
+ padding-left: 0;
520
+ margin-top: 24px;
521
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
522
 
523
+ .status-indicators {
524
+ flex-direction: row;
525
+ justify-content: center;
526
+ }
527
+ }
528
+
529
+ /* Animation improvements */
530
+ .control-group {
531
+ transition: transform 0.2s ease, box-shadow 0.2s ease;
532
+ }
533
+
534
+ .control-group:hover {
535
+ transform: translateY(-1px);
536
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
537
+ }
538
+ """
539
+
540
+ # =============================================================================
541
+ # MAIN APPLICATION
542
+ # =============================================================================
543
+
544
+ def create_professional_ui():
545
+ """Create the professional AnyCoder UI"""
546
 
547
+ with gr.Blocks(
548
+ title="AnyCoder - Professional AI Development Suite",
549
+ theme=current_theme,
550
+ css=CUSTOM_CSS,
551
+ head="""
552
+ <meta name="description" content="AnyCoder - Professional AI Development Suite for creating modern applications">
553
+ <meta name="keywords" content="AI, code generation, web development, automation">
554
+ <link rel="preconnect" href="https://fonts.googleapis.com">
555
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
556
+ <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
557
+ """
558
+ ) as demo:
559
+
560
+ # State management
561
+ history = gr.State([])
562
+ setting = gr.State({"system": HTML_SYSTEM_PROMPT})
563
+ current_model = gr.State(DEFAULT_MODEL)
564
+ session_state = gr.State({"session_id": str(uuid.uuid4())})
565
+
566
+ # Header
567
+ with gr.Row(elem_classes=["header-row"]):
568
+ with gr.Column(scale=3):
569
+ gr.HTML("""
570
+ <div class="app-header">
571
+ <div class="header-content">
572
+ <div class="logo-section">
573
+ <div class="logo">⚑</div>
574
+ <div class="app-title">
575
+ <h1>AnyCoder</h1>
576
+ <p>Professional AI Development Suite</p>
577
+ </div>
578
+ </div>
579
+ <div class="status-indicators">
580
+ <div class="status-item">
581
+ <span class="status-dot active"></span>
582
+ <span>AI Models Ready</span>
583
+ </div>
584
+ <div class="status-item">
585
+ <span class="status-dot active"></span>
586
+ <span>Media Generation Active</span>
587
+ </div>
588
  </div>
589
  </div>
590
+ </div>
591
+ """)
592
+
593
+ with gr.Column(scale=1, min_width=200):
594
+ with gr.Row():
595
+ login_button = gr.LoginButton(scale=1, size="sm")
596
+
597
+ # Main interface
598
+ with gr.Row():
599
+ # Left sidebar - Controls
600
+ with gr.Column(scale=1, elem_classes=["sidebar"]):
601
+
602
+ # Model Selection
603
+ with gr.Group(elem_classes=["control-group"]):
604
+ gr.HTML('<div class="group-title">πŸ€– AI Model</div>')
605
+
606
+ model_dropdown = gr.Dropdown(
607
+ choices=[f"{model['name']} ({model['category']})" for model in AVAILABLE_MODELS],
608
+ value=f"{DEFAULT_MODEL['name']} ({DEFAULT_MODEL['category']})",
609
+ label="Select Model",
610
+ container=False
611
+ )
612
+
613
+ model_info = gr.HTML(get_model_info_html(DEFAULT_MODEL))
614
+
615
+ # Project Configuration
616
+ with gr.Group(elem_classes=["control-group"]):
617
+ gr.HTML('<div class="group-title">βš™οΈ Project Settings</div>')
618
+
619
+ language_dropdown = gr.Dropdown(
620
+ choices=[
621
+ "html", "streamlit", "gradio", "python",
622
+ "transformers.js", "svelte", "javascript", "css"
623
+ ],
624
+ value="html",
625
+ label="Project Type",
626
+ container=False
627
+ )
628
+
629
+ search_toggle = gr.Checkbox(
630
+ label="πŸ” Enable Web Search",
631
+ value=False,
632
+ info="Include web search for current information",
633
+ container=False
634
+ )
635
+
636
+ # Media Generation Controls
637
+ with gr.Group(elem_classes=["control-group"]):
638
+ gr.HTML('<div class="group-title">🎨 Media Generation</div>')
639
+
640
+ enable_images = gr.Checkbox(
641
+ label="Generate Images (text β†’ image)",
642
+ value=False,
643
+ container=False
644
+ )
645
+
646
+ enable_image_to_image = gr.Checkbox(
647
+ label="Transform Images (image β†’ image)",
648
+ value=False,
649
+ container=False
650
+ )
651
+
652
+ enable_video = gr.Checkbox(
653
+ label="Generate Videos (text β†’ video)",
654
+ value=False,
655
+ container=False
656
+ )
657
+
658
+ enable_music = gr.Checkbox(
659
+ label="Generate Music (text β†’ music)",
660
+ value=False,
661
+ container=False
662
+ )
663
+
664
+ # Input Sources
665
+ with gr.Group(elem_classes=["control-group"]):
666
+ gr.HTML('<div class="group-title">πŸ“ Input Sources</div>')
667
+
668
+ file_input = gr.File(
669
+ label="Reference File",
670
+ file_types=[".pdf", ".txt", ".md", ".csv", ".docx", ".jpg", ".jpeg", ".png"],
671
+ container=False
672
+ )
673
 
674
+ website_url_input = gr.Textbox(
675
+ label="Website URL (for redesign)",
676
+ placeholder="https://example.com",
677
+ container=False
678
  )
679
+
680
+ image_input = gr.Image(
681
+ label="Design Reference Image",
682
+ visible=DEFAULT_MODEL.get('supports_vision', False),
683
+ container=False
684
+ )
685
+
686
+ # Quick Start Examples
687
+ with gr.Group(elem_classes=["control-group"]):
688
+ gr.HTML('<div class="group-title">πŸš€ Quick Start</div>')
689
+
690
+ quick_start_buttons = []
691
+ for i, demo in enumerate(DEMO_LIST):
692
+ btn = gr.Button(
693
+ demo["title"],
694
+ variant="secondary",
695
+ size="sm",
696
+ elem_classes=["quick-start-btn"]
697
+ )
698
+ quick_start_buttons.append(btn)
699
 
700
+ # Main content area
701
+ with gr.Column(scale=3, elem_classes=["main-content"]):
702
+
703
+ # Input area
704
+ with gr.Group(elem_classes=["input-group"]):
705
+ input_textbox = gr.Textbox(
706
+ label="What would you like to build?",
707
+ placeholder="Describe your application in detail... (e.g., 'Create a modern dashboard with charts and user management')",
708
+ lines=4,
709
+ container=False,
710
+ elem_classes=["main-input"]
711
+ )
712
+
713
+ with gr.Row():
714
+ generate_btn = gr.Button(
715
+ "πŸš€ Generate Application",
716
+ variant="primary",
717
+ scale=3,
718
+ size="lg",
719
+ elem_classes=["generate-btn"]
720
  )
721
+ clear_btn = gr.Button(
722
+ "πŸ—‘οΈ Clear",
723
+ variant="secondary",
724
+ scale=1,
725
+ size="lg"
726
+ )
727
+
728
+ # Output area with professional tabs
729
+ with gr.Tabs(elem_classes=["output-tabs"]):
730
 
731
+ # Preview Tab
732
+ with gr.Tab("πŸ–₯️ Live Preview"):
733
+ preview_controls = gr.HTML("""
734
+ <div class="preview-controls">
735
+ <div class="preview-info">
736
+ <span class="info-item">πŸ“± Responsive Design</span>
737
+ <span class="info-item">⚑ Real-time Updates</span>
738
+ <span class="info-item">πŸ”’ Sandboxed Environment</span>
739
+ </div>
740
+ </div>
741
+ """)
742
 
743
+ sandbox = gr.HTML(
744
+ "<div class='preview-message'>Ready to generate your application</div>",
745
+ elem_classes=["preview-container"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
746
  )
747
+
748
+ # Code Tab
749
+ with gr.Tab("πŸ’» Source Code"):
750
+ with gr.Row():
751
+ with gr.Column(scale=4):
752
+ code_output = gr.Code(
753
+ language="html",
754
+ lines=25,
755
+ interactive=True,
756
+ label="Generated Code",
757
+ elem_classes=["code-editor"]
758
+ )
759
+
760
+ with gr.Column(scale=1, elem_classes=["code-sidebar"]):
761
+ # Code stats
762
+ with gr.Group():
763
+ gr.HTML('<div class="group-title">πŸ“Š Code Statistics</div>')
764
+ code_stats = gr.HTML(
765
+ "<div class='code-stats'>Ready to generate...</div>",
766
+ elem_classes=["code-stats"]
767
+ )
768
+
769
+ # Hidden components for functionality
770
+ history_output = gr.Chatbot(show_label=False, height=400, type="messages", visible=False)
771
+
772
+ # =============================================================================
773
+ # EVENT HANDLERS
774
+ # =============================================================================
775
 
776
+ # Model selection handler
777
+ model_dropdown.change(
778
+ handle_model_change,
779
+ inputs=[model_dropdown],
780
+ outputs=[current_model, model_info]
781
  )
782
 
783
+ # Update image input visibility based on model
784
+ current_model.change(
785
+ update_image_input_visibility,
786
+ inputs=[current_model],
787
+ outputs=[image_input]
788
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
789
 
790
  # Generation handler
791
+ generate_btn.click(
792
+ generation_code,
793
  inputs=[
794
+ input_textbox,
795
+ image_input,
796
+ gr.State(None), # generation_image_input placeholder
797
+ file_input,
798
+ website_url_input,
799
+ setting,
 
800
  history,
801
+ current_model,
802
+ search_toggle,
803
+ language_dropdown,
804
+ gr.State("auto"), # provider_state
805
+ enable_images,
806
+ enable_image_to_image,
807
+ gr.State(""), # image_to_image_prompt placeholder
808
+ gr.State(""), # text_to_image_prompt placeholder
809
+ gr.State(False), # enable_image_to_video placeholder
810
+ gr.State(""), # image_to_video_prompt placeholder
811
+ enable_video,
812
+ gr.State(""), # text_to_video_prompt placeholder
813
+ enable_music,
814
+ gr.State("") # text_to_music_prompt placeholder
815
  ],
816
+ outputs=[code_output, history, sandbox, history_output]
817
+ ).then(
818
+ generate_code_stats,
819
+ inputs=[code_output, language_dropdown],
820
+ outputs=[code_stats]
 
821
  )
822
 
823
+ # Enter key in input triggers generation
824
+ input_textbox.submit(
825
+ generation_code,
826
+ inputs=[
827
+ input_textbox,
828
+ image_input,
829
+ gr.State(None),
830
+ file_input,
831
+ website_url_input,
832
+ setting,
833
+ history,
834
+ current_model,
835
+ search_toggle,
836
+ language_dropdown,
837
+ gr.State("auto"),
838
+ enable_images,
839
+ enable_image_to_image,
840
+ gr.State(""),
841
+ gr.State(""),
842
+ gr.State(False),
843
+ gr.State(""),
844
+ enable_video,
845
+ gr.State(""),
846
+ enable_music,
847
+ gr.State("")
848
+ ],
849
+ outputs=[code_output, history, sandbox, history_output]
850
+ ).then(
851
+ generate_code_stats,
852
+ inputs=[code_output, language_dropdown],
853
+ outputs=[code_stats]
854
  )
855
 
856
  # Clear handler
857
+ clear_btn.click(
858
+ clear_history,
859
+ outputs=[history, history_output, file_input, website_url_input, input_textbox]
860
+ ).then(
861
+ lambda: [
862
+ gr.update(value="", language="html"),
863
+ "<div class='preview-message'>Ready to generate your next application</div>",
864
+ "<div class='code-stats'>Ready to generate...</div>"
865
+ ],
866
+ outputs=[code_output, sandbox, code_stats]
867
  )
868
 
869
  # Quick start button handlers
870
+ for i, btn in enumerate(quick_start_buttons):
871
  if i < len(DEMO_LIST):
872
  btn.click(
873
  lambda demo_idx=i: DEMO_LIST[demo_idx]['description'],
874
+ outputs=[input_textbox]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
875
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
876
 
877
+ # Language change updates code editor
878
+ language_dropdown.change(
879
+ lambda lang: gr.update(language=get_gradio_language(lang)),
880
+ inputs=[language_dropdown],
881
+ outputs=[code_output]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
882
  )
883
 
884
+ return demo
885
+
886
+ # =============================================================================
887
+ # MAIN ENTRY POINT
888
+ # =============================================================================
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
889
 
890
  def main():
891
  """Main application entry point"""
892
  print("πŸš€ Starting AnyCoder Professional AI Development Suite...")
893
 
894
+ # Setup cleanup
895
+ cleanup_all_temp_media()
896
+ reap_old_media()
897
+
898
+ # Create and launch the UI
899
+ demo = create_professional_ui()
900
 
 
901
  demo.queue(api_open=False, default_concurrency_limit=20).launch(
902
  show_api=False,
903
  share=False,
904
+ server_name="0.0.0.0",
905
  server_port=7860,
906
+ show_error=True
 
907
  )
908
 
909
  if __name__ == "__main__":