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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<html><head><base href="https://websim.ai/"><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>WebSim inside WebSim</title>
|
2 |
+
<style>
|
3 |
+
body {
|
4 |
+
font-family: Arial, sans-serif;
|
5 |
+
margin: 0;
|
6 |
+
padding: 0;
|
7 |
+
background-color: #f0f0f0;
|
8 |
+
}
|
9 |
+
#header {
|
10 |
+
background-color: #333;
|
11 |
+
color: white;
|
12 |
+
padding: 10px;
|
13 |
+
display: flex;
|
14 |
+
justify-content: space-between;
|
15 |
+
align-items: center;
|
16 |
+
}
|
17 |
+
#prompt-input {
|
18 |
+
flex-grow: 1;
|
19 |
+
margin-right: 10px;
|
20 |
+
padding: 5px;
|
21 |
+
font-size: 16px;
|
22 |
+
}
|
23 |
+
#generate-btn, #settings-btn {
|
24 |
+
background-color: #4CAF50;
|
25 |
+
border: none;
|
26 |
+
color: white;
|
27 |
+
padding: 5px 10px;
|
28 |
+
text-align: center;
|
29 |
+
text-decoration: none;
|
30 |
+
display: inline-block;
|
31 |
+
font-size: 16px;
|
32 |
+
margin: 4px 2px;
|
33 |
+
cursor: pointer;
|
34 |
+
}
|
35 |
+
#settings-modal {
|
36 |
+
display: none;
|
37 |
+
position: fixed;
|
38 |
+
z-index: 1;
|
39 |
+
left: 0;
|
40 |
+
top: 0;
|
41 |
+
width: 100%;
|
42 |
+
height: 100%;
|
43 |
+
overflow: auto;
|
44 |
+
background-color: rgba(0,0,0,0.4);
|
45 |
+
}
|
46 |
+
.modal-content {
|
47 |
+
background-color: #fefefe;
|
48 |
+
margin: 15% auto;
|
49 |
+
padding: 20px;
|
50 |
+
border: 1px solid #888;
|
51 |
+
width: 80%;
|
52 |
+
max-width: 500px;
|
53 |
+
}
|
54 |
+
#result {
|
55 |
+
margin: 20px;
|
56 |
+
padding: 20px;
|
57 |
+
background-color: white;
|
58 |
+
border-radius: 5px;
|
59 |
+
box-shadow: 0 0 10px rgba(0,0,0,0.1);
|
60 |
+
}
|
61 |
+
.close {
|
62 |
+
color: #aaa;
|
63 |
+
float: right;
|
64 |
+
font-size: 28px;
|
65 |
+
font-weight: bold;
|
66 |
+
}
|
67 |
+
.close:hover,
|
68 |
+
.close:focus {
|
69 |
+
color: black;
|
70 |
+
text-decoration: none;
|
71 |
+
cursor: pointer;
|
72 |
+
}
|
73 |
+
#system-prompt {
|
74 |
+
width: 100%;
|
75 |
+
height: 100px;
|
76 |
+
margin-top: 10px;
|
77 |
+
}
|
78 |
+
#loading {
|
79 |
+
display: none;
|
80 |
+
position: fixed;
|
81 |
+
top: 50%;
|
82 |
+
left: 50%;
|
83 |
+
transform: translate(-50%, -50%);
|
84 |
+
}
|
85 |
+
.spinner {
|
86 |
+
width: 50px;
|
87 |
+
height: 50px;
|
88 |
+
border: 5px solid #f3f3f3;
|
89 |
+
border-top: 5px solid #3498db;
|
90 |
+
border-radius: 50%;
|
91 |
+
animation: spin 1s linear infinite;
|
92 |
+
}
|
93 |
+
@keyframes spin {
|
94 |
+
0% { transform: rotate(0deg); }
|
95 |
+
100% { transform: rotate(360deg); }
|
96 |
+
}
|
97 |
+
#original-response {
|
98 |
+
margin-top: 20px;
|
99 |
+
padding: 10px;
|
100 |
+
background-color: #f9f9f9;
|
101 |
+
border: 1px solid #ddd;
|
102 |
+
border-radius: 5px;
|
103 |
+
}
|
104 |
+
#copy-btn, #reset-settings-btn {
|
105 |
+
margin-top: 10px;
|
106 |
+
padding: 5px 10px;
|
107 |
+
background-color: #008CBA;
|
108 |
+
color: white;
|
109 |
+
border: none;
|
110 |
+
border-radius: 3px;
|
111 |
+
cursor: pointer;
|
112 |
+
}
|
113 |
+
#reset-settings-btn {
|
114 |
+
background-color: #f44336;
|
115 |
+
}
|
116 |
+
#max-tokens-value {
|
117 |
+
display: inline-block;
|
118 |
+
width: 50px;
|
119 |
+
text-align: right;
|
120 |
+
}
|
121 |
+
#model-select {
|
122 |
+
margin-top: 10px;
|
123 |
+
padding: 5px;
|
124 |
+
font-size: 16px;
|
125 |
+
}
|
126 |
+
</style>
|
127 |
+
</head>
|
128 |
+
<body>
|
129 |
+
<div id="header">
|
130 |
+
<input type="text" id="prompt-input" placeholder="Enter website description...">
|
131 |
+
<button id="generate-btn">Generate</button>
|
132 |
+
<button id="settings-btn">Settings</button>
|
133 |
+
</div>
|
134 |
+
|
135 |
+
<div id="settings-modal">
|
136 |
+
<div class="modal-content">
|
137 |
+
<span class="close">×</span>
|
138 |
+
<h2>Settings</h2>
|
139 |
+
<label for="huggingface-token">Hugging Face Token:</label>
|
140 |
+
<input type="text" id="huggingface-token">
|
141 |
+
<br><br>
|
142 |
+
<label for="model-select">Select Model:</label>
|
143 |
+
<select id="model-select">
|
144 |
+
<option value="codellama/CodeLlama-34b-Instruct-hf">CodeLlama-34b-Instruct-hf</option>
|
145 |
+
<option value="mistralai/Mistral-Small-Instruct-2409">Mistral-Small-Instruct-2409</option>
|
146 |
+
<option value="microsoft/Phi-3.5-mini-instruct">Phi-3.5-mini-instruct</option>
|
147 |
+
<option value="01-ai/Yi-1.5-34B-Chat">Yi-1.5-34B-Chat</option>
|
148 |
+
</select>
|
149 |
+
<br><br>
|
150 |
+
<label for="max-tokens">Max Tokens: <span id="max-tokens-value">1000</span></label>
|
151 |
+
<input type="range" id="max-tokens" min="500" max="1024" value="1000">
|
152 |
+
<br><br>
|
153 |
+
<label for="system-prompt">System prompt:</label>
|
154 |
+
<textarea id="system-prompt">Do not write any comments to your code, do not write anything before or after the code itself. Write HTML, CSS, and JavaScript in a single file. Generate only complete, working code without abbreviations or omissions. Do not use markdown code blocks (```) or any similar formatting. You are strictly prohibited from providing any explanations, comments, or any text that is not part of the actual code, including any statements after the code.</textarea>
|
155 |
+
<br><br>
|
156 |
+
<button id="save-settings">Save</button>
|
157 |
+
<button id="reset-settings-btn">Reset to Default</button>
|
158 |
+
</div>
|
159 |
+
</div>
|
160 |
+
|
161 |
+
<div id="result"></div>
|
162 |
+
|
163 |
+
<div id="original-response"></div>
|
164 |
+
<button id="copy-btn" style="display: none;">Copy Original Response</button>
|
165 |
+
|
166 |
+
<div id="loading">
|
167 |
+
<div class="spinner"></div>
|
168 |
+
</div>
|
169 |
+
|
170 |
+
<script>
|
171 |
+
let currentPrompt = '';
|
172 |
+
let currentCode = '';
|
173 |
+
let selectedModel = localStorage.getItem('selectedModel') || "codellama/CodeLlama-34b-Instruct-hf";
|
174 |
+
let huggingFaceToken = localStorage.getItem('huggingFaceToken') || "";
|
175 |
+
const defaultSystemPrompt = "Do not write any comments to your code, do not write anything before or after the code itself. Write HTML, CSS, and JavaScript in a single file. Generate only complete, working code without abbreviations or omissions. Do not use markdown code blocks (```) or any similar formatting. You are strictly prohibited from providing any explanations, comments, or any text that is not part of the actual code, including any statements after the code.";
|
176 |
+
let systemPrompt = localStorage.getItem('systemPrompt') || defaultSystemPrompt;
|
177 |
+
let maxTokens = localStorage.getItem('maxTokens') || 1000;
|
178 |
+
|
179 |
+
document.getElementById('settings-btn').addEventListener('click', function() {
|
180 |
+
document.getElementById('settings-modal').style.display = 'block';
|
181 |
+
document.getElementById('huggingface-token').value = huggingFaceToken;
|
182 |
+
document.getElementById('model-select').value = selectedModel;
|
183 |
+
document.getElementById('system-prompt').value = systemPrompt;
|
184 |
+
document.getElementById('max-tokens').value = maxTokens;
|
185 |
+
document.getElementById('max-tokens-value').textContent = maxTokens;
|
186 |
+
});
|
187 |
+
|
188 |
+
document.getElementsByClassName('close')[0].addEventListener('click', function() {
|
189 |
+
document.getElementById('settings-modal').style.display = 'none';
|
190 |
+
});
|
191 |
+
|
192 |
+
document.getElementById('save-settings').addEventListener('click', function() {
|
193 |
+
huggingFaceToken = document.getElementById('huggingface-token').value;
|
194 |
+
selectedModel = document.getElementById('model-select').value;
|
195 |
+
systemPrompt = document.getElementById('system-prompt').value;
|
196 |
+
maxTokens = document.getElementById('max-tokens').value;
|
197 |
+
localStorage.setItem('huggingFaceToken', huggingFaceToken);
|
198 |
+
localStorage.setItem('selectedModel', selectedModel);
|
199 |
+
localStorage.setItem('systemPrompt', systemPrompt);
|
200 |
+
localStorage.setItem('maxTokens', maxTokens);
|
201 |
+
document.getElementById('settings-modal').style.display = 'none';
|
202 |
+
console.log("Settings saved. Token:", huggingFaceToken, "Model:", selectedModel, "System Prompt:", systemPrompt, "Max Tokens:", maxTokens);
|
203 |
+
});
|
204 |
+
|
205 |
+
document.getElementById('reset-settings-btn').addEventListener('click', function() {
|
206 |
+
selectedModel = "codellama/CodeLlama-34b-Instruct-hf";
|
207 |
+
systemPrompt = defaultSystemPrompt;
|
208 |
+
maxTokens = 1000;
|
209 |
+
document.getElementById('model-select').value = selectedModel;
|
210 |
+
document.getElementById('system-prompt').value = systemPrompt;
|
211 |
+
document.getElementById('max-tokens').value = maxTokens;
|
212 |
+
document.getElementById('max-tokens-value').textContent = maxTokens;
|
213 |
+
localStorage.setItem('selectedModel', selectedModel);
|
214 |
+
localStorage.setItem('systemPrompt', systemPrompt);
|
215 |
+
localStorage.setItem('maxTokens', maxTokens);
|
216 |
+
console.log("Settings reset to default. Model:", selectedModel, "System Prompt:", systemPrompt, "Max Tokens:", maxTokens);
|
217 |
+
});
|
218 |
+
|
219 |
+
document.getElementById('max-tokens').addEventListener('input', function() {
|
220 |
+
document.getElementById('max-tokens-value').textContent = this.value;
|
221 |
+
});
|
222 |
+
|
223 |
+
document.getElementById('generate-btn').addEventListener('click', generateWebsite);
|
224 |
+
|
225 |
+
document.getElementById('prompt-input').addEventListener('keypress', function(event) {
|
226 |
+
if (event.key === 'Enter') {
|
227 |
+
generateWebsite();
|
228 |
+
}
|
229 |
+
});
|
230 |
+
|
231 |
+
document.getElementById('copy-btn').addEventListener('click', function() {
|
232 |
+
const originalResponse = document.getElementById('original-response').textContent;
|
233 |
+
navigator.clipboard.writeText(originalResponse).then(function() {
|
234 |
+
alert('Original response copied to clipboard!');
|
235 |
+
}, function(err) {
|
236 |
+
console.error('Could not copy text: ', err);
|
237 |
+
});
|
238 |
+
});
|
239 |
+
|
240 |
+
function generateWebsite() {
|
241 |
+
currentPrompt = document.getElementById('prompt-input').value;
|
242 |
+
if (currentPrompt) {
|
243 |
+
generateWebsiteFromAPI(currentPrompt);
|
244 |
+
}
|
245 |
+
}
|
246 |
+
|
247 |
+
async function generateWebsiteFromAPI(prompt) {
|
248 |
+
if (!huggingFaceToken) {
|
249 |
+
alert("Please set your Hugging Face token in the settings.");
|
250 |
+
return;
|
251 |
+
}
|
252 |
+
|
253 |
+
const apiUrl = 'https://api-inference.huggingface.co/models/' + selectedModel + '/v1/chat/completions';
|
254 |
+
|
255 |
+
let messages = [
|
256 |
+
{"role": "system", "content": systemPrompt},
|
257 |
+
{"role": "user", "content": "Generate a website based on this description: " + prompt}
|
258 |
+
];
|
259 |
+
|
260 |
+
document.getElementById('loading').style.display = 'block';
|
261 |
+
|
262 |
+
try {
|
263 |
+
const response = await fetch(apiUrl, {
|
264 |
+
method: 'POST',
|
265 |
+
headers: {
|
266 |
+
'Authorization': 'Bearer ' + huggingFaceToken,
|
267 |
+
'Content-Type': 'application/json'
|
268 |
+
},
|
269 |
+
body: JSON.stringify({
|
270 |
+
model: selectedModel,
|
271 |
+
messages: messages,
|
272 |
+
max_tokens: parseInt(maxTokens),
|
273 |
+
stream: false
|
274 |
+
})
|
275 |
+
});
|
276 |
+
|
277 |
+
document.getElementById('loading').style.display = 'none';
|
278 |
+
|
279 |
+
if (!response.ok) {
|
280 |
+
throw new Error(`HTTP error! status: ${response.status}`);
|
281 |
+
}
|
282 |
+
|
283 |
+
const data = await response.json();
|
284 |
+
currentCode = data.choices[0].message.content;
|
285 |
+
|
286 |
+
const resultDiv = document.getElementById('result');
|
287 |
+
resultDiv.innerHTML = '';
|
288 |
+
|
289 |
+
const sandbox = document.createElement('iframe');
|
290 |
+
sandbox.style.width = '100%';
|
291 |
+
sandbox.style.height = '500px';
|
292 |
+
sandbox.style.border = 'none';
|
293 |
+
resultDiv.appendChild(sandbox);
|
294 |
+
|
295 |
+
const sandboxContent = sandbox.contentDocument || sandbox.contentWindow.document;
|
296 |
+
sandboxContent.open();
|
297 |
+
sandboxContent.write(currentCode);
|
298 |
+
sandboxContent.close();
|
299 |
+
|
300 |
+
document.getElementById('original-response').textContent = currentCode;
|
301 |
+
document.getElementById('copy-btn').style.display = 'block';
|
302 |
+
|
303 |
+
} catch (error) {
|
304 |
+
document.getElementById('loading').style.display = 'none';
|
305 |
+
console.error('There was a problem with the fetch operation:', error);
|
306 |
+
document.getElementById('result').innerHTML = `<p>An error occurred while generating the website: ${error.message}</p>`;
|
307 |
+
}
|
308 |
+
}
|
309 |
+
</script>
|
310 |
+
|
311 |
+
</body></html>
|