Update constants.py
Browse files- constants.py +34 -106
constants.py
CHANGED
@@ -21,11 +21,28 @@ import urllib.parse
|
|
21 |
|
22 |
import gradio as gr
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
# Gradio supported languages for syntax highlighting
|
25 |
GRADIO_SUPPORTED_LANGUAGES = [
|
26 |
-
"python", "c", "cpp", "markdown", "latex", "json", "html", "css", "javascript",
|
|
|
|
|
|
|
27 |
]
|
28 |
|
|
|
29 |
def get_gradio_language(language):
|
30 |
return language if language in GRADIO_SUPPORTED_LANGUAGES else None
|
31 |
|
@@ -34,114 +51,25 @@ SEARCH_START = "<<<<<<< SEARCH"
|
|
34 |
DIVIDER = "======="
|
35 |
REPLACE_END = ">>>>>>> REPLACE"
|
36 |
|
37 |
-
#
|
38 |
-
HTML_SYSTEM_PROMPT = """ONLY USE HTML, CSS AND JAVASCRIPT.
|
39 |
-
For website redesign tasks:
|
40 |
-
- Use the provided original HTML code as the starting point for redesign
|
41 |
-
- Preserve all original content, structure, and functionality
|
42 |
-
- Keep the same semantic HTML structure but enhance the styling
|
43 |
-
- Reuse all original images and their URLs from the HTML code
|
44 |
-
- Create a modern, responsive design with improved typography and spacing
|
45 |
-
- Use modern CSS frameworks and design patterns
|
46 |
-
- Ensure accessibility and mobile responsiveness
|
47 |
-
- Maintain the same navigation and user flow
|
48 |
-
- Enhance the visual design while keeping the original layout structure
|
49 |
-
If an image is provided, analyze it and use the visual information to better understand the user's requirements.
|
50 |
-
Always respond with code that can be executed or rendered directly.
|
51 |
-
Always output only the HTML code inside a ```html ... ``` code block, and do not include any explanations or extra text. Do NOT add the language name at the top of the code output."""
|
52 |
|
53 |
-
TRANSFORMERS_JS_SYSTEM_PROMPT = """You are an expert web developer creating a transformers.js application.
|
54 |
-
IMPORTANT: You MUST output ALL THREE files in the following format:
|
55 |
-
```html
|
56 |
-
<!-- index.html content here -->
|
57 |
-
```
|
58 |
-
```javascript
|
59 |
-
// index.js content here
|
60 |
-
```
|
61 |
-
```css
|
62 |
-
/* style.css content here */
|
63 |
-
```
|
64 |
-
Requirements:
|
65 |
-
1. Create a modern, responsive web application using transformers.js
|
66 |
-
2. Use the transformers.js library for AI/ML functionality
|
67 |
-
3. Create a clean, professional UI with good user experience
|
68 |
-
4. Make the application fully responsive for mobile devices
|
69 |
-
5. Use modern CSS practices and JavaScript ES6+ features
|
70 |
-
6. Include proper error handling and loading states
|
71 |
-
7. Follow accessibility best practices
|
72 |
-
The index.html should contain the basic HTML structure and link to the CSS and JS files.
|
73 |
-
The index.js should contain all the JavaScript logic including transformers.js integration.
|
74 |
-
The style.css should contain all the styling for the application.
|
75 |
-
Always output only the three code blocks as shown above, and do not include any explanations or extra text."""
|
76 |
|
77 |
# Available HF models for code generation
|
78 |
AVAILABLE_MODELS = [
|
79 |
-
{
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
},
|
84 |
-
{
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
},
|
89 |
-
{
|
90 |
-
"name": "DeepSeek R1",
|
91 |
-
"id": "deepseek-ai/DeepSeek-R1-0528",
|
92 |
-
"description": "DeepSeek R1 model for code generation"
|
93 |
-
},
|
94 |
-
{
|
95 |
-
"name": "ERNIE-4.5-VL",
|
96 |
-
"id": "baidu/ERNIE-4.5-VL-424B-A47B-Base-PT",
|
97 |
-
"description": "ERNIE-4.5-VL model for multimodal code generation with image support"
|
98 |
-
},
|
99 |
-
{
|
100 |
-
"name": "MiniMax M1",
|
101 |
-
"id": "MiniMaxAI/MiniMax-M1-80k",
|
102 |
-
"description": "MiniMax M1 model for code generation and general tasks"
|
103 |
-
},
|
104 |
-
{
|
105 |
-
"name": "Qwen3-235B-A22B",
|
106 |
-
"id": "Qwen/Qwen3-235B-A22B",
|
107 |
-
"description": "Qwen3-235B-A22B model for code generation and general tasks"
|
108 |
-
},
|
109 |
-
{
|
110 |
-
"name": "SmolLM3-3B",
|
111 |
-
"id": "HuggingFaceTB/SmolLM3-3B",
|
112 |
-
"description": "SmolLM3-3B model for code generation and general tasks"
|
113 |
-
},
|
114 |
-
{
|
115 |
-
"name": "GLM-4.1V-9B-Thinking",
|
116 |
-
"id": "THUDM/GLM-4.1V-9B-Thinking",
|
117 |
-
"description": "GLM-4.1V-9B-Thinking model for multimodal code generation with image support"
|
118 |
-
},
|
119 |
-
{
|
120 |
-
"name": "Qwen3-235B-A22B-Instruct-2507",
|
121 |
-
"id": "Qwen/Qwen3-235B-A22B-Instruct-2507",
|
122 |
-
"description": "Qwen3-235B-A22B-Instruct-2507 model for code generation and general tasks"
|
123 |
-
},
|
124 |
-
{
|
125 |
-
"name": "Qwen3-Coder-480B-A35B",
|
126 |
-
"id": "Qwen/Qwen3-Coder-480B-A35B-Instruct",
|
127 |
-
"description": "Qwen3-Coder-480B-A35B-Instruct model for advanced code generation and programming tasks"
|
128 |
-
}
|
129 |
]
|
130 |
|
131 |
-
# Quick‑start demo list
|
132 |
-
DEMO_LIST = [
|
133 |
-
{"title": "Todo App", "description": "Create a simple todo application with add, delete, and mark as complete functionality"},
|
134 |
-
{"title": "Calculator", "description": "Build a basic calculator with addition, subtraction, multiplication, and division"},
|
135 |
-
{"title": "Chat Interface", "description": "Build a chat interface with message history and user input"},
|
136 |
-
{"title": "E-commerce Product Card", "description": "Create a product card component for an e-commerce website"},
|
137 |
-
{"title": "Login Form", "description": "Build a responsive login form with validation"},
|
138 |
-
{"title": "Dashboard Layout", "description": "Create a dashboard layout with sidebar navigation and main content area"},
|
139 |
-
{"title": "Data Table", "description": "Build a data table with sorting and filtering capabilities"},
|
140 |
-
{"title": "Image Gallery", "description": "Create an image gallery with lightbox functionality and responsive grid layout"},
|
141 |
-
{"title": "UI from Image", "description": "Upload an image of a UI design and I'll generate the HTML/CSS code for it"},
|
142 |
-
{"title": "Extract Text from Image", "description": "Upload an image containing text and I'll extract and process the text content"},
|
143 |
-
{"title": "Website Redesign", "description": "Enter a website URL to extract its content and redesign it with a modern, responsive layout"},
|
144 |
-
{"title": "Modify HTML", "description": "After generating HTML, ask me to modify it with specific changes using search/replace format"},
|
145 |
-
{"title": "Search/Replace Example", "description": "Generate HTML first, then ask: 'Change the title to My New Title' or 'Add a blue background to the body'"},
|
146 |
-
{"title": "Transformers.js App", "description": "Create a transformers.js application with AI/ML functionality using the transformers.js library"}
|
147 |
-
]
|
|
|
21 |
|
22 |
import gradio as gr
|
23 |
|
24 |
+
# Load API keys from environment
|
25 |
+
HF_TOKEN = os.getenv("HF_TOKEN")
|
26 |
+
if not HF_TOKEN:
|
27 |
+
raise RuntimeError("HF_TOKEN environment variable is not set. Please set it to your Hugging Face API token.")
|
28 |
+
|
29 |
+
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
30 |
+
if not OPENAI_API_KEY:
|
31 |
+
print("Warning: OPENAI_API_KEY not set; OpenAI provider will be unavailable.")
|
32 |
+
|
33 |
+
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
|
34 |
+
if not GEMINI_API_KEY:
|
35 |
+
print("Warning: GEMINI_API_KEY not set; Gemini provider will be unavailable.")
|
36 |
+
|
37 |
# Gradio supported languages for syntax highlighting
|
38 |
GRADIO_SUPPORTED_LANGUAGES = [
|
39 |
+
"python", "c", "cpp", "markdown", "latex", "json", "html", "css", "javascript",
|
40 |
+
"jinja2", "typescript", "yaml", "dockerfile", "shell", "r", "sql", "sql-msSQL",
|
41 |
+
"sql-mySQL", "sql-mariaDB", "sql-sqlite", "sql-cassandra", "sql-plSQL", "sql-hive",
|
42 |
+
"sql-pgSQL", "sql-gql", "sql-gpSQL", "sql-sparkSQL", "sql-esper", None
|
43 |
]
|
44 |
|
45 |
+
|
46 |
def get_gradio_language(language):
|
47 |
return language if language in GRADIO_SUPPORTED_LANGUAGES else None
|
48 |
|
|
|
51 |
DIVIDER = "======="
|
52 |
REPLACE_END = ">>>>>>> REPLACE"
|
53 |
|
54 |
+
# System prompts
|
55 |
+
HTML_SYSTEM_PROMPT = """ONLY USE HTML, CSS AND JAVASCRIPT. ... Always output only the HTML code inside a ```html ... ``` code block."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
+
TRANSFORMERS_JS_SYSTEM_PROMPT = """You are an expert web developer creating a transformers.js application. ... Always output only the three code blocks as shown above, and do not include any explanations or extra text."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
# Available HF models for code generation
|
60 |
AVAILABLE_MODELS = [
|
61 |
+
{"name": "Moonshot Kimi-K2", "id": "moonshotai/Kimi-K2-Instruct", "description": "Moonshot AI Kimi-K2-Instruct model"},
|
62 |
+
{"name": "DeepSeek V3", "id": "deepseek-ai/DeepSeek-V3-0324", "description": "DeepSeek V3 model"},
|
63 |
+
{"name": "DeepSeek R1", "id": "deepseek-ai/DeepSeek-R1-0528", "description": "DeepSeek R1 model"},
|
64 |
+
{"name": "ERNIE-4.5-VL", "id": "baidu/ERNIE-4.5-VL-424B-A47B-Base-PT", "description": "ERNIE-4.5-VL model"},
|
65 |
+
{"name": "MiniMax M1", "id": "MiniMaxAI/MiniMax-M1-80k", "description": "MiniMax M1 model"},
|
66 |
+
{"name": "Qwen3-235B-A22B", "id": "Qwen/Qwen3-235B-A22B", "description": "Qwen3-235B-A22B model"},
|
67 |
+
{"name": "SmolLM3-3B", "id": "HuggingFaceTB/SmolLM3-3B", "description": "SmolLM3-3B model"},
|
68 |
+
{"name": "GLM-4.1V-9B-Thinking", "id": "THUDM/GLM-4.1V-9B-Thinking", "description": "GLM-4.1V-9B-Thinking model"},
|
69 |
+
{"name": "OpenAI GPT-4", "id": "openai/gpt-4", "description": "OpenAI GPT-4 model"},
|
70 |
+
{"name": "Gemini Pro", "id": "gemini/pro", "description": "Google Gemini Pro model"},
|
71 |
+
{"name": "Fireworks AI", "id": "fireworks-ai/fireworks-v1", "description": "Fireworks AI model"},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
]
|
73 |
|
74 |
+
# Quick‑start demo list
|
75 |
+
DEMO_LIST = [ ... ]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|