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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
Configuration constants, models, themes, and system prompts for AnyCoder.
|
3 |
+
"""
|
4 |
+
|
5 |
+
import os
|
6 |
+
import gradio as gr
|
7 |
+
from typing import Dict, List
|
8 |
+
|
9 |
+
# Environment Variables
|
10 |
+
HF_TOKEN = os.getenv('HF_TOKEN')
|
11 |
+
TAVILY_API_KEY = os.getenv('TAVILY_API_KEY')
|
12 |
+
|
13 |
+
# Search/Replace Constants
|
14 |
+
SEARCH_START = "<<<<<<< SEARCH"
|
15 |
+
DIVIDER = "======="
|
16 |
+
REPLACE_END = ">>>>>>> REPLACE"
|
17 |
+
|
18 |
+
# Gradio supported languages for syntax highlighting
|
19 |
+
GRADIO_SUPPORTED_LANGUAGES = [
|
20 |
+
"python", "c", "cpp", "markdown", "latex", "json", "html", "css",
|
21 |
+
"javascript", "jinja2", "typescript", "yaml", "dockerfile", "shell",
|
22 |
+
"r", "sql", "sql-msSQL", "sql-mySQL", "sql-mariaDB", "sql-sqlite",
|
23 |
+
"sql-cassandra", "sql-plSQL", "sql-hive", "sql-pgSQL", "sql-gql",
|
24 |
+
"sql-gpSQL", "sql-sparkSQL", "sql-esper", None
|
25 |
+
]
|
26 |
+
|
27 |
+
# Available Models Configuration
|
28 |
+
AVAILABLE_MODELS = [
|
29 |
+
{
|
30 |
+
"name": "Moonshot Kimi-K2",
|
31 |
+
"id": "moonshotai/Kimi-K2-Instruct",
|
32 |
+
"description": "Moonshot AI Kimi-K2-Instruct model for code generation and general tasks",
|
33 |
+
"category": "General",
|
34 |
+
"supports_vision": False
|
35 |
+
},
|
36 |
+
{
|
37 |
+
"name": "Kimi K2 Turbo (Preview)",
|
38 |
+
"id": "kimi-k2-turbo-preview",
|
39 |
+
"description": "Moonshot AI Kimi K2 Turbo via OpenAI-compatible API",
|
40 |
+
"category": "General",
|
41 |
+
"supports_vision": False
|
42 |
+
},
|
43 |
+
{
|
44 |
+
"name": "DeepSeek V3",
|
45 |
+
"id": "deepseek-ai/DeepSeek-V3-0324",
|
46 |
+
"description": "DeepSeek V3 model for code generation",
|
47 |
+
"category": "Code Specialist",
|
48 |
+
"supports_vision": False
|
49 |
+
},
|
50 |
+
{
|
51 |
+
"name": "DeepSeek V3.1",
|
52 |
+
"id": "deepseek-ai/DeepSeek-V3.1",
|
53 |
+
"description": "DeepSeek V3.1 model for code generation and general tasks",
|
54 |
+
"category": "Code Specialist",
|
55 |
+
"supports_vision": False
|
56 |
+
},
|
57 |
+
{
|
58 |
+
"name": "DeepSeek R1",
|
59 |
+
"id": "deepseek-ai/DeepSeek-R1-0528",
|
60 |
+
"description": "DeepSeek R1 model for code generation",
|
61 |
+
"category": "Code Specialist",
|
62 |
+
"supports_vision": False
|
63 |
+
},
|
64 |
+
{
|
65 |
+
"name": "ERNIE-4.5-VL",
|
66 |
+
"id": "baidu/ERNIE-4.5-VL-424B-A47B-Base-PT",
|
67 |
+
"description": "ERNIE-4.5-VL model for multimodal code generation with image support",
|
68 |
+
"category": "Vision-Language",
|
69 |
+
"supports_vision": True
|
70 |
+
},
|
71 |
+
{
|
72 |
+
"name": "GLM-4.5V",
|
73 |
+
"id": "zai-org/GLM-4.5V",
|
74 |
+
"description": "GLM-4.5V multimodal model with image understanding for code generation",
|
75 |
+
"category": "Vision-Language",
|
76 |
+
"supports_vision": True
|
77 |
+
},
|
78 |
+
{
|
79 |
+
"name": "Qwen3-Coder-480B-A35B-Instruct",
|
80 |
+
"id": "Qwen/Qwen3-Coder-480B-A35B-Instruct",
|
81 |
+
"description": "Qwen3-Coder-480B-A35B-Instruct model for advanced code generation and programming tasks",
|
82 |
+
"category": "Code Specialist",
|
83 |
+
"supports_vision": False
|
84 |
+
},
|
85 |
+
{
|
86 |
+
"name": "GPT-5",
|
87 |
+
"id": "gpt-5",
|
88 |
+
"description": "OpenAI GPT-5 model for advanced code generation and general tasks",
|
89 |
+
"category": "Premium",
|
90 |
+
"supports_vision": False
|
91 |
+
},
|
92 |
+
{
|
93 |
+
"name": "Claude-Opus-4.1",
|
94 |
+
"id": "claude-opus-4.1",
|
95 |
+
"description": "Anthropic Claude Opus 4.1 via Poe (OpenAI-compatible)",
|
96 |
+
"category": "Premium",
|
97 |
+
"supports_vision": False
|
98 |
+
}
|
99 |
+
]
|
100 |
+
|
101 |
+
DEFAULT_MODEL_NAME = "Qwen3-Coder-480B-A35B-Instruct"
|
102 |
+
DEFAULT_MODEL = next((m for m in AVAILABLE_MODELS if m.get("name") == DEFAULT_MODEL_NAME), AVAILABLE_MODELS[0])
|
103 |
+
|
104 |
+
# System Prompts
|
105 |
+
HTML_SYSTEM_PROMPT = """You are an expert front-end developer creating modern, responsive web applications.
|
106 |
+
|
107 |
+
Output a COMPLETE, STANDALONE HTML document that renders directly in a browser.
|
108 |
+
|
109 |
+
Requirements:
|
110 |
+
- Include <!DOCTYPE html>, <html>, <head>, and <body> with proper nesting
|
111 |
+
- Include all required <link> and <script> tags for any libraries you use
|
112 |
+
- Use modern CSS frameworks (Tailwind CSS, Bootstrap) or custom CSS
|
113 |
+
- Ensure mobile-first responsive design
|
114 |
+
- Include proper semantic HTML structure
|
115 |
+
- Add accessibility features (ARIA labels, alt text, proper contrast)
|
116 |
+
- Use modern JavaScript ES6+ features
|
117 |
+
- Keep everything in ONE file; inline CSS/JS as needed
|
118 |
+
|
119 |
+
For website redesign tasks:
|
120 |
+
- Preserve all original content, structure, and functionality
|
121 |
+
- Keep the same semantic HTML structure but enhance the styling
|
122 |
+
- Reuse all original images and their URLs from the HTML code
|
123 |
+
- Create a modern, responsive design with improved typography and spacing
|
124 |
+
- Maintain the same navigation and user flow
|
125 |
+
- Enhance the visual design while keeping the original layout structure
|
126 |
+
|
127 |
+
Always output only the HTML code inside a ```html ... ``` code block.
|
128 |
+
"""
|
129 |
+
|
130 |
+
TRANSFORMERS_JS_SYSTEM_PROMPT = """You are an expert web developer creating transformers.js applications.
|
131 |
+
|
132 |
+
Generate THREE separate files: index.html, index.js, and style.css.
|
133 |
+
|
134 |
+
IMPORTANT: You MUST output ALL THREE files in the following format:
|
135 |
+
|
136 |
+
```html
|
137 |
+
<!-- index.html content here -->
|
138 |
+
```
|
139 |
+
|
140 |
+
```javascript
|
141 |
+
// index.js content here
|
142 |
+
```
|
143 |
+
|
144 |
+
```css
|
145 |
+
/* style.css content here */
|
146 |
+
```
|
147 |
+
|
148 |
+
Requirements:
|
149 |
+
1. Create a modern, responsive web application using transformers.js
|
150 |
+
2. Use the transformers.js library for AI/ML functionality
|
151 |
+
3. Create a clean, professional UI with good user experience
|
152 |
+
4. Make the application fully responsive for mobile devices
|
153 |
+
5. Use modern CSS practices and JavaScript ES6+ features
|
154 |
+
6. Include proper error handling and loading states
|
155 |
+
7. Follow accessibility best practices
|
156 |
+
|
157 |
+
Library import (required): Add the following to index.html:
|
158 |
+
<script type="module">
|
159 |
+
import { pipeline } from 'https://cdn.jsdelivr.net/npm/@huggingface/[email protected]';
|
160 |
+
</script>
|
161 |
+
"""
|
162 |
+
|
163 |
+
SVELTE_SYSTEM_PROMPT = """You are an expert Svelte developer creating modern Svelte applications.
|
164 |
+
|
165 |
+
Generate ONLY the custom files that need user-specific content:
|
166 |
+
|
167 |
+
```svelte
|
168 |
+
<!-- src/App.svelte content here -->
|
169 |
+
```
|
170 |
+
|
171 |
+
```css
|
172 |
+
/* src/app.css content here */
|
173 |
+
```
|
174 |
+
|
175 |
+
Requirements:
|
176 |
+
1. Create a modern, responsive Svelte application
|
177 |
+
2. Use TypeScript for better type safety
|
178 |
+
3. Create a clean, professional UI with excellent UX
|
179 |
+
4. Make the application fully responsive
|
180 |
+
5. Use modern CSS practices and Svelte best practices
|
181 |
+
6. Include proper error handling and loading states
|
182 |
+
7. Follow accessibility best practices
|
183 |
+
8. Use Svelte's reactive features effectively
|
184 |
+
"""
|
185 |
+
|
186 |
+
GENERIC_SYSTEM_PROMPT = """You are an expert {language} developer. Write clean, idiomatic, and runnable {language} code for the user's request.
|
187 |
+
|
188 |
+
Requirements:
|
189 |
+
- Write production-ready, well-structured code
|
190 |
+
- Include comprehensive error handling
|
191 |
+
- Add clear comments and documentation
|
192 |
+
- Follow language-specific best practices
|
193 |
+
- Make code modular and maintainable
|
194 |
+
- Include type hints where applicable
|
195 |
+
- Optimize for performance and readability
|
196 |
+
|
197 |
+
Output ONLY the code inside a ``` code block.
|
198 |
+
"""
|
199 |
+
|
200 |
+
# Theme Configurations
|
201 |
+
THEME_CONFIGS = {
|
202 |
+
"Professional Dark": {
|
203 |
+
"theme": gr.themes.Base(
|
204 |
+
primary_hue="blue",
|
205 |
+
secondary_hue="slate",
|
206 |
+
neutral_hue="slate",
|
207 |
+
text_size="sm",
|
208 |
+
spacing_size="sm",
|
209 |
+
radius_size="md"
|
210 |
+
).set(
|
211 |
+
body_background_fill="#0f172a",
|
212 |
+
body_background_fill_dark="#0f172a",
|
213 |
+
background_fill_primary="#3b82f6",
|
214 |
+
background_fill_secondary="#1e293b",
|
215 |
+
border_color_primary="#334155",
|
216 |
+
block_background_fill="#1e293b",
|
217 |
+
block_border_color="#334155",
|
218 |
+
body_text_color="#f1f5f9",
|
219 |
+
body_text_color_dark="#f1f5f9",
|
220 |
+
block_label_text_color="#f1f5f9",
|
221 |
+
input_background_fill="#0f172a",
|
222 |
+
input_border_color="#334155",
|
223 |
+
button_primary_background_fill="#3b82f6",
|
224 |
+
button_primary_border_color="#3b82f6",
|
225 |
+
button_secondary_background_fill="#334155"
|
226 |
+
),
|
227 |
+
"description": "Professional dark theme optimized for developers"
|
228 |
+
},
|
229 |
+
"Modern Light": {
|
230 |
+
"theme": gr.themes.Soft(
|
231 |
+
primary_hue="blue",
|
232 |
+
secondary_hue="slate",
|
233 |
+
neutral_hue="slate",
|
234 |
+
text_size="sm",
|
235 |
+
spacing_size="md",
|
236 |
+
radius_size="lg"
|
237 |
+
).set(
|
238 |
+
body_background_fill="#ffffff",
|
239 |
+
background_fill_primary="#3b82f6",
|
240 |
+
background_fill_secondary="#f8fafc",
|
241 |
+
border_color_primary="#e2e8f0",
|
242 |
+
block_background_fill="#ffffff",
|
243 |
+
block_border_color="#e2e8f0",
|
244 |
+
body_text_color="#1e293b",
|
245 |
+
button_primary_background_fill="#3b82f6"
|
246 |
+
),
|
247 |
+
"description": "Clean, modern light theme with professional styling"
|
248 |
+
}
|
249 |
+
}
|
250 |
+
|
251 |
+
# Demo Examples
|
252 |
+
DEMO_LIST = [
|
253 |
+
{
|
254 |
+
"title": "Interactive Dashboard",
|
255 |
+
"description": "Create a comprehensive analytics dashboard with charts, metrics, and real-time data visualization",
|
256 |
+
"category": "Data & Analytics",
|
257 |
+
"complexity": "Advanced"
|
258 |
+
},
|
259 |
+
{
|
260 |
+
"title": "AI Chat Interface",
|
261 |
+
"description": "Build a modern chat interface with message history, typing indicators, and file sharing",
|
262 |
+
"category": "AI & ML",
|
263 |
+
"complexity": "Intermediate"
|
264 |
+
},
|
265 |
+
{
|
266 |
+
"title": "E-commerce Platform",
|
267 |
+
"description": "Design a complete e-commerce solution with product catalog, shopping cart, and checkout",
|
268 |
+
"category": "E-commerce",
|
269 |
+
"complexity": "Advanced"
|
270 |
+
},
|
271 |
+
{
|
272 |
+
"title": "Task Management App",
|
273 |
+
"description": "Create a Kanban-style task manager with drag-and-drop, categories, and progress tracking",
|
274 |
+
"category": "Productivity",
|
275 |
+
"complexity": "Intermediate"
|
276 |
+
},
|
277 |
+
{
|
278 |
+
"title": "Social Media Feed",
|
279 |
+
"description": "Build a responsive social media feed with posts, comments, likes, and infinite scroll",
|
280 |
+
"category": "Social",
|
281 |
+
"complexity": "Intermediate"
|
282 |
+
},
|
283 |
+
{
|
284 |
+
"title": "Data Visualization Suite",
|
285 |
+
"description": "Create interactive charts and graphs with real-time data updates and export features",
|
286 |
+
"category": "Data & Analytics",
|
287 |
+
"complexity": "Advanced"
|
288 |
+
},
|
289 |
+
{
|
290 |
+
"title": "Portfolio Website",
|
291 |
+
"description": "Design a professional portfolio with project showcase, skills, and contact sections",
|
292 |
+
"category": "Portfolio",
|
293 |
+
"complexity": "Beginner"
|
294 |
+
},
|
295 |
+
{
|
296 |
+
"title": "Form Builder",
|
297 |
+
"description": "Build a dynamic form builder with validation, conditional logic, and submission handling",
|
298 |
+
"category": "Forms",
|
299 |
+
"complexity": "Advanced"
|
300 |
+
}
|
301 |
+
]
|
302 |
+
|
303 |
+
# File handling constants
|
304 |
+
TEMP_DIR_TTL_SECONDS = 6 * 60 * 60 # 6 hours
|
305 |
+
MAX_FILE_SIZE_MB = 10
|
306 |
+
SUPPORTED_FILE_TYPES = [
|
307 |
+
".pdf", ".txt", ".md", ".csv", ".docx",
|
308 |
+
".jpg", ".jpeg", ".png", ".bmp", ".tiff", ".tif", ".gif", ".webp"
|
309 |
+
]
|
310 |
+
|
311 |
+
def get_gradio_language(language):
|
312 |
+
"""Map composite options to supported syntax highlighting"""
|
313 |
+
language_map = {
|
314 |
+
"streamlit": "python",
|
315 |
+
"gradio": "python",
|
316 |
+
"transformers.js": "javascript"
|
317 |
+
}
|
318 |
+
return language_map.get(language, language if language in GRADIO_SUPPORTED_LANGUAGES else None)
|
319 |
+
|
320 |
+
def get_saved_theme():
|
321 |
+
"""Get the saved theme preference from file"""
|
322 |
+
try:
|
323 |
+
if os.path.exists('.theme_preference'):
|
324 |
+
with open('.theme_preference', 'r') as f:
|
325 |
+
return f.read().strip()
|
326 |
+
except:
|
327 |
+
pass
|
328 |
+
return "Professional Dark"
|
329 |
+
|
330 |
+
def save_theme_preference(theme_name):
|
331 |
+
"""Save theme preference to file"""
|
332 |
+
try:
|
333 |
+
with open('.theme_preference', 'w') as f:
|
334 |
+
f.write(theme_name)
|
335 |
+
except:
|
336 |
+
pass
|
main.py
DELETED
@@ -1,22 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from ui_components import create_interface
|
3 |
-
from theme_config import THEME_CONFIGS, get_saved_theme
|
4 |
-
import os
|
5 |
-
from media_processing import cleanup_all_temp_media_on_startup
|
6 |
-
|
7 |
-
def main():
|
8 |
-
# Clean up any orphaned temporary files from previous runs
|
9 |
-
cleanup_all_temp_media_on_startup()
|
10 |
-
|
11 |
-
current_theme_name = get_saved_theme()
|
12 |
-
current_theme = THEME_CONFIGS[current_theme_name]["theme"]
|
13 |
-
|
14 |
-
demo = create_interface(current_theme)
|
15 |
-
demo.queue(api_open=False, default_concurrency_limit=20).launch(
|
16 |
-
show_api=False,
|
17 |
-
ssr_mode=True,
|
18 |
-
mcp_server=False
|
19 |
-
)
|
20 |
-
|
21 |
-
if __name__ == "__main__":
|
22 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|