SaroLearningAI commited on
Commit
fdd1e6c
·
verified ·
1 Parent(s): d6f7286

Index.html changes

Browse files
Files changed (1) hide show
  1. index.html +336 -19
index.html CHANGED
@@ -1,19 +1,336 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+
7
+ <title>Angular AI Chat</title>
8
+
9
+ <style>
10
+ * {
11
+ box-sizing: border-box;
12
+ }
13
+
14
+ body {
15
+ margin: 0;
16
+ font-family: Arial, sans-serif;
17
+ background: #0f1117;
18
+ color: #fff;
19
+ }
20
+
21
+ .app {
22
+ max-width: 900px;
23
+ margin: auto;
24
+ height: 100vh;
25
+ display: flex;
26
+ flex-direction: column;
27
+ }
28
+
29
+ header {
30
+ padding: 18px;
31
+ border-bottom: 1px solid #292d36;
32
+ }
33
+
34
+ header h1 {
35
+ margin: 0;
36
+ font-size: 20px;
37
+ }
38
+
39
+ header p {
40
+ margin: 6px 0 0;
41
+ color: #9ca3af;
42
+ font-size: 13px;
43
+ }
44
+
45
+ #chat {
46
+ flex: 1;
47
+ overflow-y: auto;
48
+ padding: 20px;
49
+ }
50
+
51
+ .message {
52
+ margin-bottom: 18px;
53
+ line-height: 1.6;
54
+ white-space: pre-wrap;
55
+ }
56
+
57
+ .user {
58
+ color: #8ab4f8;
59
+ }
60
+
61
+ .assistant {
62
+ color: #e5e7eb;
63
+ }
64
+
65
+ .label {
66
+ font-size: 12px;
67
+ font-weight: bold;
68
+ margin-bottom: 4px;
69
+ color: #9ca3af;
70
+ }
71
+
72
+ .input-area {
73
+ padding: 12px;
74
+ border-top: 1px solid #292d36;
75
+ display: flex;
76
+ gap: 8px;
77
+ }
78
+
79
+ textarea {
80
+ flex: 1;
81
+ resize: none;
82
+ border: 1px solid #363b46;
83
+ border-radius: 10px;
84
+ background: #181b23;
85
+ color: white;
86
+ padding: 12px;
87
+ font-size: 15px;
88
+ outline: none;
89
+ }
90
+
91
+ button {
92
+ border: none;
93
+ border-radius: 10px;
94
+ padding: 0 18px;
95
+ background: #2563eb;
96
+ color: white;
97
+ font-weight: bold;
98
+ }
99
+
100
+ button:disabled {
101
+ opacity: 0.5;
102
+ }
103
+
104
+ #status {
105
+ padding: 0 14px 8px;
106
+ font-size: 12px;
107
+ color: #9ca3af;
108
+ }
109
+ </style>
110
+ </head>
111
+
112
+ <body>
113
+
114
+ <div class="app">
115
+
116
+ <header>
117
+ <h1>⚡ Angular AI Chat</h1>
118
+ <p>Angular • TypeScript • RxJS • CDK • Angular Material</p>
119
+ </header>
120
+
121
+ <div id="chat">
122
+ <div class="message assistant">
123
+ <div class="label">ANGULAR AI</div>
124
+ Hi! Ask me anything about Angular.
125
+ </div>
126
+ </div>
127
+
128
+ <div id="status">Model not loaded</div>
129
+
130
+ <div class="input-area">
131
+ <textarea
132
+ id="input"
133
+ rows="2"
134
+ placeholder="Ask an Angular question..."
135
+ ></textarea>
136
+
137
+ <button id="send">Send</button>
138
+ </div>
139
+
140
+ </div>
141
+
142
+ <script type="module">
143
+
144
+ import {
145
+ pipeline
146
+ } from "https://cdn.jsdelivr.net/npm/@huggingface/transformers@4.0.1";
147
+
148
+ const MODEL =
149
+ "onnx-community/Qwen2.5-Coder-0.5B-Instruct";
150
+
151
+ let generator = null;
152
+
153
+ const chat = document.getElementById("chat");
154
+ const input = document.getElementById("input");
155
+ const send = document.getElementById("send");
156
+ const status = document.getElementById("status");
157
+
158
+ const systemPrompt = `
159
+ You are an expert Angular developer.
160
+
161
+ This is an Angular-only technical chat.
162
+
163
+ Focus on:
164
+ - Angular
165
+ - TypeScript
166
+ - RxJS
167
+ - Angular CDK
168
+ - Angular Material
169
+ - Signals
170
+ - Components
171
+ - Directives
172
+ - Pipes
173
+ - Services
174
+ - Dependency Injection
175
+ - Routing
176
+ - Forms
177
+ - HTTP
178
+ - Change Detection
179
+ - Lifecycle hooks
180
+ - Performance
181
+ - Virtual scrolling
182
+ - Angular tables
183
+ - Angular + .NET
184
+ - Angular + Java/Spring Boot
185
+
186
+ Give practical, working solutions with code when useful.
187
+
188
+ If a question is completely unrelated to Angular or software
189
+ development, politely say that this chat is focused on Angular.
190
+ `;
191
+
192
+ const messages = [
193
+ {
194
+ role: "system",
195
+ content: systemPrompt
196
+ }
197
+ ];
198
+
199
+ function addMessage(type, text) {
200
+
201
+ const div = document.createElement("div");
202
+
203
+ div.className = `message ${type}`;
204
+
205
+ div.innerHTML = `
206
+ <div class="label">
207
+ ${type === "user" ? "YOU" : "ANGULAR AI"}
208
+ </div>
209
+ <div>${escapeHtml(text)}</div>
210
+ `;
211
+
212
+ chat.appendChild(div);
213
+
214
+ chat.scrollTop = chat.scrollHeight;
215
+
216
+ return div;
217
+ }
218
+
219
+ function escapeHtml(text) {
220
+
221
+ return text
222
+ .replaceAll("&", "&amp;")
223
+ .replaceAll("<", "&lt;")
224
+ .replaceAll(">", "&gt;");
225
+ }
226
+
227
+ async function loadModel() {
228
+
229
+ status.textContent =
230
+ "Loading Angular AI model... First load may take a while.";
231
+
232
+ generator = await pipeline(
233
+ "text-generation",
234
+ MODEL,
235
+ {
236
+ dtype: "q4"
237
+ }
238
+ );
239
+
240
+ status.textContent =
241
+ "Model ready ✓";
242
+
243
+ send.disabled = false;
244
+ }
245
+
246
+ async function sendMessage() {
247
+
248
+ const text = input.value.trim();
249
+
250
+ if (!text || !generator) {
251
+ return;
252
+ }
253
+
254
+ input.value = "";
255
+
256
+ addMessage("user", text);
257
+
258
+ messages.push({
259
+ role: "user",
260
+ content: text
261
+ });
262
+
263
+ send.disabled = true;
264
+
265
+ status.textContent = "Thinking...";
266
+
267
+ try {
268
+
269
+ const output = await generator(
270
+ messages,
271
+ {
272
+ max_new_tokens: 400,
273
+ do_sample: false
274
+ }
275
+ );
276
+
277
+ const answer =
278
+ output[0].generated_text.at(-1).content;
279
+
280
+ messages.push({
281
+ role: "assistant",
282
+ content: answer
283
+ });
284
+
285
+ addMessage("assistant", answer);
286
+
287
+ status.textContent = "Model ready ✓";
288
+
289
+ } catch (error) {
290
+
291
+ console.error(error);
292
+
293
+ addMessage(
294
+ "assistant",
295
+ "Something went wrong while generating the answer."
296
+ );
297
+
298
+ status.textContent = "Error";
299
+
300
+ } finally {
301
+
302
+ send.disabled = false;
303
+ input.focus();
304
+ }
305
+ }
306
+
307
+ send.disabled = true;
308
+
309
+ send.addEventListener(
310
+ "click",
311
+ sendMessage
312
+ );
313
+
314
+ input.addEventListener(
315
+ "keydown",
316
+ event => {
317
+
318
+ if (
319
+ event.key === "Enter" &&
320
+ !event.shiftKey
321
+ ) {
322
+
323
+ event.preventDefault();
324
+
325
+ sendMessage();
326
+ }
327
+
328
+ }
329
+ );
330
+
331
+ loadModel();
332
+
333
+ </script>
334
+
335
+ </body>
336
+ </html>