File size: 11,426 Bytes
42482a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
import os
import gradio as gr
from typing import Dict, List

# Environment Variables
HF_TOKEN = os.getenv('HF_TOKEN')
TAVILY_API_KEY = os.getenv('TAVILY_API_KEY')

# Search/Replace Constants
SEARCH_START = "<<<<<<< SEARCH"
DIVIDER = "======="
REPLACE_END = ">>>>>>> REPLACE"

# Gradio supported languages for syntax highlighting
GRADIO_SUPPORTED_LANGUAGES = [
    "python", "c", "cpp", "markdown", "latex", "json", "html", "css", 
    "javascript", "jinja2", "typescript", "yaml", "dockerfile", "shell", 
    "r", "sql", "sql-msSQL", "sql-mySQL", "sql-mariaDB", "sql-sqlite", 
    "sql-cassandra", "sql-plSQL", "sql-hive", "sql-pgSQL", "sql-gql", 
    "sql-gpSQL", "sql-sparkSQL", "sql-esper", None
]

# Available Models Configuration
AVAILABLE_MODELS = [
    {
        "name": "Moonshot Kimi-K2",
        "id": "moonshotai/Kimi-K2-Instruct",
        "description": "Moonshot AI Kimi-K2-Instruct model for code generation and general tasks",
        "category": "General",
        "supports_vision": False
    },
    {
        "name": "Kimi K2 Turbo (Preview)",
        "id": "kimi-k2-turbo-preview",
        "description": "Moonshot AI Kimi K2 Turbo via OpenAI-compatible API",
        "category": "General",
        "supports_vision": False
    },
    {
        "name": "DeepSeek V3",
        "id": "deepseek-ai/DeepSeek-V3-0324",
        "description": "DeepSeek V3 model for code generation",
        "category": "Code Specialist",
        "supports_vision": False
    },
    {
        "name": "DeepSeek V3.1",
        "id": "deepseek-ai/DeepSeek-V3.1",
        "description": "DeepSeek V3.1 model for code generation and general tasks",
        "category": "Code Specialist",
        "supports_vision": False
    },
    {
        "name": "DeepSeek R1",
        "id": "deepseek-ai/DeepSeek-R1-0528",
        "description": "DeepSeek R1 model for code generation",
        "category": "Code Specialist",
        "supports_vision": False
    },
    {
        "name": "ERNIE-4.5-VL",
        "id": "baidu/ERNIE-4.5-VL-424B-A47B-Base-PT",
        "description": "ERNIE-4.5-VL model for multimodal code generation with image support",
        "category": "Vision-Language",
        "supports_vision": True
    },
    {
        "name": "GLM-4.5V",
        "id": "zai-org/GLM-4.5V",
        "description": "GLM-4.5V multimodal model with image understanding for code generation",
        "category": "Vision-Language",
        "supports_vision": True
    },
    {
        "name": "Qwen3-Coder-480B-A35B-Instruct",
        "id": "Qwen/Qwen3-Coder-480B-A35B-Instruct",
        "description": "Qwen3-Coder-480B-A35B-Instruct model for advanced code generation and programming tasks",
        "category": "Code Specialist",
        "supports_vision": False
    },
    {
        "name": "GPT-5",
        "id": "gpt-5",
        "description": "OpenAI GPT-5 model for advanced code generation and general tasks",
        "category": "Premium",
        "supports_vision": False
    },
    {
        "name": "Claude-Opus-4.1",
        "id": "claude-opus-4.1",
        "description": "Anthropic Claude Opus 4.1 via Poe (OpenAI-compatible)",
        "category": "Premium",
        "supports_vision": False
    }
]

DEFAULT_MODEL_NAME = "Qwen3-Coder-480B-A35B-Instruct"
DEFAULT_MODEL = next((m for m in AVAILABLE_MODELS if m.get("name") == DEFAULT_MODEL_NAME), AVAILABLE_MODELS[0])

# System Prompts
HTML_SYSTEM_PROMPT = """You are an expert front-end developer creating modern, responsive web applications.

Output a COMPLETE, STANDALONE HTML document that renders directly in a browser.

Requirements:
- Include <!DOCTYPE html>, <html>, <head>, and <body> with proper nesting
- Include all required <link> and <script> tags for any libraries you use
- Use modern CSS frameworks (Tailwind CSS, Bootstrap) or custom CSS
- Ensure mobile-first responsive design
- Include proper semantic HTML structure
- Add accessibility features (ARIA labels, alt text, proper contrast)
- Use modern JavaScript ES6+ features
- Keep everything in ONE file; inline CSS/JS as needed

For website redesign tasks:
- Preserve all original content, structure, and functionality
- Keep the same semantic HTML structure but enhance the styling
- Reuse all original images and their URLs from the HTML code
- Create a modern, responsive design with improved typography and spacing
- Maintain the same navigation and user flow
- Enhance the visual design while keeping the original layout structure

Always output only the HTML code inside a ```html ... ``` code block.
"""

TRANSFORMERS_JS_SYSTEM_PROMPT = """You are an expert web developer creating transformers.js applications.

Generate THREE separate files: index.html, index.js, and style.css.

IMPORTANT: You MUST output ALL THREE files in the following format:

```html
<!-- index.html content here -->
```

```javascript
// index.js content here
```

```css
/* style.css content here */
```

Requirements:
1. Create a modern, responsive web application using transformers.js
2. Use the transformers.js library for AI/ML functionality
3. Create a clean, professional UI with good user experience
4. Make the application fully responsive for mobile devices
5. Use modern CSS practices and JavaScript ES6+ features
6. Include proper error handling and loading states
7. Follow accessibility best practices

Library import (required): Add the following to index.html:
<script type="module">
    import { pipeline } from 'https://cdn.jsdelivr.net/npm/@huggingface/[email protected]';
</script>
"""

SVELTE_SYSTEM_PROMPT = """You are an expert Svelte developer creating modern Svelte applications.

Generate ONLY the custom files that need user-specific content:

```svelte
<!-- src/App.svelte content here -->
```

```css
/* src/app.css content here */
```

Requirements:
1. Create a modern, responsive Svelte application
2. Use TypeScript for better type safety
3. Create a clean, professional UI with excellent UX
4. Make the application fully responsive
5. Use modern CSS practices and Svelte best practices
6. Include proper error handling and loading states
7. Follow accessibility best practices
8. Use Svelte's reactive features effectively
"""

GENERIC_SYSTEM_PROMPT = """You are an expert {language} developer. Write clean, idiomatic, and runnable {language} code for the user's request.

Requirements:
- Write production-ready, well-structured code
- Include comprehensive error handling
- Add clear comments and documentation
- Follow language-specific best practices
- Make code modular and maintainable
- Include type hints where applicable
- Optimize for performance and readability

Output ONLY the code inside a ``` code block.
"""

# Theme Configurations
THEME_CONFIGS = {
    "Professional Dark": {
        "theme": gr.themes.Base(
            primary_hue="blue",
            secondary_hue="slate",
            neutral_hue="slate",
            text_size="sm",
            spacing_size="sm",
            radius_size="md"
        ).set(
            body_background_fill="#0f172a",
            body_background_fill_dark="#0f172a",
            background_fill_primary="#3b82f6",
            background_fill_secondary="#1e293b",
            border_color_primary="#334155",
            block_background_fill="#1e293b",
            block_border_color="#334155",
            body_text_color="#f1f5f9",
            body_text_color_dark="#f1f5f9",
            block_label_text_color="#f1f5f9",
            input_background_fill="#0f172a",
            input_border_color="#334155",
            button_primary_background_fill="#3b82f6",
            button_primary_border_color="#3b82f6",
            button_secondary_background_fill="#334155"
        ),
        "description": "Professional dark theme optimized for developers"
    },
    "Modern Light": {
        "theme": gr.themes.Soft(
            primary_hue="blue",
            secondary_hue="slate",
            neutral_hue="slate",
            text_size="sm",
            spacing_size="md",
            radius_size="lg"
        ).set(
            body_background_fill="#ffffff",
            background_fill_primary="#3b82f6",
            background_fill_secondary="#f8fafc",
            border_color_primary="#e2e8f0",
            block_background_fill="#ffffff",
            block_border_color="#e2e8f0",
            body_text_color="#1e293b",
            button_primary_background_fill="#3b82f6"
        ),
        "description": "Clean, modern light theme with professional styling"
    }
}

# Demo Examples
DEMO_LIST = [
    {
        "title": "Interactive Dashboard",
        "description": "Create a comprehensive analytics dashboard with charts, metrics, and real-time data visualization",
        "category": "Data & Analytics",
        "complexity": "Advanced"
    },
    {
        "title": "AI Chat Interface",
        "description": "Build a modern chat interface with message history, typing indicators, and file sharing",
        "category": "AI & ML",
        "complexity": "Intermediate"
    },
    {
        "title": "E-commerce Platform",
        "description": "Design a complete e-commerce solution with product catalog, shopping cart, and checkout",
        "category": "E-commerce",
        "complexity": "Advanced"
    },
    {
        "title": "Task Management App",
        "description": "Create a Kanban-style task manager with drag-and-drop, categories, and progress tracking",
        "category": "Productivity",
        "complexity": "Intermediate"
    },
    {
        "title": "Social Media Feed",
        "description": "Build a responsive social media feed with posts, comments, likes, and infinite scroll",
        "category": "Social",
        "complexity": "Intermediate"
    },
    {
        "title": "Data Visualization Suite",
        "description": "Create interactive charts and graphs with real-time data updates and export features",
        "category": "Data & Analytics",
        "complexity": "Advanced"
    },
    {
        "title": "Portfolio Website",
        "description": "Design a professional portfolio with project showcase, skills, and contact sections",
        "category": "Portfolio",
        "complexity": "Beginner"
    },
    {
        "title": "Form Builder",
        "description": "Build a dynamic form builder with validation, conditional logic, and submission handling",
        "category": "Forms",
        "complexity": "Advanced"
    }
]

# File handling constants
TEMP_DIR_TTL_SECONDS = 6 * 60 * 60  # 6 hours
MAX_FILE_SIZE_MB = 10
SUPPORTED_FILE_TYPES = [
    ".pdf", ".txt", ".md", ".csv", ".docx", 
    ".jpg", ".jpeg", ".png", ".bmp", ".tiff", ".tif", ".gif", ".webp"
]

def get_gradio_language(language):
    """Map composite options to supported syntax highlighting"""
    language_map = {
        "streamlit": "python",
        "gradio": "python",
        "transformers.js": "javascript"
    }
    return language_map.get(language, language if language in GRADIO_SUPPORTED_LANGUAGES else None)

def get_saved_theme():
    """Get the saved theme preference from file"""
    try:
        if os.path.exists('.theme_preference'):
            with open('.theme_preference', 'r') as f:
                return f.read().strip()
    except:
        pass
    return "Professional Dark"

def save_theme_preference(theme_name):
    """Save theme preference to file"""
    try:
        with open('.theme_preference', 'w') as f:
            f.write(theme_name)
    except:
        pass