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