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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
Advanced UI components and interface management for the AnyCoder application.
|
3 |
+
"""
|
4 |
+
|
5 |
+
import os
|
6 |
+
import gradio as gr
|
7 |
+
import uuid
|
8 |
+
import webbrowser
|
9 |
+
import urllib.parse
|
10 |
+
from typing import Dict, List, Optional, Tuple, Any, Union
|
11 |
+
from pathlib import Path
|
12 |
+
|
13 |
+
from config import (
|
14 |
+
THEME_CONFIGS, DEMO_LIST, AVAILABLE_MODELS, DEFAULT_MODEL, DEFAULT_MODEL_NAME,
|
15 |
+
get_saved_theme, save_theme_preference, get_gradio_language
|
16 |
+
)
|
17 |
+
from utils import extract_text_from_file, process_image_for_model
|
18 |
+
from web_utils import check_hf_space_url, parse_repo_or_model_url
|
19 |
+
from code_processing import (
|
20 |
+
parse_transformers_js_output, format_transformers_js_output,
|
21 |
+
parse_svelte_output, format_svelte_output,
|
22 |
+
parse_multipage_html_output, format_multipage_output, validate_and_autofix_files,
|
23 |
+
inline_multipage_into_single_preview
|
24 |
+
)
|
25 |
+
|
26 |
+
class AdvancedUIManager:
|
27 |
+
"""Manages advanced UI components and interactions"""
|
28 |
+
|
29 |
+
def __init__(self):
|
30 |
+
self.current_theme = get_saved_theme()
|
31 |
+
self.demo_categories = self._organize_demos_by_category()
|
32 |
+
self.model_categories = self._organize_models_by_category()
|
33 |
+
|
34 |
+
def _organize_demos_by_category(self) -> Dict[str, List[Dict]]:
|
35 |
+
"""Organize demo examples by category for better UI"""
|
36 |
+
categories = {}
|
37 |
+
for demo in DEMO_LIST:
|
38 |
+
category = demo.get('category', 'General')
|
39 |
+
if category not in categories:
|
40 |
+
categories[category] = []
|
41 |
+
categories[category].append(demo)
|
42 |
+
return categories
|
43 |
+
|
44 |
+
def _organize_models_by_category(self) -> Dict[str, List[Dict]]:
|
45 |
+
"""Organize models by category for advanced selection UI"""
|
46 |
+
categories = {}
|
47 |
+
for model in AVAILABLE_MODELS:
|
48 |
+
category = model.get('category', 'General')
|
49 |
+
if category not in categories:
|
50 |
+
categories[category] = []
|
51 |
+
categories[category].append(model)
|
52 |
+
return categories
|
53 |
+
|
54 |
+
def create_advanced_model_selector(self) -> gr.Group:
|
55 |
+
"""Create an advanced model selector with categories and features"""
|
56 |
+
with gr.Group() as model_group:
|
57 |
+
gr.Markdown("### 🤖 AI Model Selection", elem_classes=["model-header"])
|
58 |
+
|
59 |
+
with gr.Accordion("Model Categories", open=False, elem_classes=["model-accordion"]):
|
60 |
+
model_tabs = gr.Tabs()
|
61 |
+
|
62 |
+
with model_tabs:
|
63 |
+
for category, models in self.model_categories.items():
|
64 |
+
with gr.Tab(category, elem_classes=["model-tab"]):
|
65 |
+
for model in models:
|
66 |
+
vision_icon = "👁️" if model.get('supports_vision', False) else ""
|
67 |
+
model_btn = gr.Button(
|
68 |
+
f"{vision_icon} {model['name']}",
|
69 |
+
variant="secondary",
|
70 |
+
elem_classes=["model-button"],
|
71 |
+
size="sm"
|
72 |
+
)
|
73 |
+
gr.Markdown(
|
74 |
+
f"*{model['description']}*",
|
75 |
+
elem_classes=["model-description"]
|
76 |
+
)
|
77 |
+
|
78 |
+
model_dropdown = gr.Dropdown(
|
79 |
+
choices=[model['name'] for model in AVAILABLE_MODELS],
|
80 |
+
value=DEFAULT_MODEL_NAME,
|
81 |
+
label="Selected Model",
|
82 |
+
elem_classes=["model-dropdown"],
|
83 |
+
container=True,
|
84 |
+
scale=2
|
85 |
+
)
|
86 |
+
|
87 |
+
with gr.Row():
|
88 |
+
model_info_btn = gr.Button("ℹ️", size="sm", elem_classes=["info-button"])
|
89 |
+
model_refresh_btn = gr.Button("🔄", size="sm", elem_classes=["refresh-button"])
|
90 |
+
|
91 |
+
return model_group, model_dropdown, model_info_btn, model_refresh_btn
|
92 |
+
|
93 |
+
def create_advanced_demo_gallery(self) -> gr.Group:
|
94 |
+
"""Create an advanced demo gallery with categories and search"""
|
95 |
+
with gr.Group() as demo_group:
|
96 |
+
gr.Markdown("### 🎯 Project Templates", elem_classes=["demo-header"])
|
97 |
+
|
98 |
+
demo_search = gr.Textbox(
|
99 |
+
placeholder="Search templates...",
|
100 |
+
label="",
|
101 |
+
elem_classes=["demo-search"],
|
102 |
+
container=False
|
103 |
+
)
|
104 |
+
|
105 |
+
demo_filter = gr.Dropdown(
|
106 |
+
choices=["All Categories"] + list(self.demo_categories.keys()),
|
107 |
+
value="All Categories",
|
108 |
+
label="Category Filter",
|
109 |
+
elem_classes=["demo-filter"]
|
110 |
+
)
|
111 |
+
|
112 |
+
with gr.Group(elem_classes=["demo-gallery"]):
|
113 |
+
demo_cards = []
|
114 |
+
for category, demos in self.demo_categories.items():
|
115 |
+
with gr.Group(visible=True, elem_classes=[f"demo-category-{category.lower().replace(' ', '-')}"]):
|
116 |
+
gr.Markdown(f"#### {category}", elem_classes=["category-header"])
|
117 |
+
|
118 |
+
with gr.Row():
|
119 |
+
for demo in demos:
|
120 |
+
complexity_color = {
|
121 |
+
"Beginner": "success",
|
122 |
+
"Intermediate": "secondary",
|
123 |
+
"Advanced": "stop"
|
124 |
+
}.get(demo.get('complexity', 'Intermediate'), 'secondary')
|
125 |
+
|
126 |
+
demo_card = gr.Button(
|
127 |
+
f"**{demo['title']}**\n{demo['description'][:100]}...",
|
128 |
+
variant=complexity_color,
|
129 |
+
elem_classes=["demo-card"],
|
130 |
+
size="lg"
|
131 |
+
)
|
132 |
+
demo_cards.append((demo_card, demo))
|
133 |
+
|
134 |
+
return demo_group, demo_cards, demo_search, demo_filter
|
135 |
+
|
136 |
+
def create_advanced_media_controls(self) -> gr.Group:
|
137 |
+
"""Create advanced media generation controls with smart layouts"""
|
138 |
+
with gr.Group() as media_group:
|
139 |
+
gr.Markdown("### 🎨 AI Media Generation", elem_classes=["media-header"])
|
140 |
+
|
141 |
+
with gr.Accordion("Media Options", open=False, elem_classes=["media-accordion"]):
|
142 |
+
with gr.Tabs() as media_tabs:
|
143 |
+
# Text to Image Tab
|
144 |
+
with gr.Tab("🖼️ Text → Image", elem_classes=["media-tab"]):
|
145 |
+
text_to_image_toggle = gr.Checkbox(
|
146 |
+
label="Generate Images from Text",
|
147 |
+
value=False,
|
148 |
+
elem_classes=["media-toggle"]
|
149 |
+
)
|
150 |
+
text_to_image_prompt = gr.Textbox(
|
151 |
+
label="Image Description",
|
152 |
+
placeholder="A modern, minimalist dashboard with clean lines and soft colors",
|
153 |
+
lines=2,
|
154 |
+
visible=False,
|
155 |
+
elem_classes=["media-prompt"]
|
156 |
+
)
|
157 |
+
|
158 |
+
with gr.Row(visible=False) as t2i_advanced:
|
159 |
+
t2i_style = gr.Dropdown(
|
160 |
+
choices=["Photorealistic", "Illustration", "Digital Art", "Sketch", "Abstract"],
|
161 |
+
value="Digital Art",
|
162 |
+
label="Style"
|
163 |
+
)
|
164 |
+
t2i_quality = gr.Slider(
|
165 |
+
minimum=0.5,
|
166 |
+
maximum=1.0,
|
167 |
+
value=0.9,
|
168 |
+
step=0.1,
|
169 |
+
label="Quality"
|
170 |
+
)
|
171 |
+
|
172 |
+
# Image to Image Tab
|
173 |
+
with gr.Tab("🎭 Image → Image", elem_classes=["media-tab"]):
|
174 |
+
image_to_image_toggle = gr.Checkbox(
|
175 |
+
label="Transform Uploaded Images",
|
176 |
+
value=False,
|
177 |
+
elem_classes=["media-toggle"]
|
178 |
+
)
|
179 |
+
generation_image_input = gr.Image(
|
180 |
+
label="Source Image",
|
181 |
+
visible=False,
|
182 |
+
elem_classes=["media-image"]
|
183 |
+
)
|
184 |
+
image_to_image_prompt = gr.Textbox(
|
185 |
+
label="Transformation Description",
|
186 |
+
placeholder="Transform this into a futuristic version",
|
187 |
+
lines=2,
|
188 |
+
visible=False,
|
189 |
+
elem_classes=["media-prompt"]
|
190 |
+
)
|
191 |
+
|
192 |
+
# Image to Video Tab
|
193 |
+
with gr.Tab("🎬 Image → Video", elem_classes=["media-tab"]):
|
194 |
+
image_to_video_toggle = gr.Checkbox(
|
195 |
+
label="Generate Video from Image",
|
196 |
+
value=False,
|
197 |
+
elem_classes=["media-toggle"]
|
198 |
+
)
|
199 |
+
image_to_video_prompt = gr.Textbox(
|
200 |
+
label="Motion Description",
|
201 |
+
placeholder="The person starts walking forward with a confident stride",
|
202 |
+
lines=2,
|
203 |
+
visible=False,
|
204 |
+
elem_classes=["media-prompt"]
|
205 |
+
)
|
206 |
+
|
207 |
+
# Text to Video Tab
|
208 |
+
with gr.Tab("📹 Text → Video", elem_classes=["media-tab"]):
|
209 |
+
text_to_video_toggle = gr.Checkbox(
|
210 |
+
label="Generate Video from Text",
|
211 |
+
value=False,
|
212 |
+
elem_classes=["media-toggle"]
|
213 |
+
)
|
214 |
+
text_to_video_prompt = gr.Textbox(
|
215 |
+
label="Video Description",
|
216 |
+
placeholder="A time-lapse of a city skyline transitioning from day to night",
|
217 |
+
lines=2,
|
218 |
+
visible=False,
|
219 |
+
elem_classes=["media-prompt"]
|
220 |
+
)
|
221 |
+
|
222 |
+
# Text to Music Tab
|
223 |
+
with gr.Tab("🎵 Text → Music", elem_classes=["media-tab"]):
|
224 |
+
text_to_music_toggle = gr.Checkbox(
|
225 |
+
label="Generate Background Music",
|
226 |
+
value=False,
|
227 |
+
elem_classes=["media-toggle"]
|
228 |
+
)
|
229 |
+
text_to_music_prompt = gr.Textbox(
|
230 |
+
label="Music Description",
|
231 |
+
placeholder="Upbeat electronic background music for a tech demo",
|
232 |
+
lines=2,
|
233 |
+
visible=False,
|
234 |
+
elem_classes=["media-prompt"]
|
235 |
+
)
|
236 |
+
|
237 |
+
with gr.Row(visible=False) as music_controls:
|
238 |
+
music_duration = gr.Slider(
|
239 |
+
minimum=10,
|
240 |
+
maximum=120,
|
241 |
+
value=30,
|
242 |
+
step=5,
|
243 |
+
label="Duration (seconds)"
|
244 |
+
)
|
245 |
+
music_style = gr.Dropdown(
|
246 |
+
choices=["Electronic", "Orchestral", "Ambient", "Upbeat", "Cinematic"],
|
247 |
+
value="Electronic",
|
248 |
+
label="Style"
|
249 |
+
)
|
250 |
+
|
251 |
+
# Create visibility toggle handlers
|
252 |
+
media_components = {
|
253 |
+
'text_to_image_toggle': text_to_image_toggle,
|
254 |
+
'text_to_image_prompt': text_to_image_prompt,
|
255 |
+
't2i_advanced': t2i_advanced,
|
256 |
+
'image_to_image_toggle': image_to_image_toggle,
|
257 |
+
'generation_image_input': generation_image_input,
|
258 |
+
'image_to_image_prompt': image_to_image_prompt,
|
259 |
+
'image_to_video_toggle': image_to_video_toggle,
|
260 |
+
'image_to_video_prompt': image_to_video_prompt,
|
261 |
+
'text_to_video_toggle': text_to_video_toggle,
|
262 |
+
'text_to_video_prompt': text_to_video_prompt,
|
263 |
+
'text_to_music_toggle': text_to_music_toggle,
|
264 |
+
'text_to_music_prompt': text_to_music_prompt,
|
265 |
+
'music_controls': music_controls,
|
266 |
+
}
|
267 |
+
|
268 |
+
return media_group, media_components
|
269 |
+
|
270 |
+
def create_advanced_code_editor(self) -> gr.Group:
|
271 |
+
"""Create advanced code editor with multi-file support and intelligent features"""
|
272 |
+
with gr.Group() as editor_group:
|
273 |
+
gr.Markdown("### 💻 Generated Code", elem_classes=["editor-header"])
|
274 |
+
|
275 |
+
with gr.Row():
|
276 |
+
with gr.Column(scale=3):
|
277 |
+
# Main code editor
|
278 |
+
code_output = gr.Code(
|
279 |
+
language="html",
|
280 |
+
lines=25,
|
281 |
+
interactive=True,
|
282 |
+
label="Generated Code",
|
283 |
+
elem_classes=["main-editor"]
|
284 |
+
)
|
285 |
+
|
286 |
+
# Multi-file editors (initially hidden)
|
287 |
+
with gr.Group(visible=False, elem_classes=["multi-file-group"]) as transformers_group:
|
288 |
+
gr.Markdown("#### Transformers.js Files")
|
289 |
+
with gr.Tabs():
|
290 |
+
with gr.Tab("index.html"):
|
291 |
+
tjs_html_code = gr.Code(language="html", lines=20, interactive=True)
|
292 |
+
with gr.Tab("index.js"):
|
293 |
+
tjs_js_code = gr.Code(language="javascript", lines=20, interactive=True)
|
294 |
+
with gr.Tab("style.css"):
|
295 |
+
tjs_css_code = gr.Code(language="css", lines=20, interactive=True)
|
296 |
+
|
297 |
+
with gr.Group(visible=False, elem_classes=["multi-file-group"]) as svelte_group:
|
298 |
+
gr.Markdown("#### Svelte Files")
|
299 |
+
with gr.Tabs():
|
300 |
+
with gr.Tab("App.svelte"):
|
301 |
+
svelte_app_code = gr.Code(language="javascript", lines=20, interactive=True)
|
302 |
+
with gr.Tab("app.css"):
|
303 |
+
svelte_css_code = gr.Code(language="css", lines=20, interactive=True)
|
304 |
+
|
305 |
+
with gr.Column(scale=1, elem_classes=["editor-sidebar"]):
|
306 |
+
# Code actions
|
307 |
+
with gr.Group(elem_classes=["code-actions"]):
|
308 |
+
gr.Markdown("**Actions**")
|
309 |
+
|
310 |
+
code_format_btn = gr.Button("🎨 Format Code", size="sm")
|
311 |
+
code_download_btn = gr.Button("💾 Download", size="sm")
|
312 |
+
code_share_btn = gr.Button("🔗 Share", size="sm")
|
313 |
+
code_deploy_btn = gr.Button("🚀 Deploy", size="sm", variant="primary")
|
314 |
+
|
315 |
+
# Code statistics
|
316 |
+
with gr.Group(elem_classes=["code-stats"]):
|
317 |
+
gr.Markdown("**Statistics**")
|
318 |
+
code_stats = gr.JSON(
|
319 |
+
value={"lines": 0, "characters": 0, "files": 1},
|
320 |
+
label="",
|
321 |
+
elem_classes=["stats-display"]
|
322 |
+
)
|
323 |
+
|
324 |
+
editor_components = {
|
325 |
+
'code_output': code_output,
|
326 |
+
'transformers_group': transformers_group,
|
327 |
+
'tjs_html_code': tjs_html_code,
|
328 |
+
'tjs_js_code': tjs_js_code,
|
329 |
+
'tjs_css_code': tjs_css_code,
|
330 |
+
'svelte_group': svelte_group,
|
331 |
+
'svelte_app_code': svelte_app_code,
|
332 |
+
'svelte_css_code': svelte_css_code,
|
333 |
+
'code_format_btn': code_format_btn,
|
334 |
+
'code_download_btn': code_download_btn,
|
335 |
+
'code_share_btn': code_share_btn,
|
336 |
+
'code_deploy_btn': code_deploy_btn,
|
337 |
+
'code_stats': code_stats
|
338 |
+
}
|
339 |
+
|
340 |
+
return editor_group, editor_components
|
341 |
+
|
342 |
+
def create_advanced_preview_panel(self) -> gr.Group:
|
343 |
+
"""Create advanced preview panel with multiple view modes"""
|
344 |
+
with gr.Group() as preview_group:
|
345 |
+
gr.Markdown("### 👁️ Live Preview", elem_classes=["preview-header"])
|
346 |
+
|
347 |
+
with gr.Row():
|
348 |
+
preview_mode = gr.Radio(
|
349 |
+
choices=["Desktop", "Tablet", "Mobile"],
|
350 |
+
value="Desktop",
|
351 |
+
label="View Mode",
|
352 |
+
elem_classes=["preview-mode"]
|
353 |
+
)
|
354 |
+
|
355 |
+
preview_refresh_btn = gr.Button("🔄", size="sm", elem_classes=["preview-refresh"])
|
356 |
+
preview_fullscreen_btn = gr.Button("⛶", size="sm", elem_classes=["preview-fullscreen"])
|
357 |
+
preview_qr_btn = gr.Button("📱", size="sm", elem_classes=["preview-qr"])
|
358 |
+
|
359 |
+
# Main preview area
|
360 |
+
sandbox = gr.HTML(
|
361 |
+
label="Live Preview",
|
362 |
+
elem_classes=["preview-sandbox"]
|
363 |
+
)
|
364 |
+
|
365 |
+
# Preview status bar
|
366 |
+
with gr.Row(elem_classes=["preview-status"]):
|
367 |
+
preview_status = gr.Markdown("Ready", elem_classes=["status-text"])
|
368 |
+
preview_metrics = gr.JSON(
|
369 |
+
value={"load_time": "0ms", "size": "0KB", "elements": 0},
|
370 |
+
label="",
|
371 |
+
elem_classes=["preview-metrics"]
|
372 |
+
)
|
373 |
+
|
374 |
+
preview_components = {
|
375 |
+
'sandbox': sandbox,
|
376 |
+
'preview_mode': preview_mode,
|
377 |
+
'preview_refresh_btn': preview_refresh_btn,
|
378 |
+
'preview_fullscreen_btn': preview_fullscreen_btn,
|
379 |
+
'preview_qr_btn': preview_qr_btn,
|
380 |
+
'preview_status': preview_status,
|
381 |
+
'preview_metrics': preview_metrics
|
382 |
+
}
|
383 |
+
|
384 |
+
return preview_group, preview_components
|
385 |
+
|
386 |
+
def create_chat_interface(self) -> gr.Group:
|
387 |
+
"""Create advanced chat-based interface for beta mode"""
|
388 |
+
with gr.Group() as chat_group:
|
389 |
+
gr.Markdown("### 💬 AI Assistant Chat", elem_classes=["chat-header"])
|
390 |
+
|
391 |
+
# Main chat area
|
392 |
+
chatbot = gr.Chatbot(
|
393 |
+
type="messages",
|
394 |
+
show_label=False,
|
395 |
+
height=400,
|
396 |
+
layout="bubble",
|
397 |
+
bubble_full_width=False,
|
398 |
+
group_consecutive_messages=True,
|
399 |
+
elem_classes=["main-chatbot"],
|
400 |
+
avatar_images=("🧑💻", "🤖")
|
401 |
+
)
|
402 |
+
|
403 |
+
# Chat input with advanced features
|
404 |
+
with gr.Row():
|
405 |
+
chat_input = gr.MultimodalTextbox(
|
406 |
+
placeholder="Describe what you want to build... (supports text, images, and files)",
|
407 |
+
submit_btn=True,
|
408 |
+
stop_btn=False,
|
409 |
+
show_label=False,
|
410 |
+
sources=["upload", "microphone"],
|
411 |
+
elem_classes=["chat-input"],
|
412 |
+
scale=4
|
413 |
+
)
|
414 |
+
|
415 |
+
chat_voice_btn = gr.Button("🎤", size="sm", elem_classes=["voice-button"])
|
416 |
+
|
417 |
+
# Chat controls
|
418 |
+
with gr.Row():
|
419 |
+
chat_clear_btn = gr.ClearButton([chat_input, chatbot], size="sm")
|
420 |
+
chat_export_btn = gr.Button("📤 Export Chat", size="sm")
|
421 |
+
chat_settings_btn = gr.Button("⚙️", size="sm")
|
422 |
+
|
423 |
+
# Quick actions
|
424 |
+
with gr.Row(elem_classes=["chat-quick-actions"]):
|
425 |
+
quick_actions = [
|
426 |
+
("🌐 Website", "Create a modern website"),
|
427 |
+
("📱 App", "Build a mobile app"),
|
428 |
+
("📊 Dashboard", "Design a data dashboard"),
|
429 |
+
("🎮 Game", "Create an interactive game")
|
430 |
+
]
|
431 |
+
|
432 |
+
quick_buttons = []
|
433 |
+
for icon_text, prompt in quick_actions:
|
434 |
+
btn = gr.Button(icon_text, size="sm", elem_classes=["quick-action"])
|
435 |
+
quick_buttons.append((btn, prompt))
|
436 |
+
|
437 |
+
chat_components = {
|
438 |
+
'chatbot': chatbot,
|
439 |
+
'chat_input': chat_input,
|
440 |
+
'chat_voice_btn': chat_voice_btn,
|
441 |
+
'chat_clear_btn': chat_clear_btn,
|
442 |
+
'chat_export_btn': chat_export_btn,
|
443 |
+
'chat_settings_btn': chat_settings_btn,
|
444 |
+
'quick_buttons': quick_buttons
|
445 |
+
}
|
446 |
+
|
447 |
+
return chat_group, chat_components
|
448 |
+
|
449 |
+
def create_advanced_sidebar(self) -> gr.Column:
|
450 |
+
"""Create advanced sidebar with intelligent organization"""
|
451 |
+
with gr.Column(elem_classes=["advanced-sidebar"]) as sidebar:
|
452 |
+
# Header with user info
|
453 |
+
with gr.Group(elem_classes=["sidebar-header"]):
|
454 |
+
login_button = gr.LoginButton(elem_classes=["login-btn"])
|
455 |
+
|
456 |
+
with gr.Row():
|
457 |
+
beta_toggle = gr.Checkbox(
|
458 |
+
value=False,
|
459 |
+
label="🧪 Beta Chat Mode",
|
460 |
+
info="Try our new conversational interface",
|
461 |
+
elem_classes=["beta-toggle"]
|
462 |
+
)
|
463 |
+
|
464 |
+
# Chat interface (hidden by default)
|
465 |
+
chat_group, chat_components = self.create_chat_interface()
|
466 |
+
chat_group.visible = False
|
467 |
+
|
468 |
+
# Classic controls
|
469 |
+
with gr.Group(elem_classes=["classic-controls"]) as classic_group:
|
470 |
+
# Project input section
|
471 |
+
with gr.Group(elem_classes=["input-section"]):
|
472 |
+
gr.Markdown("### 🎯 Project Description")
|
473 |
+
input_textbox = gr.Textbox(
|
474 |
+
label="What would you like to build?",
|
475 |
+
placeholder="Describe your application in detail...",
|
476 |
+
lines=3,
|
477 |
+
elem_classes=["main-input"]
|
478 |
+
)
|
479 |
+
|
480 |
+
# Advanced model selector
|
481 |
+
model_group, model_dropdown, model_info_btn, model_refresh_btn = self.create_advanced_model_selector()
|
482 |
+
|
483 |
+
# Language and framework selection
|
484 |
+
with gr.Group(elem_classes=["language-section"]):
|
485 |
+
gr.Markdown("### ⚙️ Technology Stack")
|
486 |
+
|
487 |
+
language_dropdown = gr.Dropdown(
|
488 |
+
choices=[
|
489 |
+
"HTML/CSS/JS", "React", "Vue", "Svelte", "Streamlit",
|
490 |
+
"Gradio", "Python", "Transformers.js", "Node.js", "FastAPI"
|
491 |
+
],
|
492 |
+
value="HTML/CSS/JS",
|
493 |
+
label="Framework",
|
494 |
+
elem_classes=["language-dropdown"]
|
495 |
+
)
|
496 |
+
|
497 |
+
with gr.Row():
|
498 |
+
responsive_toggle = gr.Checkbox(
|
499 |
+
label="📱 Responsive Design",
|
500 |
+
value=True,
|
501 |
+
elem_classes=["feature-toggle"]
|
502 |
+
)
|
503 |
+
dark_mode_toggle = gr.Checkbox(
|
504 |
+
label="🌙 Dark Mode Support",
|
505 |
+
value=False,
|
506 |
+
elem_classes=["feature-toggle"]
|
507 |
+
)
|
508 |
+
|
509 |
+
# File inputs section
|
510 |
+
with gr.Group(elem_classes=["file-section"]):
|
511 |
+
gr.Markdown("### 📂 Input Sources")
|
512 |
+
|
513 |
+
file_input = gr.File(
|
514 |
+
label="Reference Files",
|
515 |
+
file_types=[".pdf", ".txt", ".md", ".csv", ".docx", ".jpg", ".png"],
|
516 |
+
elem_classes=["file-input"]
|
517 |
+
)
|
518 |
+
|
519 |
+
website_url_input = gr.Textbox(
|
520 |
+
label="Website to Redesign",
|
521 |
+
placeholder="https://example.com",
|
522 |
+
elem_classes=["url-input"]
|
523 |
+
)
|
524 |
+
|
525 |
+
image_input = gr.Image(
|
526 |
+
label="UI Design Reference",
|
527 |
+
visible=False,
|
528 |
+
elem_classes=["image-input"]
|
529 |
+
)
|
530 |
+
|
531 |
+
# Media generation controls
|
532 |
+
media_group, media_components = self.create_advanced_media_controls()
|
533 |
+
|
534 |
+
# Advanced options
|
535 |
+
with gr.Accordion("🔧 Advanced Options", open=False, elem_classes=["advanced-options"]):
|
536 |
+
search_toggle = gr.Checkbox(
|
537 |
+
label="🌐 Enable Web Search",
|
538 |
+
value=False,
|
539 |
+
info="Use real-time web search for latest information"
|
540 |
+
)
|
541 |
+
|
542 |
+
optimization_level = gr.Slider(
|
543 |
+
minimum=1,
|
544 |
+
maximum=5,
|
545 |
+
value=3,
|
546 |
+
step=1,
|
547 |
+
label="Code Optimization Level",
|
548 |
+
info="Higher values produce more optimized code"
|
549 |
+
)
|
550 |
+
|
551 |
+
accessibility_toggle = gr.Checkbox(
|
552 |
+
label="♿ Accessibility Focus",
|
553 |
+
value=True,
|
554 |
+
info="Prioritize accessibility best practices"
|
555 |
+
)
|
556 |
+
|
557 |
+
# Generation controls
|
558 |
+
with gr.Row(elem_classes=["generation-controls"]):
|
559 |
+
generate_btn = gr.Button(
|
560 |
+
"✨ Generate Code",
|
561 |
+
variant="primary",
|
562 |
+
size="lg",
|
563 |
+
elem_classes=["generate-button"]
|
564 |
+
)
|
565 |
+
|
566 |
+
with gr.Column(scale=1):
|
567 |
+
clear_btn = gr.Button("🗑️", size="sm", elem_classes=["clear-button"])
|
568 |
+
stop_btn = gr.Button("⏹️", size="sm", elem_classes=["stop-button"])
|
569 |
+
|
570 |
+
# Demo gallery
|
571 |
+
demo_group, demo_cards, demo_search, demo_filter = self.create_advanced_demo_gallery()
|
572 |
+
|
573 |
+
# Project import section
|
574 |
+
with gr.Group(elem_classes=["import-section"]):
|
575 |
+
gr.Markdown("### 📥 Import Project")
|
576 |
+
|
577 |
+
import_url = gr.Textbox(
|
578 |
+
label="Project URL",
|
579 |
+
placeholder="GitHub, HuggingFace Space, or Model URL",
|
580 |
+
elem_classes=["import-input"]
|
581 |
+
)
|
582 |
+
|
583 |
+
with gr.Row():
|
584 |
+
import_btn = gr.Button("Import", size="sm")
|
585 |
+
import_status = gr.Markdown("", visible=False)
|
586 |
+
|
587 |
+
# Deployment section
|
588 |
+
with gr.Group(elem_classes=["deploy-section"], visible=False) as deploy_group:
|
589 |
+
gr.Markdown("### 🚀 Deploy Application")
|
590 |
+
|
591 |
+
space_name_input = gr.Textbox(
|
592 |
+
label="App Name",
|
593 |
+
placeholder="my-awesome-app",
|
594 |
+
elem_classes=["space-name-input"]
|
595 |
+
)
|
596 |
+
|
597 |
+
sdk_dropdown = gr.Dropdown(
|
598 |
+
choices=["Static HTML", "Gradio", "Streamlit", "Transformers.js", "Svelte"],
|
599 |
+
value="Static HTML",
|
600 |
+
label="Deployment Type",
|
601 |
+
elem_classes=["sdk-dropdown"]
|
602 |
+
)
|
603 |
+
|
604 |
+
deploy_btn = gr.Button(
|
605 |
+
"🚀 Deploy to HuggingFace",
|
606 |
+
variant="primary",
|
607 |
+
elem_classes=["deploy-button"]
|
608 |
+
)
|
609 |
+
|
610 |
+
deploy_status = gr.Markdown("", visible=False, elem_classes=["deploy-status"])
|
611 |
+
|
612 |
+
# Collect all components for return
|
613 |
+
sidebar_components = {
|
614 |
+
'login_button': login_button,
|
615 |
+
'beta_toggle': beta_toggle,
|
616 |
+
'chat_group': chat_group,
|
617 |
+
'chat_components': chat_components,
|
618 |
+
'classic_group': classic_group,
|
619 |
+
'input_textbox': input_textbox,
|
620 |
+
'model_dropdown': model_dropdown,
|
621 |
+
'model_info_btn': model_info_btn,
|
622 |
+
'model_refresh_btn': model_refresh_btn,
|
623 |
+
'language_dropdown': language_dropdown,
|
624 |
+
'responsive_toggle': responsive_toggle,
|
625 |
+
'dark_mode_toggle': dark_mode_toggle,
|
626 |
+
'file_input': file_input,
|
627 |
+
'website_url_input': website_url_input,
|
628 |
+
'image_input': image_input,
|
629 |
+
'media_components': media_components,
|
630 |
+
'search_toggle': search_toggle,
|
631 |
+
'optimization_level': optimization_level,
|
632 |
+
'accessibility_toggle': accessibility_toggle,
|
633 |
+
'generate_btn': generate_btn,
|
634 |
+
'clear_btn': clear_btn,
|
635 |
+
'stop_btn': stop_btn,
|
636 |
+
'demo_cards': demo_cards,
|
637 |
+
'demo_search': demo_search,
|
638 |
+
'demo_filter': demo_filter,
|
639 |
+
'import_url': import_url,
|
640 |
+
'import_btn': import_btn,
|
641 |
+
'import_status': import_status,
|
642 |
+
'deploy_group': deploy_group,
|
643 |
+
'space_name_input': space_name_input,
|
644 |
+
'sdk_dropdown': sdk_dropdown,
|
645 |
+
'deploy_btn': deploy_btn,
|
646 |
+
'deploy_status': deploy_status
|
647 |
+
}
|
648 |
+
|
649 |
+
return sidebar, sidebar_components
|
650 |
+
|
651 |
+
class ThemeManager:
|
652 |
+
"""Manages application themes and styling"""
|
653 |
+
|
654 |
+
@staticmethod
|
655 |
+
def get_custom_css() -> str:
|
656 |
+
"""Get custom CSS for advanced styling"""
|
657 |
+
return """
|
658 |
+
/* Advanced AnyCoder Styling */
|
659 |
+
|
660 |
+
.advanced-sidebar {
|
661 |
+
background: linear-gradient(145deg, #f8fafc 0%, #f1f5f9 100%);
|
662 |
+
border-radius: 12px;
|
663 |
+
padding: 16px;
|
664 |
+
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
|
665 |
+
}
|
666 |
+
|
667 |
+
.sidebar-header {
|
668 |
+
background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
|
669 |
+
color: white;
|
670 |
+
padding: 12px;
|
671 |
+
border-radius: 8px;
|
672 |
+
margin-bottom: 16px;
|
673 |
+
}
|
674 |
+
|
675 |
+
.main-input {
|
676 |
+
border-radius: 8px;
|
677 |
+
border: 2px solid #e5e7eb;
|
678 |
+
transition: border-color 0.2s ease;
|
679 |
+
}
|
680 |
+
|
681 |
+
.main-input:focus {
|
682 |
+
border-color: #3b82f6;
|
683 |
+
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
|
684 |
+
}
|
685 |
+
|
686 |
+
.generate-button {
|
687 |
+
background: linear-gradient(135deg, #10b981 0%, #059669 100%);
|
688 |
+
border: none;
|
689 |
+
border-radius: 8px;
|
690 |
+
font-weight: 600;
|
691 |
+
text-transform: uppercase;
|
692 |
+
letter-spacing: 0.5px;
|
693 |
+
transition: all 0.2s ease;
|
694 |
+
}
|
695 |
+
|
696 |
+
.generate-button:hover {
|
697 |
+
transform: translateY(-1px);
|
698 |
+
box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
|
699 |
+
}
|
700 |
+
|
701 |
+
.demo-card {
|
702 |
+
background: white;
|
703 |
+
border: 1px solid #e5e7eb;
|
704 |
+
border-radius: 8px;
|
705 |
+
padding: 12px;
|
706 |
+
transition: all 0.2s ease;
|
707 |
+
text-align: left;
|
708 |
+
min-height: 100px;
|
709 |
+
}
|
710 |
+
|
711 |
+
.demo-card:hover {
|
712 |
+
transform: translateY(-2px);
|
713 |
+
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
|
714 |
+
border-color: #3b82f6;
|
715 |
+
}
|
716 |
+
|
717 |
+
.model-button {
|
718 |
+
background: white;
|
719 |
+
border: 1px solid #d1d5db;
|
720 |
+
border-radius: 6px;
|
721 |
+
margin: 4px 0;
|
722 |
+
transition: all 0.2s ease;
|
723 |
+
}
|
724 |
+
|
725 |
+
.model-button:hover {
|
726 |
+
background: #f9fafb;
|
727 |
+
border-color: #3b82f6;
|
728 |
+
}
|
729 |
+
|
730 |
+
.code-actions {
|
731 |
+
background: #f8fafc;
|
732 |
+
border-radius: 8px;
|
733 |
+
padding: 12px;
|
734 |
+
border: 1px solid #e5e7eb;
|
735 |
+
}
|
736 |
+
|
737 |
+
.preview-sandbox {
|
738 |
+
border: 2px solid #e5e7eb;
|
739 |
+
border-radius: 8px;
|
740 |
+
overflow: hidden;
|
741 |
+
}
|
742 |
+
|
743 |
+
.chat-input {
|
744 |
+
border-radius: 20px;
|
745 |
+
border: 2px solid #e5e7eb;
|
746 |
+
}
|
747 |
+
|
748 |
+
.main-chatbot {
|
749 |
+
border: 1px solid #e5e7eb;
|
750 |
+
border-radius: 12px;
|
751 |
+
background: #fafafa;
|
752 |
+
}
|
753 |
+
|
754 |
+
.media-toggle {
|
755 |
+
color: #374151;
|
756 |
+
font-weight: 500;
|
757 |
+
}
|
758 |
+
|
759 |
+
.media-prompt {
|
760 |
+
border-radius: 6px;
|
761 |
+
border: 1px solid #d1d5db;
|
762 |
+
}
|
763 |
+
|
764 |
+
.quick-action {
|
765 |
+
background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
|
766 |
+
border: 1px solid #d1d5db;
|
767 |
+
border-radius: 6px;
|
768 |
+
font-size: 12px;
|
769 |
+
transition: all 0.2s ease;
|
770 |
+
}
|
771 |
+
|
772 |
+
.quick-action:hover {
|
773 |
+
background: linear-gradient(135deg, #e5e7eb 0%, #d1d5db 100%);
|
774 |
+
transform: translateY(-1px);
|
775 |
+
}
|
776 |
+
|
777 |
+
.feature-toggle {
|
778 |
+
font-size: 13px;
|
779 |
+
color: #6b7280;
|
780 |
+
}
|
781 |
+
|
782 |
+
.stats-display {
|
783 |
+
font-size: 11px;
|
784 |
+
background: #f9fafb;
|
785 |
+
border-radius: 4px;
|
786 |
+
padding: 8px;
|
787 |
+
}
|
788 |
+
|
789 |
+
.preview-metrics {
|
790 |
+
font-size: 10px;
|
791 |
+
color: #6b7280;
|
792 |
+
}
|
793 |
+
|
794 |
+
.category-header {
|
795 |
+
color: #374151;
|
796 |
+
font-weight: 600;
|
797 |
+
margin: 8px 0;
|
798 |
+
padding-bottom: 4px;
|
799 |
+
border-bottom: 1px solid #e5e7eb;
|
800 |
+
}
|
801 |
+
|
802 |
+
.deploy-button {
|
803 |
+
background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
|
804 |
+
color: white;
|
805 |
+
font-weight: 600;
|
806 |
+
}
|
807 |
+
|
808 |
+
.beta-toggle {
|
809 |
+
background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
|
810 |
+
color: white;
|
811 |
+
padding: 4px 8px;
|
812 |
+
border-radius: 6px;
|
813 |
+
font-size: 12px;
|
814 |
+
}
|
815 |
+
"""
|
816 |
+
|
817 |
+
@staticmethod
|
818 |
+
def apply_theme_updates(theme_name: str) -> Dict[str, Any]:
|
819 |
+
"""Apply theme and return UI updates"""
|
820 |
+
if theme_name in THEME_CONFIGS:
|
821 |
+
save_theme_preference(theme_name)
|
822 |
+
|
823 |
+
restart_message = f"""
|
824 |
+
🎨 **Theme Applied:** {theme_name}
|
825 |
+
|
826 |
+
**{THEME_CONFIGS[theme_name]['description']}**
|
827 |
+
|
828 |
+
Your theme preference has been saved. Some advanced styling may require a restart to fully apply.
|
829 |
+
"""
|
830 |
+
|
831 |
+
return {
|
832 |
+
'theme_status': gr.update(value=restart_message, visible=True),
|
833 |
+
'current_theme': theme_name
|
834 |
+
}
|
835 |
+
|
836 |
+
return {'theme_status': gr.update(visible=False), 'current_theme': theme_name}
|
837 |
+
|
838 |
+
class DeploymentManager:
|
839 |
+
"""Manages application deployment to various platforms"""
|
840 |
+
|
841 |
+
@staticmethod
|
842 |
+
def create_deployment_options() -> Dict[str, Any]:
|
843 |
+
"""Create deployment options for different platforms"""
|
844 |
+
platforms = {
|
845 |
+
'huggingface': {
|
846 |
+
'name': 'HuggingFace Spaces',
|
847 |
+
'icon': '🤗',
|
848 |
+
'description': 'Deploy to HuggingFace Spaces with automatic hosting',
|
849 |
+
'sdks': ['Static', 'Gradio', 'Streamlit', 'Docker']
|
850 |
+
},
|
851 |
+
'netlify': {
|
852 |
+
'name': 'Netlify',
|
853 |
+
'icon': '🌐',
|
854 |
+
'description': 'Deploy static sites with continuous deployment',
|
855 |
+
'sdks': ['Static']
|
856 |
+
},
|
857 |
+
'vercel': {
|
858 |
+
'name': 'Vercel',
|
859 |
+
'icon': '▲',
|
860 |
+
'description': 'Deploy with edge functions and optimized performance',
|
861 |
+
'sdks': ['Static', 'Next.js']
|
862 |
+
}
|
863 |
+
}
|
864 |
+
|
865 |
+
return platforms
|
866 |
+
|
867 |
+
@staticmethod
|
868 |
+
def prepare_deployment_files(code: str, language: str, framework: str) -> Dict[str, str]:
|
869 |
+
"""Prepare files for deployment based on the framework"""
|
870 |
+
files = {}
|
871 |
+
|
872 |
+
if language == "transformers.js":
|
873 |
+
# Parse and prepare transformers.js files
|
874 |
+
parsed_files = parse_transformers_js_output(code)
|
875 |
+
files.update(parsed_files)
|
876 |
+
|
877 |
+
elif language == "svelte":
|
878 |
+
# Parse and prepare Svelte files
|
879 |
+
parsed_files = parse_svelte_output(code)
|
880 |
+
files.update(parsed_files)
|
881 |
+
|
882 |
+
elif language == "html":
|
883 |
+
# Handle multi-page or single HTML
|
884 |
+
parsed_files = parse_multipage_html_output(code)
|
885 |
+
if parsed_files:
|
886 |
+
files.update(validate_and_autofix_files(parsed_files))
|
887 |
+
else:
|
888 |
+
files['index.html'] = code
|
889 |
+
|
890 |
+
else:
|
891 |
+
# Single file deployment
|
892 |
+
extension_map = {
|
893 |
+
'python': '.py',
|
894 |
+
'javascript': '.js',
|
895 |
+
'typescript': '.ts',
|
896 |
+
'css': '.css'
|
897 |
+
}
|
898 |
+
|
899 |
+
filename = f"app{extension_map.get(language, '.txt')}"
|
900 |
+
files[filename] = code
|
901 |
+
|
902 |
+
return files
|
903 |
+
|
904 |
+
# Global UI manager instance
|
905 |
+
ui_manager = AdvancedUIManager()
|
906 |
+
theme_manager = ThemeManager()
|
907 |
+
deployment_manager = DeploymentManager()
|