Spaces:
Paused
Paused
Upload 4 files (#1)
Browse files- Upload 4 files (1165cb3c8fafdcd471a5f33d223df2a10deee44e)
README.md
CHANGED
@@ -1,12 +1,13 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
colorFrom: red
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 5.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
|
|
10 |
---
|
11 |
|
12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: GPT-5 Vibe Coder
|
3 |
+
emoji: 🌍
|
4 |
colorFrom: red
|
5 |
+
colorTo: blue
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 5.38.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
+
license: apache-2.0
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,443 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import re
|
2 |
+
|
3 |
+
import gradio as gr
|
4 |
+
from openai import OpenAI
|
5 |
+
from config import API_KEY, MODEL, SYSTEM_PROMPT, ENDPOINT, EXAMPLES, DEFAULT_LOCALE, DEFAULT_THEME
|
6 |
+
|
7 |
+
client = OpenAI(api_key=API_KEY, base_url=ENDPOINT)
|
8 |
+
|
9 |
+
react_imports = {
|
10 |
+
"lucide-react": "https://esm.sh/lucide-react@0.525.0",
|
11 |
+
"recharts": "https://esm.sh/recharts@3.1.0",
|
12 |
+
"framer-motion": "https://esm.sh/framer-motion@12.23.6",
|
13 |
+
"matter-js": "https://esm.sh/matter-js@0.20.0",
|
14 |
+
"p5": "https://esm.sh/p5@2.0.3",
|
15 |
+
"konva": "https://esm.sh/konva@9.3.22",
|
16 |
+
"react-konva": "https://esm.sh/react-konva@19.0.7",
|
17 |
+
"three": "https://esm.sh/three@0.178.0",
|
18 |
+
"@react-three/fiber": "https://esm.sh/@react-three/fiber@9.2.0",
|
19 |
+
"@react-three/drei": "https://esm.sh/@react-three/drei@10.5.2",
|
20 |
+
"@tailwindcss/browser": "https://esm.sh/@tailwindcss/browser@4.1.11",
|
21 |
+
"react": "https://esm.sh/react@^19.0.0",
|
22 |
+
"react/": "https://esm.sh/react@^19.0.0/",
|
23 |
+
"react-dom": "https://esm.sh/react-dom@^19.0.0",
|
24 |
+
"react-dom/": "https://esm.sh/react-dom@^19.0.0/",
|
25 |
+
"react-dom/client": "https://esm.sh/react-dom@^19.0.0/client"
|
26 |
+
}
|
27 |
+
|
28 |
+
|
29 |
+
class GradioEvents:
|
30 |
+
|
31 |
+
@staticmethod
|
32 |
+
def generate_code(input_value, system_prompt_input_value, state_value):
|
33 |
+
|
34 |
+
def get_generated_files(text):
|
35 |
+
patterns = {
|
36 |
+
'html': r'```html\n(.+?)\n```',
|
37 |
+
'jsx': r'```jsx\n(.+?)\n```',
|
38 |
+
'tsx': r'```tsx\n(.+?)\n```',
|
39 |
+
}
|
40 |
+
result = {}
|
41 |
+
|
42 |
+
for ext, pattern in patterns.items():
|
43 |
+
matches = re.findall(pattern, text, re.DOTALL)
|
44 |
+
if matches:
|
45 |
+
content = '\n'.join(matches).strip()
|
46 |
+
result[f'index.{ext}'] = content
|
47 |
+
|
48 |
+
if len(result) == 0:
|
49 |
+
result["index.html"] = text.strip()
|
50 |
+
return result
|
51 |
+
|
52 |
+
def process_react_imports(code):
|
53 |
+
"""Process React code to work with ES modules and import map"""
|
54 |
+
# Remove export default and replace with const App
|
55 |
+
processed_code = code.replace("export default", "const App =")
|
56 |
+
|
57 |
+
# Process imports to use the import map
|
58 |
+
import_lines = []
|
59 |
+
code_lines = []
|
60 |
+
|
61 |
+
for line in processed_code.split('\n'):
|
62 |
+
line = line.strip()
|
63 |
+
if line.startswith('import '):
|
64 |
+
# Extract import statement
|
65 |
+
import_lines.append(line)
|
66 |
+
else:
|
67 |
+
code_lines.append(line)
|
68 |
+
|
69 |
+
# Combine processed imports and code
|
70 |
+
if import_lines:
|
71 |
+
processed_code = '\n'.join(import_lines) + '\n\n' + '\n'.join(code_lines)
|
72 |
+
else:
|
73 |
+
processed_code = '\n'.join(code_lines)
|
74 |
+
|
75 |
+
return processed_code
|
76 |
+
|
77 |
+
yield {
|
78 |
+
empty_output: gr.update(visible=False),
|
79 |
+
loading_output: gr.update(visible=True),
|
80 |
+
sandbox: gr.update(visible=False),
|
81 |
+
output: gr.update(value=None)
|
82 |
+
}
|
83 |
+
|
84 |
+
if input_value is None:
|
85 |
+
input_value = ''
|
86 |
+
|
87 |
+
messages = [{
|
88 |
+
'role': "system",
|
89 |
+
"content": SYSTEM_PROMPT
|
90 |
+
# 'content': system_prompt_input_value
|
91 |
+
}] + state_value["history"]
|
92 |
+
|
93 |
+
messages.append({'role': "user", 'content': input_value})
|
94 |
+
|
95 |
+
generator = client.chat.completions.create(model=MODEL,
|
96 |
+
messages=messages,
|
97 |
+
stream=True)
|
98 |
+
response = ""
|
99 |
+
for chunk in generator:
|
100 |
+
content = chunk.choices[0].delta.content
|
101 |
+
if content is not None:
|
102 |
+
response += content
|
103 |
+
if chunk.choices[0].finish_reason == 'stop':
|
104 |
+
state_value["history"] = messages + [{
|
105 |
+
'role': "assistant",
|
106 |
+
'content': response
|
107 |
+
}]
|
108 |
+
generated_files = get_generated_files(response)
|
109 |
+
react_code = generated_files.get(
|
110 |
+
"index.tsx") or generated_files.get("index.jsx")
|
111 |
+
html_code = generated_files.get("index.html")
|
112 |
+
# Completed
|
113 |
+
# Create HTML content for sandbox
|
114 |
+
if react_code:
|
115 |
+
# For React code, create a complete HTML page that renders React with ES modules
|
116 |
+
processed_react_code = process_react_imports(react_code)
|
117 |
+
escaped_react_code = processed_react_code.replace("`", "`").replace("'", "'")
|
118 |
+
|
119 |
+
# Create import map from react_imports
|
120 |
+
import_map = '{\n "imports": {\n'
|
121 |
+
for package, url in react_imports.items():
|
122 |
+
import_map += f' "{package}": "{url}",\n'
|
123 |
+
import_map = import_map.rstrip(',\n') + '\n }\n }'
|
124 |
+
|
125 |
+
sandbox_content = f"""
|
126 |
+
<iframe style="width: 100%; height: 600px; border: 1px solid #ddd; border-radius: 8px;"
|
127 |
+
srcdoc='<!DOCTYPE html>
|
128 |
+
<html>
|
129 |
+
<head>
|
130 |
+
<meta charset="UTF-8">
|
131 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
132 |
+
<script type="importmap">
|
133 |
+
{import_map}
|
134 |
+
</script>
|
135 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
136 |
+
</head>
|
137 |
+
<body>
|
138 |
+
<div id="root"></div>
|
139 |
+
<script type="module">
|
140 |
+
import React from "react";
|
141 |
+
import { createRoot } from "react-dom/client";
|
142 |
+
|
143 |
+
{escaped_react_code}
|
144 |
+
|
145 |
+
const root = createRoot(document.getElementById("root"));
|
146 |
+
root.render(React.createElement(App));
|
147 |
+
</script>
|
148 |
+
</body>
|
149 |
+
</html>'>
|
150 |
+
</iframe>
|
151 |
+
"""
|
152 |
+
else:
|
153 |
+
# For HTML code, just display it in iframe
|
154 |
+
escaped_html_code = html_code.replace("'", "'")
|
155 |
+
sandbox_content = f"""
|
156 |
+
<iframe style="width: 100%; height: 600px; border: 1px solid #ddd; border-radius: 8px;"
|
157 |
+
srcdoc='{escaped_html_code}'>
|
158 |
+
</iframe>
|
159 |
+
"""
|
160 |
+
|
161 |
+
yield {
|
162 |
+
output: gr.update(value=response),
|
163 |
+
download_content: gr.update(value=react_code or html_code),
|
164 |
+
empty_output: gr.update(visible=False),
|
165 |
+
loading_output: gr.update(visible=False),
|
166 |
+
sandbox: gr.update(value=sandbox_content, visible=True),
|
167 |
+
download_btn: gr.update(interactive=True),
|
168 |
+
state: gr.update(value=state_value)
|
169 |
+
}
|
170 |
+
|
171 |
+
else:
|
172 |
+
# Generating
|
173 |
+
yield {
|
174 |
+
output: gr.update(value=response),
|
175 |
+
}
|
176 |
+
|
177 |
+
@staticmethod
|
178 |
+
def select_example(example: dict):
|
179 |
+
return lambda: gr.update(value=example["description"])
|
180 |
+
|
181 |
+
@staticmethod
|
182 |
+
def toggle_visibility(visible_state):
|
183 |
+
return gr.update(visible=not visible_state)
|
184 |
+
|
185 |
+
@staticmethod
|
186 |
+
def disable_btns(btns: list):
|
187 |
+
return lambda: [gr.update(disabled=True) for _ in btns]
|
188 |
+
|
189 |
+
@staticmethod
|
190 |
+
def enable_btns(btns: list):
|
191 |
+
return lambda: [gr.update(disabled=False) for _ in btns]
|
192 |
+
|
193 |
+
@staticmethod
|
194 |
+
def update_system_prompt(system_prompt_input_value, state_value):
|
195 |
+
state_value["system_prompt"] = system_prompt_input_value
|
196 |
+
return gr.update(value=state_value)
|
197 |
+
|
198 |
+
@staticmethod
|
199 |
+
def reset_system_prompt(state_value):
|
200 |
+
return gr.update(value=state_value["system_prompt"])
|
201 |
+
|
202 |
+
@staticmethod
|
203 |
+
def render_history(statue_value):
|
204 |
+
return gr.update(value=statue_value["history"])
|
205 |
+
|
206 |
+
@staticmethod
|
207 |
+
def clear_history(state_value):
|
208 |
+
gr.Success("History Cleared.")
|
209 |
+
state_value["history"] = []
|
210 |
+
return gr.update(value=state_value)
|
211 |
+
|
212 |
+
|
213 |
+
css = """
|
214 |
+
.output-empty, .output-loading {
|
215 |
+
display: flex;
|
216 |
+
flex-direction: column;
|
217 |
+
align-items: center;
|
218 |
+
justify-content: center;
|
219 |
+
width: 100%;
|
220 |
+
min-height: 680px;
|
221 |
+
}
|
222 |
+
|
223 |
+
.output-html {
|
224 |
+
display: flex;
|
225 |
+
flex-direction: column;
|
226 |
+
width: 100%;
|
227 |
+
min-height: 680px;
|
228 |
+
max-height: 1200px;
|
229 |
+
}
|
230 |
+
|
231 |
+
.output-html > iframe {
|
232 |
+
flex: 1;
|
233 |
+
}
|
234 |
+
|
235 |
+
.output-code {
|
236 |
+
flex: 1;
|
237 |
+
min-height: 100%;
|
238 |
+
}
|
239 |
+
|
240 |
+
.gradio-container {
|
241 |
+
max-width: 1200px !important;
|
242 |
+
}
|
243 |
+
"""
|
244 |
+
|
245 |
+
with gr.Blocks(css=css, title="GPT5 Vibe Tester") as demo:
|
246 |
+
# Global State
|
247 |
+
state = gr.State({"system_prompt": "", "history": []})
|
248 |
+
|
249 |
+
# Header
|
250 |
+
with gr.Row():
|
251 |
+
with gr.Column():
|
252 |
+
gr.HTML("""
|
253 |
+
<div style="text-align: center; margin: 20px 0;">
|
254 |
+
<div style="font-size: 64px; margin-bottom: 10px;">🎯</div>
|
255 |
+
<h1 style="color: #6A57FF; margin: 10px 0;">GPT5 Vibe Tester</h1>
|
256 |
+
<p style="color: #666; margin: 5px 0;">Test your creative vibes with GPT5</p>
|
257 |
+
</div>
|
258 |
+
""")
|
259 |
+
|
260 |
+
with gr.Row():
|
261 |
+
# Left Column - Input and Controls
|
262 |
+
with gr.Column(scale=1):
|
263 |
+
# Input
|
264 |
+
input = gr.Textbox(
|
265 |
+
lines=4,
|
266 |
+
placeholder="Describe the idea you want to test",
|
267 |
+
label="Your Idea",
|
268 |
+
elem_id="input-container"
|
269 |
+
)
|
270 |
+
|
271 |
+
# Note
|
272 |
+
gr.HTML("""
|
273 |
+
<p style="color: #ff7f00; font-weight: bold; margin: 10px 0;">
|
274 |
+
<strong>Note:</strong> Test your vibes through interactive prototypes. The app supports multi-round dialogue to refine your ideas.
|
275 |
+
</p>
|
276 |
+
""")
|
277 |
+
|
278 |
+
# Submit Button
|
279 |
+
submit_btn = gr.Button(
|
280 |
+
"Submit",
|
281 |
+
variant="primary",
|
282 |
+
size="lg",
|
283 |
+
elem_id="submit-btn"
|
284 |
+
)
|
285 |
+
|
286 |
+
# Settings
|
287 |
+
gr.HTML("<hr style='margin: 20px 0;'><h3>Settings</h3>")
|
288 |
+
|
289 |
+
with gr.Row():
|
290 |
+
history_btn = gr.Button("📜 View History", elem_id="history-btn")
|
291 |
+
clear_history_btn = gr.Button("🧹 Clear History", variant="stop")
|
292 |
+
|
293 |
+
# Examples
|
294 |
+
gr.HTML("<hr style='margin: 20px 0;'><h3>Examples</h3>")
|
295 |
+
|
296 |
+
# Create example buttons
|
297 |
+
example_buttons = []
|
298 |
+
for i, example in enumerate(EXAMPLES):
|
299 |
+
btn = gr.Button(
|
300 |
+
f"🎯 {example['title']}",
|
301 |
+
variant="secondary",
|
302 |
+
size="sm"
|
303 |
+
)
|
304 |
+
example_buttons.append(btn)
|
305 |
+
# Set up click event for each example
|
306 |
+
btn.click(
|
307 |
+
fn=lambda desc=example['description']: desc,
|
308 |
+
outputs=[input]
|
309 |
+
)
|
310 |
+
|
311 |
+
# Right Column - Output
|
312 |
+
with gr.Column(scale=2):
|
313 |
+
with gr.Group():
|
314 |
+
gr.HTML("<h3>Output</h3>")
|
315 |
+
|
316 |
+
with gr.Row():
|
317 |
+
download_btn = gr.Button("📥 Download Code", variant="secondary", interactive=False)
|
318 |
+
view_code_btn = gr.Button("🧑💻 View Code", variant="primary")
|
319 |
+
|
320 |
+
# Output tabs using visibility
|
321 |
+
output_state = gr.State("empty") # "empty", "loading", "render"
|
322 |
+
|
323 |
+
# Empty state
|
324 |
+
empty_output = gr.HTML(
|
325 |
+
"""
|
326 |
+
<div class="output-empty">
|
327 |
+
<div style="text-align: center; color: #666;">
|
328 |
+
<h3>🚀 Ready to Generate</h3>
|
329 |
+
<p>Enter your request to generate code</p>
|
330 |
+
</div>
|
331 |
+
</div>
|
332 |
+
""",
|
333 |
+
visible=True
|
334 |
+
)
|
335 |
+
|
336 |
+
# Loading state
|
337 |
+
loading_output = gr.HTML(
|
338 |
+
"""
|
339 |
+
<div class="output-loading">
|
340 |
+
<div style="text-align: center; color: #666;">
|
341 |
+
<h3>⚡ Generating code...</h3>
|
342 |
+
<p>Please wait while I create your application</p>
|
343 |
+
</div>
|
344 |
+
</div>
|
345 |
+
""",
|
346 |
+
visible=False
|
347 |
+
)
|
348 |
+
|
349 |
+
# Render state
|
350 |
+
sandbox = gr.HTML(
|
351 |
+
"",
|
352 |
+
elem_classes="output-html",
|
353 |
+
visible=False
|
354 |
+
)
|
355 |
+
|
356 |
+
# Hidden components for functionality
|
357 |
+
download_content = gr.Text(visible=False)
|
358 |
+
output_loading = gr.State(False)
|
359 |
+
state_tab = gr.State("empty")
|
360 |
+
|
361 |
+
# Modals using Gradio components
|
362 |
+
with gr.Row(visible=False) as system_prompt_modal:
|
363 |
+
with gr.Column():
|
364 |
+
gr.HTML("<h3>System Prompt</h3>")
|
365 |
+
system_prompt_input = gr.Textbox(
|
366 |
+
lines=8,
|
367 |
+
placeholder="Enter your system prompt here",
|
368 |
+
label="System Prompt"
|
369 |
+
)
|
370 |
+
|
371 |
+
# Code viewer (will be shown/hidden)
|
372 |
+
with gr.Row(visible=False) as output_code_drawer:
|
373 |
+
with gr.Column():
|
374 |
+
gr.HTML("<h3>Generated Code</h3>")
|
375 |
+
output = gr.Markdown(label="Code Output")
|
376 |
+
|
377 |
+
# History viewer
|
378 |
+
with gr.Row(visible=False) as history_drawer:
|
379 |
+
with gr.Column():
|
380 |
+
gr.HTML("<h3>Chat History</h3>")
|
381 |
+
history_output = gr.Chatbot(
|
382 |
+
show_label=False,
|
383 |
+
type="messages",
|
384 |
+
height=400
|
385 |
+
)
|
386 |
+
# Event Handlers
|
387 |
+
|
388 |
+
# Clear history
|
389 |
+
clear_history_btn.click(
|
390 |
+
fn=GradioEvents.clear_history,
|
391 |
+
inputs=[state],
|
392 |
+
outputs=[state]
|
393 |
+
)
|
394 |
+
|
395 |
+
# Show history
|
396 |
+
history_btn.click(
|
397 |
+
fn=lambda: gr.update(visible=True),
|
398 |
+
outputs=[history_drawer]
|
399 |
+
).then(
|
400 |
+
fn=GradioEvents.render_history,
|
401 |
+
inputs=[state],
|
402 |
+
outputs=[history_output]
|
403 |
+
)
|
404 |
+
|
405 |
+
# Download code
|
406 |
+
download_btn.click(
|
407 |
+
fn=None,
|
408 |
+
inputs=[download_content],
|
409 |
+
js="""(content) => {
|
410 |
+
const blob = new Blob([content], { type: 'text/plain' })
|
411 |
+
const url = URL.createObjectURL(blob)
|
412 |
+
const a = document.createElement('a')
|
413 |
+
a.href = url
|
414 |
+
a.download = 'generated_code.txt'
|
415 |
+
a.click()
|
416 |
+
}"""
|
417 |
+
)
|
418 |
+
|
419 |
+
# View code
|
420 |
+
view_code_btn.click(
|
421 |
+
fn=lambda: gr.update(visible=True),
|
422 |
+
outputs=[output_code_drawer]
|
423 |
+
)
|
424 |
+
|
425 |
+
# Submit button
|
426 |
+
submit_btn.click(
|
427 |
+
fn=lambda: [gr.update(interactive=False), gr.update(interactive=False)],
|
428 |
+
outputs=[submit_btn, download_btn]
|
429 |
+
).then(
|
430 |
+
fn=GradioEvents.generate_code,
|
431 |
+
inputs=[input, system_prompt_input, state],
|
432 |
+
outputs=[
|
433 |
+
output, empty_output, loading_output, sandbox,
|
434 |
+
download_content, download_btn, state
|
435 |
+
]
|
436 |
+
).then(
|
437 |
+
fn=lambda: [gr.update(interactive=True), gr.update(interactive=True)],
|
438 |
+
outputs=[submit_btn, download_btn]
|
439 |
+
)
|
440 |
+
|
441 |
+
if __name__ == "__main__":
|
442 |
+
demo.queue(default_concurrency_limit=100,
|
443 |
+
max_size=100).launch(ssr_mode=False, max_threads=100)
|
config.py
ADDED
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
API_KEY = os.getenv('OPENAI_API_KEY')
|
4 |
+
|
5 |
+
MODEL = "gpt-4o-mini"
|
6 |
+
|
7 |
+
ENDPOINT = "https://api.openai.com/v1"
|
8 |
+
|
9 |
+
SYSTEM_PROMPT = """You are an expert on frontend design, you will always respond to web design tasks.
|
10 |
+
Your task is to create a website according to the user's request using either native HTML or React framework.
|
11 |
+
When choosing implementation framework, you should follow these rules:
|
12 |
+
[Implementation Rules]
|
13 |
+
1. You should use React by default.
|
14 |
+
2. When the user requires HTML, choose HTML to implement the request.
|
15 |
+
3. If the user requires a library that is not installed in current react environment, please use HTML and tell the user the reason.
|
16 |
+
4. After choosing the implementation framework, please follow the corresponding instruction.
|
17 |
+
|
18 |
+
|
19 |
+
[HTML Instruction]
|
20 |
+
You are a powerful code editing assistant capable of writing code and creating artifacts in conversations with users, or modifying and updating existing artifacts as requested by users.
|
21 |
+
All code is written in a single code block to form a complete code file for display, without separating HTML and JavaScript code. An artifact refers to a runnable complete code snippet, you prefer to integrate and output such complete runnable code rather than breaking it down into several code blocks. For certain types of code, they can render graphical interfaces in a UI window. After generation, please check the code execution again to ensure there are no errors in the output.
|
22 |
+
Do not use localStorage as it is not supported by current environment.
|
23 |
+
Output only the HTML, without any additional descriptive text.
|
24 |
+
|
25 |
+
|
26 |
+
[React Instruction]
|
27 |
+
You are an expert on frontend design, you will always respond to web design tasks.
|
28 |
+
Your task is to create a website using a SINGLE static React JSX file, which exports a default component. This code will go directly into the App.jsx file and will be used to render the website.
|
29 |
+
|
30 |
+
## Common Design Principles
|
31 |
+
|
32 |
+
Regardless of the technology used, follow these principles for all designs:
|
33 |
+
|
34 |
+
### General Design Guidelines:
|
35 |
+
- Create a stunning, contemporary, and highly functional website based on the user's request
|
36 |
+
- Implement a cohesive design language throughout the entire website/application
|
37 |
+
- Choose a carefully selected, harmonious color palette that enhances the overall aesthetic
|
38 |
+
- Create a clear visual hierarchy with proper typography to improve readability
|
39 |
+
- Incorporate subtle animations and transitions to add polish and improve user experience
|
40 |
+
- Ensure proper spacing and alignment using appropriate layout techniques
|
41 |
+
- Implement responsive design principles to ensure the website looks great on all device sizes
|
42 |
+
- Use modern UI patterns like cards, gradients, and subtle shadows to add depth and visual interest
|
43 |
+
- Incorporate whitespace effectively to create a clean, uncluttered design
|
44 |
+
- For images, use placeholder images from services like https://placehold.co/
|
45 |
+
|
46 |
+
## React Design Guidelines
|
47 |
+
|
48 |
+
### Implementation Requirements:
|
49 |
+
- Ensure the React app is a single page application
|
50 |
+
- DO NOT include any external libraries, frameworks, or dependencies outside of what is already installed
|
51 |
+
- Utilize TailwindCSS for styling, focusing on creating a visually appealing and responsive layout
|
52 |
+
- Avoid using arbitrary values (e.g., `h-[600px]`). Stick to Tailwind's predefined classes for consistency
|
53 |
+
- Use mock data instead of making HTTP requests or API calls to external services
|
54 |
+
- Utilize Tailwind's typography classes to create a clear visual hierarchy and improve readability
|
55 |
+
- Ensure proper spacing and alignment using Tailwind's margin, padding, and flexbox/grid classes
|
56 |
+
- Do not use localStorage as it is not supported by current environment.
|
57 |
+
|
58 |
+
### Installed Libraries:
|
59 |
+
You can use these installed libraries if required.
|
60 |
+
- **lucide-react**: Lightweight SVG icon library with 1000+ icons. Import as `import { IconName } from "lucide-react"`. Perfect for buttons, navigation, status indicators, and decorative elements.
|
61 |
+
- **recharts**: Declarative charting library built on D3. Import components like `import { LineChart, BarChart } from "recharts"`. Use for data visualization, analytics dashboards, and statistical displays.
|
62 |
+
- **framer-motion**: Production-ready motion library for React. Import as `import { motion } from "framer-motion"`. Use for animations, page transitions, hover effects, and interactive micro-interactions.
|
63 |
+
- **p5.js** : JavaScript library for creative coding and generative art. Usage: import p5 from "p5". Create interactive visuals, animations, sound-driven experiences, and artistic simulations.
|
64 |
+
- **three, @react-three/fiber, @react-three/drei**: 3D graphics library with React renderer and helpers. Import as `import { Canvas } from "@react-three/fiber"` and `import { OrbitControls } from "@react-three/drei"`. Use for 3D scenes, visualizations, and immersive experiences.
|
65 |
+
|
66 |
+
Remember to only return code for the App.jsx file and nothing else. The resulting application should be visually impressive, highly functional, and something users would be proud to showcase."""
|
67 |
+
|
68 |
+
EXAMPLES = [
|
69 |
+
{
|
70 |
+
"title":
|
71 |
+
"Bouncing ball",
|
72 |
+
"description":
|
73 |
+
"Make a page in HTML that shows an animation of a ball bouncing in a rotating hypercube.",
|
74 |
+
},
|
75 |
+
{
|
76 |
+
"title": "Pokémon SVG",
|
77 |
+
"description":
|
78 |
+
"Help me to generate an SVG of 5 Pokémons, include details."
|
79 |
+
},
|
80 |
+
{
|
81 |
+
"title":
|
82 |
+
"Strawberry card",
|
83 |
+
"description":
|
84 |
+
"""How many "r"s are in the word "strawberry"? Make a cute little card!"""
|
85 |
+
},
|
86 |
+
{
|
87 |
+
"title":
|
88 |
+
"TODO list",
|
89 |
+
"description":
|
90 |
+
"I want a TODO list that allows me to add tasks, delete tasks, and I would like the overall color theme to be purple."
|
91 |
+
},
|
92 |
+
]
|
93 |
+
|
94 |
+
DEFAULT_LOCALE = 'en_US'
|
95 |
+
|
96 |
+
DEFAULT_THEME = {
|
97 |
+
"token": {
|
98 |
+
"colorPrimary": "#6A57FF",
|
99 |
+
}
|
100 |
+
}
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
openai
|