Spaces:
Running
Running
Update index.html
Browse files- index.html +967 -1163
index.html
CHANGED
@@ -1,1209 +1,1013 @@
|
|
1 |
<!DOCTYPE html>
|
2 |
<html lang="th">
|
3 |
<head>
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
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 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
.chip-container {
|
473 |
-
display: flex;
|
474 |
-
gap: 15px;
|
475 |
-
margin-bottom: 25px;
|
476 |
-
flex-wrap: wrap;
|
477 |
-
padding: 0 30px;
|
478 |
-
}
|
479 |
-
|
480 |
-
.chip {
|
481 |
-
padding: 12px 20px;
|
482 |
-
background: var(--bg-tertiary);
|
483 |
-
border: 1px solid var(--glass-border);
|
484 |
-
border-radius: 25px;
|
485 |
-
font-size: 0.9rem;
|
486 |
-
font-weight: 600;
|
487 |
-
cursor: pointer;
|
488 |
-
transition: all 0.35s cubic-bezier(0.165, 0.84, 0.44, 1);
|
489 |
-
color: var(--text-secondary);
|
490 |
-
}
|
491 |
-
|
492 |
-
.chip:hover {
|
493 |
-
background: var(--accent-secondary);
|
494 |
-
color: #fff;
|
495 |
-
transform: translateY(-3px);
|
496 |
-
box-shadow: 0 8px 22px rgba(255, 153, 51, 0.4);
|
497 |
-
border-color: transparent;
|
498 |
-
}
|
499 |
-
|
500 |
-
.floating-buttons {
|
501 |
-
position: absolute;
|
502 |
-
top: 25px;
|
503 |
-
right: 25px;
|
504 |
-
display: flex;
|
505 |
-
gap: 15px;
|
506 |
-
z-index: 200; /* Ensure above chat */
|
507 |
-
}
|
508 |
-
|
509 |
-
.floating-btn {
|
510 |
-
width: 50px;
|
511 |
-
height: 50px;
|
512 |
-
border-radius: 50%;
|
513 |
-
background: var(--bg-secondary);
|
514 |
-
backdrop-filter: blur(10px);
|
515 |
-
border: 1px solid var(--glass-border);
|
516 |
-
display: flex;
|
517 |
-
align-items: center;
|
518 |
-
justify-content: center;
|
519 |
-
transition: all 0.35s cubic-bezier(0.165, 0.84, 0.44, 1);
|
520 |
-
padding: 0;
|
521 |
-
color: var(--text-primary);
|
522 |
-
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
|
523 |
-
}
|
524 |
-
|
525 |
-
.floating-btn:hover {
|
526 |
-
background: var(--accent-primary);
|
527 |
-
color: #000;
|
528 |
-
transform: translateY(-3px) scale(1.1);
|
529 |
-
box-shadow: 0 10px 30px rgba(51, 255, 153, 0.4);
|
530 |
-
}
|
531 |
-
|
532 |
-
.code-tools {
|
533 |
-
position: absolute;
|
534 |
-
top: 15px;
|
535 |
-
right: 15px;
|
536 |
-
display: flex;
|
537 |
-
gap: 10px;
|
538 |
-
opacity: 0; /* Hidden by default */
|
539 |
-
transition: opacity 0.3s ease;
|
540 |
-
}
|
541 |
-
pre:hover .code-tools { opacity: 1; } /* Show on hover */
|
542 |
-
|
543 |
-
.code-tools button {
|
544 |
-
padding: 8px 14px;
|
545 |
-
font-size: 0.8rem;
|
546 |
-
background: var(--bg-tertiary);
|
547 |
-
backdrop-filter: blur(5px);
|
548 |
-
border: 1px solid var(--glass-border);
|
549 |
-
color: var(--text-primary);
|
550 |
-
border-radius: 6px;
|
551 |
-
box-shadow: none;
|
552 |
-
}
|
553 |
-
.code-tools button:hover {
|
554 |
-
background: var(--accent-primary);
|
555 |
-
color: #000;
|
556 |
-
transform: translateY(-2px);
|
557 |
-
box-shadow: 0 4px 10px rgba(51, 255, 153, 0.3);
|
558 |
-
}
|
559 |
-
|
560 |
-
.image-preview {
|
561 |
-
max-width: 100%;
|
562 |
-
max-height: 350px;
|
563 |
-
border-radius: 15px;
|
564 |
-
margin-top: 15px;
|
565 |
-
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
|
566 |
-
border: 1px solid #ddd;
|
567 |
-
}
|
568 |
-
|
569 |
-
@keyframes fadeInUp {
|
570 |
-
from { opacity: 0; transform: translateY(35px); }
|
571 |
-
to { opacity: 1; transform: translateY(0); }
|
572 |
-
}
|
573 |
-
|
574 |
-
@media (max-width: 768px) {
|
575 |
-
.app-container { flex-direction: column; height: 100vh; border-radius: 0; width: 100%; }
|
576 |
-
.settings-panel { width: 100%; max-height: 35vh; border-right: none; border-bottom: 1px solid var(--glass-border); }
|
577 |
-
.settings-panel.collapsed { max-height: 0; }
|
578 |
-
.chat-container { max-height: 55vh; padding: 20px; border-radius: 0; }
|
579 |
-
.input-container { padding: 20px; border-radius: 0; }
|
580 |
-
#userInput { margin-bottom: 0; }
|
581 |
-
.floating-buttons { top: 15px; right: 15px; }
|
582 |
-
.floating-btn { width: 45px; height: 45px; }
|
583 |
-
.material-icons { font-size: 24px; }
|
584 |
-
}
|
585 |
-
@media (max-width: 480px) {
|
586 |
-
.chip { font-size: 0.85rem; padding: 10px 16px; }
|
587 |
-
.form-field select, .form-field textarea, #userInput { font-size: 1rem; }
|
588 |
-
.message { padding: 15px 20px; }
|
589 |
-
}
|
590 |
-
</style>
|
591 |
</head>
|
592 |
<body>
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
💡 เลือกโมเดลที่ต้องการ ใช้ VL หรือ Florence สำหรับรูปภาพ
|
605 |
-
</p>
|
606 |
-
</div>
|
607 |
-
<div class="form-field">
|
608 |
-
<label>👁️ โมเดล OCR (สำหรับรูปภาพ):</label>
|
609 |
-
<select id="ocrModelSelect">
|
610 |
-
<option value="none">ไม่ใช้</option>
|
611 |
-
<option value="microsoft/trocr-base-printed">TrOCR Base (แนะนำ)</option>
|
612 |
-
</select>
|
613 |
-
</div>
|
614 |
-
<button id="saveSettingsBtn">💾 บันทึกการตั้งค่า</button>
|
615 |
-
</div>
|
616 |
-
|
617 |
-
<div class="main-content">
|
618 |
-
<div class="floating-buttons">
|
619 |
-
<button id="settingsToggle" class="floating-btn">
|
620 |
-
<span class="material-icons">settings</span>
|
621 |
-
</button>
|
622 |
-
<button id="fullscreenToggle" class="floating-btn">
|
623 |
-
<span class="material-icons">fullscreen</span>
|
624 |
-
</button>
|
625 |
-
<button id="refreshBtn" class="floating-btn">
|
626 |
-
<span class="material-icons">refresh</span>
|
627 |
-
</button>
|
628 |
-
</div>
|
629 |
-
|
630 |
-
<div class="mode-toggle">
|
631 |
-
<button id="carouselModeBtn" class="active">🎛️ แก้ไข Prompt</button>
|
632 |
-
<button id="chatModeBtn">💬 แชท</button>
|
633 |
-
<div class="mode-toggle-slider" id="modeToggleSlider"></div>
|
634 |
-
</div>
|
635 |
-
|
636 |
-
<div id="carouselMode">
|
637 |
-
<div class="carousel-container">
|
638 |
-
<div class="carousel" id="promptCarousel">
|
639 |
-
<div class="carousel-card" style="transform: rotateY(0deg) translateZ(350px);">
|
640 |
-
<label>🎯 Primary System Prompt:</label>
|
641 |
-
<textarea id="primarySystemPrompt" placeholder="ป้อน Prompt หลักสำหรับ AI...">You are a powerful AI assistant that excels at understanding code, images, and technical content. Provide clear, accurate, and helpful responses. Focus on practical solutions and detailed explanations.</textarea>
|
642 |
-
</div>
|
643 |
-
<div class="carousel-card" style="transform: rotateY(60deg) translateZ(350px); opacity: 0.7;">
|
644 |
-
<label>👁️ OCR System Prompt:</label>
|
645 |
-
<textarea id="ocrSystemPrompt" placeholder="ป้อน Prompt สำหรับ OCR...">Extract all text from the provided image clearly and accurately. Preserve formatting, structure, and layout when possible. If text is unclear, indicate uncertain parts.</textarea>
|
646 |
-
</div>
|
647 |
-
<div class="carousel-card" style="transform: rotateY(120deg) translateZ(350px); opacity: 0.7;">
|
648 |
-
<label>💻 Code Template:</label>
|
649 |
-
<textarea id="codeTemplate" placeholder="ป้อน Template สำหรับโค้ด...">```javascript
|
650 |
-
// Enhanced code implementation
|
651 |
-
function solution() {
|
652 |
-
// Your optimized code here
|
653 |
-
return result;
|
654 |
-
}
|
655 |
-
```</textarea>
|
656 |
</div>
|
657 |
-
<div class="
|
658 |
-
|
659 |
-
|
|
|
|
|
|
|
660 |
</div>
|
661 |
-
<
|
662 |
-
|
663 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
664 |
</div>
|
665 |
-
<div class="
|
666 |
-
|
667 |
-
|
|
|
|
|
|
|
668 |
</div>
|
669 |
-
|
670 |
-
<div class="carousel-controls">
|
671 |
-
<button id="prevCard"><span class="material-icons">chevron_left</span></button>
|
672 |
-
<button id="nextCard"><span class="material-icons">chevron_right</span></button>
|
673 |
-
</div>
|
674 |
-
<div class="carousel-indicator" id="carouselIndicator">
|
675 |
-
<div class="carousel-dot active" data-index="0"></div>
|
676 |
-
<div class="carousel-dot" data-index="1"></div>
|
677 |
-
<div class="carousel-dot" data-index="2"></div>
|
678 |
-
<div class="carousel-dot" data-index="3"></div>
|
679 |
-
<div class="carousel-dot" data-index="4"></div>
|
680 |
-
<div class="carousel-dot" data-index="5"></div>
|
681 |
-
</div>
|
682 |
-
<button id="applyPromptBtn" style="margin-top: 30px;">✅ ใช้ Prompt & ไปที่แชท</button>
|
683 |
</div>
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
</div>
|
697 |
-
|
698 |
-
<button id="attachButton"><span class="material-icons">attach_file</span></button>
|
699 |
-
<input type="file" id="fileInput" multiple accept="image/*" style="display: none;">
|
700 |
-
<span class="file-name" id="fileName"></span>
|
701 |
-
<textarea id="userInput" placeholder="พิมพ์ข้อความที่นี่... (Shift+Enter เพื่อขึ้นบรรทัดใหม่)"></textarea>
|
702 |
-
<button id="sendButton"><span class="material-icons">send</span></button>
|
703 |
</div>
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
|
|
713 |
</div>
|
714 |
-
</div>
|
715 |
-
|
716 |
-
<script src="[https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js](https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js)"></script>
|
717 |
-
<script src="[https://cdnjs.cloudflare.com/ajax/libs/marked/9.1.6/marked.min.js](https://cdnjs.cloudflare.com/ajax/libs/marked/9.1.6/marked.min.js)"></script>
|
718 |
-
<script>
|
719 |
-
// Global variables
|
720 |
-
let attachedFiles = [];
|
721 |
-
let currentCarouselIndex = 0;
|
722 |
-
let isLoading = false;
|
723 |
-
const HUGGINGFACE_TOKEN = "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"; // <<< !!! ใส่ Hugging Face Token ของคุณที่นี่ !!!
|
724 |
-
|
725 |
-
// Initialize the application
|
726 |
-
document.addEventListener('DOMContentLoaded', function() {
|
727 |
-
loadSettings();
|
728 |
-
setupEventListeners();
|
729 |
-
setupCarousel();
|
730 |
-
setupDropzone();
|
731 |
-
switchMode('carousel'); // Start in carousel mode
|
732 |
-
updateCarouselPosition(); // Ensure initial position is set
|
733 |
-
});
|
734 |
-
|
735 |
-
// Settings management
|
736 |
-
function loadSettings() {
|
737 |
-
const settings = {
|
738 |
-
model: localStorage.getItem('selectedModel') || 'Qwen/Qwen2.5-Coder-32B-Instruct',
|
739 |
-
ocrModel: localStorage.getItem('selectedOcrModel') || 'none',
|
740 |
-
primarySystemPrompt: localStorage.getItem('primarySystemPrompt') || 'You are a powerful AI assistant that excels at understanding code, images, and technical content. Provide clear, accurate, and helpful responses. Focus on practical solutions and detailed explanations.',
|
741 |
-
ocrSystemPrompt: localStorage.getItem('ocrSystemPrompt') || 'Extract all text from the provided image clearly and accurately. Preserve formatting, structure, and layout when possible. If text is unclear, indicate uncertain parts.',
|
742 |
-
codeTemplate: localStorage.getItem('codeTemplate') || '```javascript\n// Enhanced code implementation\nfunction solution() {\n // Your optimized code here\n return result;\n}\n```',
|
743 |
-
additionalInstructions: localStorage.getItem('additionalInstructions') || 'Always provide working, tested code examples. Include error handling and optimization suggestions. Explain complex concepts step by step. Use modern best practices.',
|
744 |
-
promptPrefix: localStorage.getItem('promptPrefix') || 'Please analyze the following request carefully and provide a comprehensive solution:',
|
745 |
-
promptSuffix: localStorage.getItem('promptSuffix') || 'Ensure your response is complete, accurate, and includes practical examples where applicable.'
|
746 |
-
};
|
747 |
-
|
748 |
-
document.getElementById('modelSelect').value = settings.model;
|
749 |
-
document.getElementById('ocrModelSelect').value = settings.ocrModel;
|
750 |
-
document.getElementById('primarySystemPrompt').value = settings.primarySystemPrompt;
|
751 |
-
document.getElementById('ocrSystemPrompt').value = settings.ocrSystemPrompt;
|
752 |
-
document.getElementById('codeTemplate').value = settings.codeTemplate;
|
753 |
-
document.getElementById('additionalInstructions').value = settings.additionalInstructions;
|
754 |
-
document.getElementById('promptPrefix').value = settings.promptPrefix;
|
755 |
-
document.getElementById('promptSuffix').value = settings.promptSuffix;
|
756 |
-
}
|
757 |
-
|
758 |
-
function saveSettings() {
|
759 |
-
localStorage.setItem('selectedModel', document.getElementById('modelSelect').value);
|
760 |
-
localStorage.setItem('selectedOcrModel', document.getElementById('ocrModelSelect').value);
|
761 |
-
localStorage.setItem('primarySystemPrompt', document.getElementById('primarySystemPrompt').value);
|
762 |
-
localStorage.setItem('ocrSystemPrompt', document.getElementById('ocrSystemPrompt').value);
|
763 |
-
localStorage.setItem('codeTemplate', document.getElementById('codeTemplate').value);
|
764 |
-
localStorage.setItem('additionalInstructions', document.getElementById('additionalInstructions').value);
|
765 |
-
localStorage.setItem('promptPrefix', document.getElementById('promptPrefix').value);
|
766 |
-
localStorage.setItem('promptSuffix', document.getElementById('promptSuffix').value);
|
767 |
-
showNotification('บันทึกการตั้งค่าแล้ว!', 'success');
|
768 |
-
}
|
769 |
-
|
770 |
-
// Event listeners setup
|
771 |
-
function setupEventListeners() {
|
772 |
-
// Mode toggle
|
773 |
-
document.getElementById('carouselModeBtn').addEventListener('click', () => switchMode('carousel'));
|
774 |
-
document.getElementById('chatModeBtn').addEventListener('click', () => switchMode('chat'));
|
775 |
-
// Settings
|
776 |
-
document.getElementById('saveSettingsBtn').addEventListener('click', saveSettings);
|
777 |
-
document.getElementById('settingsToggle').addEventListener('click', toggleSettings);
|
778 |
-
// Carousel controls - Using 'click' for better cross-device compatibility
|
779 |
-
document.getElementById('prevCard').addEventListener('click', () => rotateCarousel(-1));
|
780 |
-
document.getElementById('nextCard').addEventListener('click', () => rotateCarousel(1));
|
781 |
-
document.getElementById('applyPromptBtn').addEventListener('click', applyPromptsAndSwitchToChat);
|
782 |
-
// Chat controls
|
783 |
-
document.getElementById('sendButton').addEventListener('click', sendMessage);
|
784 |
-
document.getElementById('attachButton').addEventListener('click', () => document.getElementById('fileInput').click());
|
785 |
-
document.getElementById('fileInput').addEventListener('change', handleFileSelect);
|
786 |
-
document.getElementById('userInput').addEventListener('keydown', handleKeyDown);
|
787 |
-
// Other controls
|
788 |
-
document.getElementById('fullscreenToggle').addEventListener('click', toggleFullscreen);
|
789 |
-
document.getElementById('refreshBtn').addEventListener('click', refreshApp);
|
790 |
-
// Quick prompts
|
791 |
-
document.querySelectorAll('.chip').forEach(chip => {
|
792 |
-
chip.addEventListener('click', (e) => {
|
793 |
-
const prompt = e.target.getAttribute('data-prompt');
|
794 |
-
document.getElementById('userInput').value = prompt;
|
795 |
-
document.getElementById('userInput').focus();
|
796 |
-
});
|
797 |
-
});
|
798 |
-
// Carousel dots
|
799 |
-
document.querySelectorAll('.carousel-dot').forEach(dot => {
|
800 |
-
dot.addEventListener('click', (e) => {
|
801 |
-
const index = parseInt(e.target.getAttribute('data-index'));
|
802 |
-
goToCarouselIndex(index);
|
803 |
-
});
|
804 |
-
});
|
805 |
-
}
|
806 |
-
|
807 |
-
// Mode switching
|
808 |
-
function switchMode(mode) {
|
809 |
-
const carouselMode = document.getElementById('carouselMode');
|
810 |
-
const chatMode = document.getElementById('chatMode');
|
811 |
-
const carouselBtn = document.getElementById('carouselModeBtn');
|
812 |
-
const chatBtn = document.getElementById('chatModeBtn');
|
813 |
-
const slider = document.getElementById('modeToggleSlider');
|
814 |
-
|
815 |
-
if (mode === 'carousel') {
|
816 |
-
carouselMode.style.display = 'flex'; // Use flex for centering
|
817 |
-
chatMode.style.display = 'none';
|
818 |
-
carouselBtn.classList.add('active');
|
819 |
-
chatBtn.classList.remove('active');
|
820 |
-
slider.style.left = '5px';
|
821 |
-
slider.style.width = 'calc(50% - 5px)';
|
822 |
-
} else {
|
823 |
-
carouselMode.style.display = 'none';
|
824 |
-
chatMode.style.display = 'flex'; // Use flex for layout
|
825 |
-
carouselBtn.classList.remove('active');
|
826 |
-
chatBtn.classList.add('active');
|
827 |
-
slider.style.left = 'calc(50% + 0px)'; // Adjusted position
|
828 |
-
slider.style.width = 'calc(50% - 5px)';
|
829 |
-
}
|
830 |
-
}
|
831 |
-
|
832 |
-
// Carousel functionality
|
833 |
-
function setupCarousel() {
|
834 |
-
const carousel = document.getElementById('promptCarousel');
|
835 |
-
const cards = carousel.querySelectorAll('.carousel-card');
|
836 |
-
const cardWidth = cards[0].offsetWidth; // Get card width
|
837 |
-
const totalCards = cards.length;
|
838 |
-
const angle = 360 / totalCards;
|
839 |
-
const translateZ = (cardWidth / 2) / Math.tan( (angle / 2) * (Math.PI / 180) ); // Calculate translateZ dynamically
|
840 |
-
|
841 |
-
cards.forEach((card, index) => {
|
842 |
-
const cardAngle = index * angle;
|
843 |
-
card.style.transform = `rotateY(${cardAngle}deg) translateZ(${translateZ}px)`;
|
844 |
-
});
|
845 |
-
|
846 |
-
// Store translateZ for rotation
|
847 |
-
carousel.dataset.translateZ = translateZ;
|
848 |
-
updateCarouselPosition();
|
849 |
-
}
|
850 |
-
|
851 |
-
|
852 |
-
function rotateCarousel(direction) {
|
853 |
-
const totalCards = 6;
|
854 |
-
currentCarouselIndex = (currentCarouselIndex + direction + totalCards) % totalCards;
|
855 |
-
updateCarouselPosition();
|
856 |
-
}
|
857 |
-
|
858 |
-
function goToCarouselIndex(index) {
|
859 |
-
currentCarouselIndex = index;
|
860 |
-
updateCarouselPosition();
|
861 |
-
}
|
862 |
-
|
863 |
-
function updateCarouselPosition() {
|
864 |
-
const carousel = document.getElementById('promptCarousel');
|
865 |
-
const cards = carousel.querySelectorAll('.carousel-card');
|
866 |
-
const dots = document.querySelectorAll('.carousel-dot');
|
867 |
-
const totalCards = cards.length;
|
868 |
-
const anglePerCard = 360 / totalCards;
|
869 |
-
const rotationAngle = -currentCarouselIndex * anglePerCard;
|
870 |
-
const translateZ = carousel.dataset.translateZ || 350; // Use stored or default
|
871 |
-
|
872 |
-
carousel.style.transform = `translateZ(-${translateZ}px) rotateY(${rotationAngle}deg)`;
|
873 |
-
|
874 |
-
cards.forEach((card, index) => {
|
875 |
-
const isActive = index === currentCarouselIndex;
|
876 |
-
card.style.opacity = isActive ? '1' : '0.6';
|
877 |
-
card.style.cursor = isActive ? 'default' : 'pointer'; // Make non-active cards clickable? Maybe not.
|
878 |
-
// No need to change individual card transforms here, only opacity/etc.
|
879 |
-
});
|
880 |
|
881 |
-
|
882 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
883 |
});
|
884 |
-
}
|
885 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
886 |
|
887 |
-
|
888 |
-
|
889 |
-
|
890 |
-
|
891 |
-
|
|
|
|
|
|
|
892 |
|
893 |
-
|
894 |
-
|
895 |
-
|
896 |
-
|
|
|
|
|
897 |
|
898 |
-
|
899 |
-
|
900 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
901 |
|
902 |
-
|
903 |
-
|
904 |
-
e.stopPropagation();
|
905 |
-
}
|
906 |
|
907 |
-
|
908 |
-
|
909 |
-
|
910 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
911 |
}
|
912 |
-
}
|
913 |
-
});
|
914 |
-
|
915 |
-
['dragleave', 'drop'].forEach(eventName => {
|
916 |
-
appContainer.addEventListener(eventName, () => dropzone.classList.remove('active'), false);
|
917 |
-
});
|
918 |
-
|
919 |
-
appContainer.addEventListener('drop', handleDrop, false);
|
920 |
-
}
|
921 |
-
|
922 |
-
function handleDrop(e) {
|
923 |
-
if (document.getElementById('chatMode').style.display === 'none') return;
|
924 |
-
const dt = e.dataTransfer;
|
925 |
-
const files = dt.files;
|
926 |
-
handleFiles(files);
|
927 |
-
}
|
928 |
-
|
929 |
-
function handleFileSelect(e) {
|
930 |
-
const files = e.target.files;
|
931 |
-
handleFiles(files);
|
932 |
-
}
|
933 |
-
|
934 |
-
function handleFiles(files) {
|
935 |
-
attachedFiles.push(...Array.from(files).filter(f => f.type.startsWith('image/'))); // Only add images
|
936 |
-
updateFileDisplay();
|
937 |
-
if (attachedFiles.length > 0) {
|
938 |
-
showNotification(`${attachedFiles.length} รูปถูกแนบแล้ว`, 'success');
|
939 |
-
}
|
940 |
-
}
|
941 |
-
|
942 |
-
function updateFileDisplay() {
|
943 |
-
const fileName = document.getElementById('fileName');
|
944 |
-
if (attachedFiles.length === 0) {
|
945 |
-
fileName.textContent = '';
|
946 |
-
} else if (attachedFiles.length === 1) {
|
947 |
-
fileName.textContent = attachedFiles[0].name;
|
948 |
-
} else {
|
949 |
-
fileName.textContent = `${attachedFiles.length} ไฟล์`;
|
950 |
-
}
|
951 |
-
}
|
952 |
-
|
953 |
-
// Chat functionality
|
954 |
-
function handleKeyDown(e) {
|
955 |
-
if (e.key === 'Enter' && !e.shiftKey) {
|
956 |
-
e.preventDefault();
|
957 |
-
sendMessage();
|
958 |
-
}
|
959 |
-
}
|
960 |
-
|
961 |
-
async function sendMessage() {
|
962 |
-
const userInput = document.getElementById('userInput');
|
963 |
-
const message = userInput.value.trim();
|
964 |
-
|
965 |
-
if (!message && attachedFiles.length === 0) return;
|
966 |
-
if (isLoading) return;
|
967 |
-
|
968 |
-
setLoading(true);
|
969 |
-
const chatContainer = document.getElementById('chatContainer');
|
970 |
-
const userMessage = message; // Keep a copy
|
971 |
-
|
972 |
-
// Add user message
|
973 |
-
if (userMessage) {
|
974 |
-
addMessage(userMessage, 'user');
|
975 |
-
}
|
976 |
-
|
977 |
-
// Add file previews and clear input/files
|
978 |
-
const currentFiles = [...attachedFiles];
|
979 |
-
attachedFiles = [];
|
980 |
-
userInput.value = '';
|
981 |
-
updateFileDisplay();
|
982 |
-
|
983 |
-
for (const file of currentFiles) {
|
984 |
-
const imageUrl = URL.createObjectURL(file);
|
985 |
-
addImageMessage(imageUrl, 'user');
|
986 |
-
}
|
987 |
-
|
988 |
-
chatContainer.scrollTop = chatContainer.scrollHeight;
|
989 |
-
|
990 |
-
try {
|
991 |
-
const response = await callHuggingFaceAPI(userMessage, currentFiles);
|
992 |
-
addMessage(response, 'ai');
|
993 |
-
} catch (error) {
|
994 |
-
console.error('Error:', error);
|
995 |
-
addMessage('ขออภัย, เกิดข้อผิดพลาดในการประมวลผล โปรดลองอีกครั้ง', 'ai');
|
996 |
-
showNotification('Error: ' + error.message, 'error');
|
997 |
-
} finally {
|
998 |
-
setLoading(false);
|
999 |
-
chatContainer.scrollTop = chatContainer.scrollHeight;
|
1000 |
-
}
|
1001 |
-
}
|
1002 |
-
|
1003 |
-
async function callHuggingFaceAPI(message, files) {
|
1004 |
-
const model = document.getElementById('modelSelect').value;
|
1005 |
-
const primaryPrompt = document.getElementById('primarySystemPrompt').value;
|
1006 |
-
const prefix = document.getElementById('promptPrefix').value;
|
1007 |
-
const suffix = document.getElementById('promptSuffix').value;
|
1008 |
-
const ocrModel = document.getElementById('ocrModelSelect').value;
|
1009 |
-
|
1010 |
-
let fullPrompt = `${primaryPrompt}\n\n${prefix}\n\nUser: ${message}`;
|
1011 |
-
|
1012 |
-
// Handle OCR and image data based on model
|
1013 |
-
let imageInput = null;
|
1014 |
-
if (files.length > 0) {
|
1015 |
-
const file = files[0]; // Assuming one image for simplicity now
|
1016 |
-
const reader = new FileReader();
|
1017 |
-
imageInput = await new Promise((resolve) => {
|
1018 |
-
reader.onloadend = () => resolve(reader.result.split(',')[1]); // Base64
|
1019 |
-
reader.readAsDataURL(file);
|
1020 |
-
});
|
1021 |
|
1022 |
-
|
1023 |
-
|
1024 |
-
|
1025 |
-
|
1026 |
-
|
1027 |
-
|
1028 |
-
|
1029 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1030 |
} else {
|
1031 |
-
|
|
|
1032 |
}
|
1033 |
}
|
1034 |
|
1035 |
-
fullPrompt += `\n\n${suffix}\n\nAI:`;
|
1036 |
|
1037 |
-
|
1038 |
-
|
1039 |
-
|
1040 |
-
|
|
|
|
|
1041 |
|
1042 |
-
|
1043 |
-
|
1044 |
-
|
|
|
|
|
|
|
1045 |
|
1046 |
-
const response = await fetch(`https://api-inference.huggingface.co/models/${model}`, {
|
1047 |
-
method: 'POST',
|
1048 |
-
headers: {
|
1049 |
-
'Authorization': `Bearer ${HUGGINGFACE_TOKEN}`,
|
1050 |
-
'Content-Type': 'application/json',
|
1051 |
-
},
|
1052 |
-
body: JSON.stringify(payload)
|
1053 |
-
});
|
1054 |
|
1055 |
-
|
1056 |
-
const
|
1057 |
-
|
1058 |
-
|
|
|
|
|
|
|
|
|
|
|
1059 |
}
|
1060 |
|
1061 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1062 |
|
1063 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1064 |
|
1065 |
-
|
1066 |
-
|
1067 |
-
|
1068 |
-
|
1069 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1070 |
}
|
1071 |
|
1072 |
-
|
1073 |
-
|
|
|
|
|
|
|
1074 |
|
1075 |
-
|
1076 |
-
|
1077 |
-
|
1078 |
-
|
1079 |
-
|
1080 |
-
|
1081 |
-
|
1082 |
-
|
1083 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1084 |
|
1085 |
-
|
1086 |
-
|
1087 |
-
|
1088 |
}
|
1089 |
|
1090 |
-
const data = await response.json();
|
1091 |
-
// OCR models have varying outputs, check common ones
|
1092 |
-
return data[0]?.generated_text || data.generated_text || data.text || 'ไม่สามารถอ่านข้อความได้';
|
1093 |
-
}
|
1094 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1095 |
|
1096 |
-
|
1097 |
-
|
1098 |
-
|
1099 |
-
messageDiv.className = `message ${sender}`;
|
1100 |
|
1101 |
-
|
1102 |
-
|
1103 |
-
|
1104 |
-
|
1105 |
-
|
1106 |
-
|
1107 |
-
|
1108 |
-
|
1109 |
-
|
1110 |
-
|
1111 |
-
|
1112 |
-
|
1113 |
-
|
1114 |
-
|
1115 |
-
|
1116 |
-
|
1117 |
-
|
1118 |
-
|
1119 |
-
|
1120 |
-
|
1121 |
-
|
1122 |
-
|
1123 |
-
|
1124 |
-
|
1125 |
-
|
1126 |
-
|
1127 |
-
|
1128 |
-
|
1129 |
-
|
1130 |
-
|
1131 |
-
|
1132 |
-
|
1133 |
-
|
1134 |
-
|
1135 |
-
|
1136 |
-
|
1137 |
-
|
1138 |
-
|
1139 |
-
|
1140 |
-
|
1141 |
-
|
1142 |
-
|
1143 |
-
|
1144 |
-
|
1145 |
-
|
1146 |
-
|
1147 |
-
|
1148 |
-
|
1149 |
-
|
1150 |
-
|
1151 |
-
|
1152 |
-
|
1153 |
-
|
1154 |
-
|
1155 |
-
|
1156 |
-
|
1157 |
-
|
1158 |
-
|
1159 |
-
|
1160 |
-
|
1161 |
-
|
1162 |
-
|
1163 |
-
|
1164 |
-
|
1165 |
-
|
1166 |
-
|
1167 |
-
|
1168 |
-
|
1169 |
-
|
1170 |
-
|
1171 |
-
|
1172 |
-
|
1173 |
-
|
1174 |
-
|
1175 |
-
|
1176 |
-
|
1177 |
-
|
1178 |
-
|
1179 |
-
|
1180 |
-
|
1181 |
-
|
1182 |
-
|
1183 |
-
|
1184 |
-
|
1185 |
-
|
1186 |
-
|
1187 |
-
|
1188 |
-
|
1189 |
-
|
1190 |
-
|
1191 |
-
|
1192 |
-
|
1193 |
-
|
1194 |
-
|
1195 |
-
|
1196 |
-
|
1197 |
-
|
1198 |
-
|
1199 |
-
|
1200 |
-
|
1201 |
-
|
1202 |
-
|
1203 |
-
|
1204 |
-
|
1205 |
-
|
1206 |
-
|
1207 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1208 |
</body>
|
1209 |
</html>
|
|
|
1 |
<!DOCTYPE html>
|
2 |
<html lang="th">
|
3 |
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
|
6 |
+
<title>AI Chatbot - Cyber Material</title>
|
7 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/atom-one-dark.min.css">
|
8 |
+
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
9 |
+
<link rel="preconnect" href="https://fonts.googleapis.com">
|
10 |
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
11 |
+
<link href="https://fonts.googleapis.com/css2?family=Courier+Prime:wght@400;700&family=Roboto+Mono:wght@300;400;500&display=swap" rel="stylesheet">
|
12 |
+
|
13 |
+
<style>
|
14 |
+
:root {
|
15 |
+
--bg-primary: #08080a; /* เกือบดำ */
|
16 |
+
--bg-secondary: #18181b; /* เทาเข้ม */
|
17 |
+
--bg-tertiary: #27272a; /* เทาเข้มกลาง */
|
18 |
+
--bg-cream: #f4f1ea; /* ครีม */
|
19 |
+
--text-primary: #e0e0e0; /* ขาวนวล */
|
20 |
+
--text-secondary: #a0a0a0; /* เทา */
|
21 |
+
--text-dark: #1f1f1f; /* ดำสำหรับพื้นครีม */
|
22 |
+
--accent-green: #00ffab; /* เขียวไซเบอร์ */
|
23 |
+
--accent-orange: #ff8c00; /* ส้มไซเบอร์ */
|
24 |
+
--accent-brown: #a0522d; /* น้ำตาล */
|
25 |
+
--border-color: rgba(0, 255, 171, 0.2);
|
26 |
+
--shadow-color-green: rgba(0, 255, 171, 0.3);
|
27 |
+
--shadow-color-orange: rgba(255, 140, 0, 0.3);
|
28 |
+
--font-main: 'Roboto Mono', 'Courier Prime', 'Courier New', monospace;
|
29 |
+
--font-code: 'Courier Prime', 'Courier New', monospace;
|
30 |
+
}
|
31 |
+
|
32 |
+
* {
|
33 |
+
box-sizing: border-box;
|
34 |
+
margin: 0;
|
35 |
+
padding: 0;
|
36 |
+
scrollbar-width: thin;
|
37 |
+
scrollbar-color: var(--accent-green) transparent;
|
38 |
+
}
|
39 |
+
|
40 |
+
*::-webkit-scrollbar { width: 5px; }
|
41 |
+
*::-webkit-scrollbar-track { background: transparent; }
|
42 |
+
*::-webkit-scrollbar-thumb { background: var(--accent-green); border-radius: 3px; }
|
43 |
+
|
44 |
+
body {
|
45 |
+
font-family: var(--font-main);
|
46 |
+
background: var(--bg-primary);
|
47 |
+
color: var(--text-primary);
|
48 |
+
display: flex;
|
49 |
+
justify-content: center;
|
50 |
+
align-items: center;
|
51 |
+
min-height: 100vh;
|
52 |
+
overflow: hidden;
|
53 |
+
-webkit-tap-highlight-color: transparent; /* สำคัญสำหรับทัช */
|
54 |
+
font-weight: 300;
|
55 |
+
}
|
56 |
+
|
57 |
+
.app-container {
|
58 |
+
width: 100%;
|
59 |
+
height: 100%;
|
60 |
+
max-width: 1600px; /* ขยายสำหรับแท็บเล็ต */
|
61 |
+
max-height: 100vh; /* เต็มจอ */
|
62 |
+
background: var(--bg-secondary);
|
63 |
+
border: 1px solid var(--border-color);
|
64 |
+
border-radius: 0; /* เต็มจอ */
|
65 |
+
box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
|
66 |
+
display: flex;
|
67 |
+
overflow: hidden;
|
68 |
+
position: relative;
|
69 |
+
}
|
70 |
+
|
71 |
+
/* --- Panel ทั่วไป --- */
|
72 |
+
.panel {
|
73 |
+
background: var(--bg-secondary);
|
74 |
+
transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
|
75 |
+
position: absolute;
|
76 |
+
top: 0;
|
77 |
+
bottom: 0;
|
78 |
+
z-index: 200;
|
79 |
+
display: flex;
|
80 |
+
flex-direction: column;
|
81 |
+
padding: 25px;
|
82 |
+
box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
|
83 |
+
border-color: var(--border-color);
|
84 |
+
}
|
85 |
+
|
86 |
+
/* --- Settings Panel (ซ้าย) --- */
|
87 |
+
.settings-panel {
|
88 |
+
left: 0;
|
89 |
+
width: 320px;
|
90 |
+
border-right: 1px solid var(--border-color);
|
91 |
+
transform: translateX(0);
|
92 |
+
}
|
93 |
+
.settings-panel.collapsed {
|
94 |
+
transform: translateX(-100%);
|
95 |
+
}
|
96 |
+
|
97 |
+
/* --- Prompt Panel (ขวา) --- */
|
98 |
+
.prompt-panel {
|
99 |
+
right: 0;
|
100 |
+
width: 400px;
|
101 |
+
border-left: 1px solid var(--border-color);
|
102 |
+
transform: translateX(0);
|
103 |
+
}
|
104 |
+
.prompt-panel.collapsed {
|
105 |
+
transform: translateX(100%);
|
106 |
+
}
|
107 |
+
|
108 |
+
/* --- Main Content (กลาง) --- */
|
109 |
+
.main-content {
|
110 |
+
flex: 1;
|
111 |
+
display: flex;
|
112 |
+
flex-direction: column;
|
113 |
+
position: relative;
|
114 |
+
background: var(--bg-primary);
|
115 |
+
transition: margin 0.5s cubic-bezier(0.4, 0, 0.2, 1);
|
116 |
+
margin-left: 320px; /* Default margin */
|
117 |
+
margin-right: 400px; /* Default margin */
|
118 |
+
height: 100%;
|
119 |
+
}
|
120 |
+
|
121 |
+
/* --- การปรับ Margin เมื่อ Panel ยุบ --- */
|
122 |
+
.main-content.settings-collapsed { margin-left: 0; }
|
123 |
+
.main-content.prompts-collapsed { margin-right: 0; }
|
124 |
+
|
125 |
+
/* --- UI Elements --- */
|
126 |
+
h2 {
|
127 |
+
font-size: 1.3rem;
|
128 |
+
margin-bottom: 25px;
|
129 |
+
color: var(--accent-green);
|
130 |
+
font-weight: 500;
|
131 |
+
border-bottom: 1px solid var(--border-color);
|
132 |
+
padding-bottom: 10px;
|
133 |
+
}
|
134 |
+
|
135 |
+
.form-field { margin-bottom: 20px; }
|
136 |
+
.form-field label {
|
137 |
+
display: block;
|
138 |
+
margin-bottom: 8px;
|
139 |
+
font-size: 0.85rem;
|
140 |
+
font-weight: 400;
|
141 |
+
color: var(--text-secondary);
|
142 |
+
text-transform: uppercase;
|
143 |
+
letter-spacing: 1px;
|
144 |
+
}
|
145 |
+
|
146 |
+
.form-field select, .form-field textarea {
|
147 |
+
width: 100%;
|
148 |
+
padding: 12px 15px;
|
149 |
+
border: 1px solid var(--border-color);
|
150 |
+
border-radius: 4px; /* Material Flat */
|
151 |
+
background: var(--bg-tertiary);
|
152 |
+
color: var(--text-primary);
|
153 |
+
font-size: 0.9rem;
|
154 |
+
font-family: var(--font-main);
|
155 |
+
transition: all 0.2s ease-in-out;
|
156 |
+
}
|
157 |
+
|
158 |
+
.form-field select:focus, .form-field textarea:focus {
|
159 |
+
outline: none;
|
160 |
+
border-color: var(--accent-green);
|
161 |
+
box-shadow: 0 0 10px var(--shadow-color-green);
|
162 |
+
}
|
163 |
+
|
164 |
+
.form-field textarea { resize: vertical; min-height: 90px; }
|
165 |
+
|
166 |
+
button {
|
167 |
+
padding: 12px 25px;
|
168 |
+
border: 1px solid var(--accent-green);
|
169 |
+
border-radius: 4px;
|
170 |
+
background: transparent;
|
171 |
+
color: var(--accent-green);
|
172 |
+
cursor: pointer;
|
173 |
+
font-size: 0.9rem;
|
174 |
+
font-weight: 500;
|
175 |
+
transition: all 0.2s ease-in-out;
|
176 |
+
touch-action: manipulation; /* สำคัญสำหรับทัช */
|
177 |
+
text-transform: uppercase;
|
178 |
+
font-family: var(--font-main);
|
179 |
+
}
|
180 |
+
|
181 |
+
button:hover, button.active {
|
182 |
+
background: var(--accent-green);
|
183 |
+
color: var(--bg-primary);
|
184 |
+
box-shadow: 0 0 12px var(--shadow-color-green);
|
185 |
+
}
|
186 |
+
|
187 |
+
button:active { transform: scale(0.97); }
|
188 |
+
|
189 |
+
.material-icons {
|
190 |
+
font-size: 22px;
|
191 |
+
vertical-align: middle;
|
192 |
+
line-height: 1; /* จัดแนว */
|
193 |
+
}
|
194 |
+
|
195 |
+
/* --- Chat Area --- */
|
196 |
+
.chat-container {
|
197 |
+
flex: 1;
|
198 |
+
padding: 25px;
|
199 |
+
overflow-y: auto;
|
200 |
+
display: flex;
|
201 |
+
flex-direction: column;
|
202 |
+
gap: 18px;
|
203 |
+
background: var(--bg-cream);
|
204 |
+
color: var(--text-dark);
|
205 |
+
}
|
206 |
+
|
207 |
+
.message {
|
208 |
+
max-width: 80%;
|
209 |
+
padding: 15px 20px;
|
210 |
+
border-radius: 6px; /* Flat edges */
|
211 |
+
font-size: 0.95rem;
|
212 |
+
line-height: 1.6;
|
213 |
+
position: relative;
|
214 |
+
animation: messageSlide 0.4s ease-out forwards;
|
215 |
+
opacity: 0;
|
216 |
+
transform: translateY(15px);
|
217 |
+
font-family: 'Roboto', 'Segoe UI', sans-serif; /* Font อ่านง่ายสำหรับแชท */
|
218 |
+
font-weight: 400;
|
219 |
+
}
|
220 |
+
|
221 |
+
@keyframes messageSlide { to { opacity: 1; transform: translateY(0); } }
|
222 |
+
|
223 |
+
.message.user {
|
224 |
+
background: var(--accent-orange);
|
225 |
+
align-self: flex-end;
|
226 |
+
color: #fff;
|
227 |
+
box-shadow: 0 4px 8px var(--shadow-color-orange);
|
228 |
+
}
|
229 |
+
|
230 |
+
.message.ai {
|
231 |
+
background: #ffffff;
|
232 |
+
align-self: flex-start;
|
233 |
+
border: 1px solid #e0e0e0;
|
234 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.05);
|
235 |
+
}
|
236 |
+
|
237 |
+
.message.ai pre {
|
238 |
+
background: #1e1e1e; /* Darker code bg */
|
239 |
+
color: #d4d4d4;
|
240 |
+
padding: 18px;
|
241 |
+
border-radius: 4px;
|
242 |
+
overflow-x: auto;
|
243 |
+
border: 1px solid #333;
|
244 |
+
margin-top: 12px;
|
245 |
+
position: relative;
|
246 |
+
}
|
247 |
+
.message.ai pre code {
|
248 |
+
font-family: var(--font-code);
|
249 |
+
font-size: 0.85rem;
|
250 |
+
font-weight: 400; /* Thin */
|
251 |
+
background: none !important;
|
252 |
+
color: inherit !important;
|
253 |
+
}
|
254 |
+
|
255 |
+
.code-tools {
|
256 |
+
position: absolute;
|
257 |
+
top: 8px; right: 8px;
|
258 |
+
display: flex; gap: 6px;
|
259 |
+
opacity: 0; transition: opacity 0.3s ease;
|
260 |
+
}
|
261 |
+
pre:hover .code-tools { opacity: 1; }
|
262 |
+
.code-tools button {
|
263 |
+
padding: 5px 10px; font-size: 0.75rem;
|
264 |
+
background: #333; color: var(--accent-green);
|
265 |
+
border: 1px solid var(--accent-green);
|
266 |
+
}
|
267 |
+
.code-tools button:hover { background: var(--accent-green); color: #1e1e1e; }
|
268 |
+
|
269 |
+
/* --- Input Area --- */
|
270 |
+
.input-container {
|
271 |
+
display: flex;
|
272 |
+
gap: 10px;
|
273 |
+
padding: 15px;
|
274 |
+
background: var(--bg-secondary);
|
275 |
+
border-top: 1px solid var(--border-color);
|
276 |
+
align-items: center;
|
277 |
+
}
|
278 |
+
|
279 |
+
#userInput {
|
280 |
+
flex: 1;
|
281 |
+
padding: 15px 18px;
|
282 |
+
border: 1px solid var(--border-color);
|
283 |
+
border-radius: 4px;
|
284 |
+
background: var(--bg-tertiary);
|
285 |
+
color: var(--text-primary);
|
286 |
+
resize: none;
|
287 |
+
min-height: 54px;
|
288 |
+
max-height: 150px;
|
289 |
+
font-size: 0.95rem;
|
290 |
+
font-family: var(--font-main);
|
291 |
+
transition: all 0.2s ease-in-out;
|
292 |
+
}
|
293 |
+
#userInput:focus {
|
294 |
+
outline: none;
|
295 |
+
border-color: var(--accent-orange);
|
296 |
+
box-shadow: 0 0 10px var(--shadow-color-orange);
|
297 |
+
}
|
298 |
+
|
299 |
+
.input-btn {
|
300 |
+
width: 54px; height: 54px;
|
301 |
+
border-radius: 4px;
|
302 |
+
display: flex;
|
303 |
+
align-items: center;
|
304 |
+
justify-content: center;
|
305 |
+
padding: 0;
|
306 |
+
border-color: var(--accent-orange);
|
307 |
+
color: var(--accent-orange);
|
308 |
+
}
|
309 |
+
.input-btn:hover {
|
310 |
+
background: var(--accent-orange);
|
311 |
+
color: var(--bg-primary);
|
312 |
+
box-shadow: 0 0 12px var(--shadow-color-orange);
|
313 |
+
}
|
314 |
+
.input-btn:disabled {
|
315 |
+
background: var(--bg-tertiary); color: #555;
|
316 |
+
border-color: #444; cursor: not-allowed;
|
317 |
+
box-shadow: none; opacity: 0.5;
|
318 |
+
}
|
319 |
+
.spinner {
|
320 |
+
width: 24px; height: 24px;
|
321 |
+
border: 3px solid rgba(255, 140, 0, 0.3);
|
322 |
+
border-top: 3px solid var(--accent-orange);
|
323 |
+
border-radius: 50%;
|
324 |
+
animation: spin 1s linear infinite;
|
325 |
+
}
|
326 |
+
@keyframes spin { to { transform: rotate(360deg); } }
|
327 |
+
|
328 |
+
/* --- Carousel --- */
|
329 |
+
.carousel-container {
|
330 |
+
perspective: 1000px;
|
331 |
+
height: 100%;
|
332 |
+
display: flex;
|
333 |
+
flex-direction: column;
|
334 |
+
align-items: center;
|
335 |
+
justify-content: center;
|
336 |
+
position: relative;
|
337 |
+
user-select: none;
|
338 |
+
padding: 20px;
|
339 |
+
flex: 1; /* ให้เต็มพื้นที่ */
|
340 |
+
overflow: hidden; /* ป้องกันการล้น */
|
341 |
+
}
|
342 |
+
.carousel {
|
343 |
+
position: relative;
|
344 |
+
width: 95%;
|
345 |
+
max-width: 350px; /* ลดขนาดให้พอดี Panel */
|
346 |
+
height: 280px; /* ลดขนาด */
|
347 |
+
transform-style: preserve-3d;
|
348 |
+
transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
|
349 |
+
cursor: grab;
|
350 |
+
}
|
351 |
+
.carousel.dragging { cursor: grabbing; }
|
352 |
+
.carousel-card {
|
353 |
+
position: absolute;
|
354 |
+
width: 100%; height: 100%;
|
355 |
+
background: var(--bg-tertiary);
|
356 |
+
border: 1px solid var(--border-color);
|
357 |
+
border-radius: 6px;
|
358 |
+
padding: 20px;
|
359 |
+
box-shadow: 0 5px 15px rgba(0,0,0,0.3);
|
360 |
+
display: flex;
|
361 |
+
flex-direction: column;
|
362 |
+
gap: 10px;
|
363 |
+
transition: all 0.6s cubic-bezier(0.4, 0, 0.2, 1);
|
364 |
+
backface-visibility: hidden;
|
365 |
+
}
|
366 |
+
.carousel-card label { font-size: 0.8rem; }
|
367 |
+
.carousel-card textarea { font-size: 0.85rem; min-height: 150px; }
|
368 |
+
.carousel-controls, .carousel-indicator {
|
369 |
+
display: flex; gap: 15px; margin-top: 20px;
|
370 |
+
}
|
371 |
+
.carousel-controls button {
|
372 |
+
padding: 8px; width: 40px; height: 40px;
|
373 |
+
border-radius: 50%; display: flex;
|
374 |
+
align-items: center; justify-content: center;
|
375 |
+
}
|
376 |
+
.carousel-dot {
|
377 |
+
width: 12px; height: 12px;
|
378 |
+
background: var(--bg-tertiary);
|
379 |
+
border-radius: 50%;
|
380 |
+
cursor: pointer;
|
381 |
+
transition: all 0.3s ease;
|
382 |
+
border: 1px solid var(--accent-green);
|
383 |
+
}
|
384 |
+
.carousel-dot.active { background: var(--accent-green); transform: scale(1.3); }
|
385 |
+
|
386 |
+
/* --- Floating Buttons --- */
|
387 |
+
.floating-buttons {
|
388 |
+
position: absolute;
|
389 |
+
top: 15px;
|
390 |
+
left: 15px; /* เปลี่ยนมาซ้าย */
|
391 |
+
display: flex;
|
392 |
+
flex-direction: column; /* เรียงแนวตั้ง */
|
393 |
+
gap: 10px;
|
394 |
+
z-index: 300;
|
395 |
+
}
|
396 |
+
.floating-btn {
|
397 |
+
width: 44px; height: 44px;
|
398 |
+
border-radius: 50%;
|
399 |
+
background: var(--bg-tertiary);
|
400 |
+
border: 1px solid var(--border-color);
|
401 |
+
display: flex;
|
402 |
+
align-items: center;
|
403 |
+
justify-content: center;
|
404 |
+
transition: all 0.2s ease;
|
405 |
+
padding: 0;
|
406 |
+
color: var(--text-primary);
|
407 |
+
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
|
408 |
+
}
|
409 |
+
.floating-btn:hover {
|
410 |
+
background: var(--accent-green);
|
411 |
+
color: var(--bg-primary);
|
412 |
+
transform: scale(1.1);
|
413 |
+
box-shadow: 0 4px 12px var(--shadow-color-green);
|
414 |
+
}
|
415 |
+
#promptToggle { border-color: var(--accent-orange); color: var(--accent-orange); }
|
416 |
+
#promptToggle:hover { background: var(--accent-orange); color: var(--bg-primary); box-shadow: 0 4px 12px var(--shadow-color-orange); }
|
417 |
+
|
418 |
+
/* --- อื่นๆ --- */
|
419 |
+
.dropzone {
|
420 |
+
position: absolute; top: 0; left: 0; right: 0; bottom: 0;
|
421 |
+
background: rgba(0, 255, 171, 0.1);
|
422 |
+
border: 2px dashed var(--accent-green);
|
423 |
+
display: none; align-items: center; justify-content: center;
|
424 |
+
color: var(--accent-green); font-size: 1.3rem; z-index: 150;
|
425 |
+
}
|
426 |
+
.dropzone.active { display: flex; }
|
427 |
+
.file-name {
|
428 |
+
font-size: 0.8rem; color: var(--accent-green);
|
429 |
+
margin-left: 10px; align-self: center;
|
430 |
+
max-width: 150px; white-space: nowrap;
|
431 |
+
overflow: hidden; text-overflow: ellipsis;
|
432 |
+
}
|
433 |
+
.notification {
|
434 |
+
position: fixed; bottom: 20px; left: 50%;
|
435 |
+
transform: translateX(-50%);
|
436 |
+
padding: 12px 20px; border-radius: 4px;
|
437 |
+
color: #fff; font-size: 0.9rem; z-index: 1000;
|
438 |
+
display: none; background: #333;
|
439 |
+
border: 1px solid var(--border-color);
|
440 |
+
animation: notificationFade 3.5s ease forwards;
|
441 |
+
}
|
442 |
+
.notification.error-message { background: #d32f2f; border-color: #d32f2f; }
|
443 |
+
.notification.success-message { background: #388e3c; border-color: #388e3c; }
|
444 |
+
@keyframes notificationFade {
|
445 |
+
0% { opacity: 0; transform: translate(-50%, 20px); }
|
446 |
+
15% { opacity: 1; transform: translate(-50%, 0); }
|
447 |
+
85% { opacity: 1; transform: translate(-50%, 0); }
|
448 |
+
100% { opacity: 0; transform: translate(-50%, -20px); }
|
449 |
+
}
|
450 |
+
|
451 |
+
/* --- Responsive for Tablet --- */
|
452 |
+
@media (max-width: 1024px) {
|
453 |
+
.settings-panel, .prompt-panel {
|
454 |
+
width: 280px;
|
455 |
+
transform: translateX(-100%); /* Start collapsed */
|
456 |
+
}
|
457 |
+
.prompt-panel { transform: translateX(100%); }
|
458 |
+
.settings-panel.open { transform: translateX(0); }
|
459 |
+
.prompt-panel.open { transform: translateX(0); }
|
460 |
+
.main-content { margin-left: 0; margin-right: 0; }
|
461 |
+
}
|
462 |
+
@media (max-width: 768px) {
|
463 |
+
.settings-panel, .prompt-panel { width: 100%; border: none; }
|
464 |
+
.floating-buttons { top: 10px; left: 10px; }
|
465 |
+
.chat-container { padding: 15px; }
|
466 |
+
.input-container { padding: 10px; }
|
467 |
+
#userInput { min-height: 50px; }
|
468 |
+
.input-btn { width: 50px; height: 50px; }
|
469 |
+
}
|
470 |
+
|
471 |
+
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
472 |
</head>
|
473 |
<body>
|
474 |
+
<div class="app-container" id="appContainer">
|
475 |
+
|
476 |
+
<div class="settings-panel panel" id="settingsPanel">
|
477 |
+
<h2>⚙️ ตั้งค่า</h2>
|
478 |
+
<div class="form-field">
|
479 |
+
<label>🤖 โมเดลหลัก:</label>
|
480 |
+
<select id="modelSelect">
|
481 |
+
<option value="Qwen/Qwen2.5-Coder-32B-Instruct">Qwen2.5-Coder 32B</option>
|
482 |
+
<option value="Qwen/Qwen2-VL-72B-Instruct">Qwen2-VL 72B (Image)</option>
|
483 |
+
<option value="microsoft/Florence-2-large">Florence-2 Large (Image)</option>
|
484 |
+
</select>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
485 |
</div>
|
486 |
+
<div class="form-field">
|
487 |
+
<label>👁️ โมเดล OCR:</label>
|
488 |
+
<select id="ocrModelSelect">
|
489 |
+
<option value="none">ไม่ใช้</option>
|
490 |
+
<option value="microsoft/trocr-base-printed">TrOCR Base</option>
|
491 |
+
</select>
|
492 |
</div>
|
493 |
+
<button id="saveSettingsBtn">💾 บันทึก</button>
|
494 |
+
<p style="font-size: 0.7rem; color: var(--text-secondary); margin-top: auto; padding-top: 20px;">
|
495 |
+
UI v2.1 - Cyber Material Touch.
|
496 |
+
</p>
|
497 |
+
</div>
|
498 |
+
|
499 |
+
<div class="main-content" id="mainContent">
|
500 |
+
<div class="chat-container" id="chatContainer">
|
501 |
+
<div class="message ai">สวัสดี! ฉันคือ AI Chatbot ที่พร้อมช่วยคุณ. เลือกโมเดลและเริ่มแชทได้เลย!</div>
|
502 |
</div>
|
503 |
+
<div class="input-container">
|
504 |
+
<button id="attachButton" class="input-btn"><span class="material-icons">attach_file</span></button>
|
505 |
+
<input type="file" id="fileInput" multiple accept="image/*" style="display: none;">
|
506 |
+
<span class="file-name" id="fileName"></span>
|
507 |
+
<textarea id="userInput" placeholder="พิมพ์ข้อความ..."></textarea>
|
508 |
+
<button id="sendButton" class="input-btn"><span class="material-icons">send</span></button>
|
509 |
</div>
|
510 |
+
<div class="dropzone" id="dropzone">📁 วางไฟล์ที่นี่</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
511 |
</div>
|
512 |
+
|
513 |
+
<div class="prompt-panel panel" id="promptPanel">
|
514 |
+
<h2>🎛️ แก้ไข Prompt</h2>
|
515 |
+
<div class="carousel-container">
|
516 |
+
<div class="carousel" id="promptCarousel">
|
517 |
+
</div>
|
518 |
+
<div class="carousel-controls">
|
519 |
+
<button id="prevCard"><span class="material-icons">chevron_left</span></button>
|
520 |
+
<button id="nextCard"><span class="material-icons">chevron_right</span></button>
|
521 |
+
</div>
|
522 |
+
<div class="carousel-indicator" id="carouselIndicator">
|
523 |
+
</div>
|
524 |
</div>
|
525 |
+
<button id="applyPromptBtn" style="margin-top: auto;">✅ ใช้ Prompt</button>
|
|
|
|
|
|
|
|
|
|
|
526 |
</div>
|
527 |
+
|
528 |
+
<div class="floating-buttons">
|
529 |
+
<button id="settingsToggle" class="floating-btn"><span class="material-icons">settings</span></button>
|
530 |
+
<button id="promptToggle" class="floating-btn"><span class="material-icons">edit_note</span></button>
|
531 |
+
<button id="refreshBtn" class="floating-btn"><span class="material-icons">refresh</span></button>
|
532 |
+
<button id="fullscreenToggle" class="floating-btn"><span class="material-icons">fullscreen</span></button>
|
533 |
+
</div>
|
534 |
+
|
535 |
+
<div class="notification" id="notificationBar"></div>
|
536 |
+
|
537 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
538 |
|
539 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
|
540 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/9.1.6/marked.min.js"></script>
|
541 |
+
<script>
|
542 |
+
const HUGGINGFACE_TOKEN = "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"; // <<< !!! ใส่ Hugging Face Token ของคุณที่นี่ !!!
|
543 |
+
|
544 |
+
let attachedFiles = [];
|
545 |
+
let currentCarouselIndex = 0;
|
546 |
+
let isLoading = false;
|
547 |
+
let isDragging = false;
|
548 |
+
let startX = 0;
|
549 |
+
let currentAngle = 0;
|
550 |
+
let startAngle = 0;
|
551 |
+
let carouselElement; // Define globally
|
552 |
+
|
553 |
+
const prompts = [
|
554 |
+
{ id: 'primarySystemPrompt', label: '🎯 Primary System Prompt', value: 'You are a powerful AI assistant focusing on code, images, and tech. Be clear, accurate, helpful. Focus on solutions & explanations.' },
|
555 |
+
{ id: 'ocrSystemPrompt', label: '👁️ OCR System Prompt', value: 'Extract all text accurately. Preserve format. Indicate unclear parts.' },
|
556 |
+
{ id: 'codeTemplate', label: '💻 Code Template', value: '```javascript\n// Code goes here\nfunction main() {\n return "Hello";\n}\n```' },
|
557 |
+
{ id: 'additionalInstructions', label: '📋 Additional Instructions', value: 'Provide tested examples. Include error handling. Explain step-by-step. Use modern practices.' },
|
558 |
+
{ id: 'promptPrefix', label: '🚀 Prompt Prefix', value: 'Analyze carefully and provide a comprehensive solution:' },
|
559 |
+
{ id: 'promptSuffix', label: '✨ Prompt Suffix', value: 'Ensure response is complete, accurate, with examples.' }
|
560 |
+
];
|
561 |
+
|
562 |
+
document.addEventListener('DOMContentLoaded', () => {
|
563 |
+
carouselElement = document.getElementById('promptCarousel'); // Assign here
|
564 |
+
loadSettings();
|
565 |
+
populateCarousel();
|
566 |
+
setupEventListeners();
|
567 |
+
setupCarouselInteraction();
|
568 |
+
setupDropzone();
|
569 |
+
updateCarouselPosition(true); // Initial setup without transition
|
570 |
+
updatePanelLayout(); // Set initial layout based on screen size
|
571 |
});
|
|
|
572 |
|
573 |
+
function populateCarousel() {
|
574 |
+
const carousel = document.getElementById('promptCarousel');
|
575 |
+
const indicator = document.getElementById('carouselIndicator');
|
576 |
+
carousel.innerHTML = '';
|
577 |
+
indicator.innerHTML = '';
|
578 |
+
|
579 |
+
prompts.forEach((prompt, index) => {
|
580 |
+
const card = document.createElement('div');
|
581 |
+
card.className = 'carousel-card';
|
582 |
+
card.innerHTML = `
|
583 |
+
<label>${prompt.label}</label>
|
584 |
+
<textarea id="${prompt.id}" placeholder="Enter prompt...">${localStorage.getItem(prompt.id) || prompt.value}</textarea>
|
585 |
+
`;
|
586 |
+
carousel.appendChild(card);
|
587 |
+
|
588 |
+
const dot = document.createElement('div');
|
589 |
+
dot.className = 'carousel-dot';
|
590 |
+
dot.dataset.index = index;
|
591 |
+
indicator.appendChild(dot);
|
592 |
+
});
|
593 |
+
}
|
594 |
|
595 |
+
function loadSettings() {
|
596 |
+
document.getElementById('modelSelect').value = localStorage.getItem('selectedModel') || 'Qwen/Qwen2.5-Coder-32B-Instruct';
|
597 |
+
document.getElementById('ocrModelSelect').value = localStorage.getItem('selectedOcrModel') || 'none';
|
598 |
+
prompts.forEach(p => {
|
599 |
+
const el = document.getElementById(p.id);
|
600 |
+
if (el) el.value = localStorage.getItem(p.id) || p.value;
|
601 |
+
});
|
602 |
+
}
|
603 |
|
604 |
+
function saveSettings() {
|
605 |
+
localStorage.setItem('selectedModel', document.getElementById('modelSelect').value);
|
606 |
+
localStorage.setItem('selectedOcrModel', document.getElementById('ocrModelSelect').value);
|
607 |
+
prompts.forEach(p => localStorage.setItem(p.id, document.getElementById(p.id).value));
|
608 |
+
showNotification('บันทึกการตั้งค่าแล้ว!', 'success');
|
609 |
+
}
|
610 |
|
611 |
+
function setupEventListeners() {
|
612 |
+
document.getElementById('saveSettingsBtn').addEventListener('click', saveSettings);
|
613 |
+
document.getElementById('settingsToggle').addEventListener('click', toggleSettingsPanel);
|
614 |
+
document.getElementById('promptToggle').addEventListener('click', togglePromptPanel);
|
615 |
+
document.getElementById('prevCard').addEventListener('click', () => rotateCarousel(-1));
|
616 |
+
document.getElementById('nextCard').addEventListener('click', () => rotateCarousel(1));
|
617 |
+
document.getElementById('applyPromptBtn').addEventListener('click', applyPrompts);
|
618 |
+
document.getElementById('sendButton').addEventListener('click', sendMessage);
|
619 |
+
document.getElementById('attachButton').addEventListener('click', () => document.getElementById('fileInput').click());
|
620 |
+
document.getElementById('fileInput').addEventListener('change', handleFileSelect);
|
621 |
+
document.getElementById('userInput').addEventListener('keydown', handleKeyDown);
|
622 |
+
document.getElementById('refreshBtn').addEventListener('click', () => location.reload());
|
623 |
+
document.getElementById('fullscreenToggle').addEventListener('click', toggleFullscreen);
|
624 |
+
|
625 |
+
document.querySelectorAll('.carousel-dot').forEach(dot => {
|
626 |
+
dot.addEventListener('click', (e) => goToCarouselIndex(parseInt(e.target.dataset.index)));
|
627 |
+
});
|
628 |
|
629 |
+
window.addEventListener('resize', updatePanelLayout); // Update layout on resize
|
630 |
+
}
|
|
|
|
|
631 |
|
632 |
+
function updatePanelLayout() {
|
633 |
+
const settingsPanel = document.getElementById('settingsPanel');
|
634 |
+
const promptPanel = document.getElementById('promptPanel');
|
635 |
+
const mainContent = document.getElementById('mainContent');
|
636 |
+
|
637 |
+
if (window.innerWidth <= 1024) {
|
638 |
+
settingsPanel.classList.add('collapsed');
|
639 |
+
promptPanel.classList.add('collapsed');
|
640 |
+
settingsPanel.classList.remove('open');
|
641 |
+
promptPanel.classList.remove('open');
|
642 |
+
mainContent.classList.add('settings-collapsed', 'prompts-collapsed');
|
643 |
+
} else {
|
644 |
+
settingsPanel.classList.remove('collapsed', 'open');
|
645 |
+
promptPanel.classList.remove('collapsed', 'open');
|
646 |
+
mainContent.classList.remove('settings-collapsed', 'prompts-collapsed');
|
647 |
}
|
648 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
649 |
|
650 |
+
function togglePanel(panelId, mainContentClass) {
|
651 |
+
const panel = document.getElementById(panelId);
|
652 |
+
const mainContent = document.getElementById('mainContent');
|
653 |
+
const isOpen = panel.classList.contains('open');
|
654 |
+
|
655 |
+
if (window.innerWidth <= 1024) {
|
656 |
+
if (isOpen) {
|
657 |
+
panel.classList.remove('open');
|
658 |
+
panel.classList.add('collapsed');
|
659 |
+
} else {
|
660 |
+
// Close other panel if open
|
661 |
+
const otherPanelId = panelId === 'settingsPanel' ? 'promptPanel' : 'settingsPanel';
|
662 |
+
document.getElementById(otherPanelId).classList.remove('open');
|
663 |
+
document.getElementById(otherPanelId).classList.add('collapsed');
|
664 |
+
// Open current panel
|
665 |
+
panel.classList.add('open');
|
666 |
+
panel.classList.remove('collapsed');
|
667 |
+
}
|
668 |
} else {
|
669 |
+
panel.classList.toggle('collapsed');
|
670 |
+
mainContent.classList.toggle(mainContentClass);
|
671 |
}
|
672 |
}
|
673 |
|
|
|
674 |
|
675 |
+
function toggleSettingsPanel() {
|
676 |
+
const panel = document.getElementById('settingsPanel');
|
677 |
+
const main = document.getElementById('mainContent');
|
678 |
+
panel.classList.toggle('collapsed');
|
679 |
+
main.classList.toggle('settings-collapsed');
|
680 |
+
}
|
681 |
|
682 |
+
function togglePromptPanel() {
|
683 |
+
const panel = document.getElementById('promptPanel');
|
684 |
+
const main = document.getElementById('mainContent');
|
685 |
+
panel.classList.toggle('collapsed');
|
686 |
+
main.classList.toggle('prompts-collapsed');
|
687 |
+
}
|
688 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
689 |
|
690 |
+
function setupCarouselInteraction() {
|
691 |
+
const carousel = carouselElement;
|
692 |
+
carousel.addEventListener('touchstart', dragStart, { passive: false });
|
693 |
+
carousel.addEventListener('touchmove', dragging, { passive: false });
|
694 |
+
carousel.addEventListener('touchend', dragEnd);
|
695 |
+
carousel.addEventListener('mousedown', dragStart);
|
696 |
+
carousel.addEventListener('mousemove', dragging);
|
697 |
+
carousel.addEventListener('mouseup', dragEnd);
|
698 |
+
carousel.addEventListener('mouseleave', dragEnd);
|
699 |
}
|
700 |
|
701 |
+
function dragStart(e) {
|
702 |
+
e.preventDefault();
|
703 |
+
isDragging = true;
|
704 |
+
startX = (e.type === 'touchstart' ? e.touches[0].clientX : e.clientX);
|
705 |
+
startAngle = currentAngle;
|
706 |
+
carouselElement.style.transition = 'none'; // Disable transition during drag
|
707 |
+
carouselElement.classList.add('dragging');
|
708 |
+
}
|
709 |
|
710 |
+
function dragging(e) {
|
711 |
+
if (!isDragging) return;
|
712 |
+
e.preventDefault();
|
713 |
+
const x = (e.type === 'touchmove' ? e.touches[0].clientX : e.clientX);
|
714 |
+
const dx = x - startX;
|
715 |
+
const sensitivity = 0.5; // Adjust drag speed
|
716 |
+
const angleChange = dx * sensitivity;
|
717 |
+
currentAngle = startAngle - angleChange; // Invert for natural feel
|
718 |
+
carouselElement.style.transform = `translateZ(-288px) rotateY(${currentAngle}deg)`;
|
719 |
+
}
|
720 |
|
721 |
+
function dragEnd(e) {
|
722 |
+
if (!isDragging) return;
|
723 |
+
isDragging = false;
|
724 |
+
carouselElement.style.transition = 'transform 0.6s cubic-bezier(0.4, 0, 0.2, 1)';
|
725 |
+
carouselElement.classList.remove('dragging');
|
726 |
+
|
727 |
+
const totalCards = prompts.length;
|
728 |
+
const anglePerCard = 360 / totalCards;
|
729 |
+
// Snap to the nearest card
|
730 |
+
currentCarouselIndex = Math.round(currentAngle / anglePerCard);
|
731 |
+
currentCarouselIndex = (currentCarouselIndex % totalCards + totalCards) % totalCards; // Ensure positive index
|
732 |
+
updateCarouselPosition();
|
733 |
}
|
734 |
|
735 |
+
function rotateCarousel(direction) {
|
736 |
+
const totalCards = prompts.length;
|
737 |
+
currentCarouselIndex = (currentCarouselIndex + direction + totalCards) % totalCards;
|
738 |
+
updateCarouselPosition();
|
739 |
+
}
|
740 |
|
741 |
+
function goToCarouselIndex(index) {
|
742 |
+
currentCarouselIndex = index;
|
743 |
+
updateCarouselPosition();
|
744 |
+
}
|
745 |
+
|
746 |
+
function updateCarouselPosition(noTransition = false) {
|
747 |
+
const carousel = carouselElement;
|
748 |
+
const cards = carousel.querySelectorAll('.carousel-card');
|
749 |
+
const dots = document.querySelectorAll('.carousel-dot');
|
750 |
+
const totalCards = cards.length;
|
751 |
+
const anglePerCard = 360 / totalCards;
|
752 |
+
const cardWidth = cards.length > 0 ? cards[0].offsetWidth : 350;
|
753 |
+
// Recalculate or use a fixed good value for translateZ
|
754 |
+
const translateZ = (cardWidth / 2) / Math.tan((anglePerCard / 2) * (Math.PI / 180)) + 20; // Added some padding
|
755 |
+
|
756 |
+
currentAngle = currentCarouselIndex * anglePerCard;
|
757 |
+
|
758 |
+
carousel.style.transition = noTransition ? 'none' : 'transform 0.6s cubic-bezier(0.4, 0, 0.2, 1)';
|
759 |
+
carousel.style.transform = `translateZ(-${translateZ}px) rotateY(${-currentAngle}deg)`;
|
760 |
+
|
761 |
+
cards.forEach((card, index) => {
|
762 |
+
const angle = index * anglePerCard;
|
763 |
+
card.style.transform = `rotateY(${angle}deg) translateZ(${translateZ}px)`;
|
764 |
+
card.style.opacity = index === currentCarouselIndex ? '1' : '0.5';
|
765 |
+
});
|
766 |
|
767 |
+
dots.forEach((dot, index) => {
|
768 |
+
dot.classList.toggle('active', index === currentCarouselIndex);
|
769 |
+
});
|
770 |
}
|
771 |
|
|
|
|
|
|
|
|
|
772 |
|
773 |
+
function applyPrompts() {
|
774 |
+
saveSettings();
|
775 |
+
showNotification('ใช้ Prompt แล้ว!', 'success');
|
776 |
+
if (window.innerWidth <= 1024) {
|
777 |
+
togglePromptPanel(); // Close panel on mobile after apply
|
778 |
+
}
|
779 |
+
}
|
780 |
|
781 |
+
function setupDropzone() {
|
782 |
+
const dropzone = document.getElementById('dropzone');
|
783 |
+
const chatContainer = document.getElementById('chatContainer');
|
|
|
784 |
|
785 |
+
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
|
786 |
+
chatContainer.addEventListener(eventName, preventDefaults, false);
|
787 |
+
document.body.addEventListener(eventName, preventDefaults, false); // Global prevent
|
788 |
+
});
|
789 |
+
|
790 |
+
function preventDefaults(e) {
|
791 |
+
e.preventDefault();
|
792 |
+
e.stopPropagation();
|
793 |
+
}
|
794 |
+
|
795 |
+
['dragenter', 'dragover'].forEach(eventName => {
|
796 |
+
chatContainer.addEventListener(eventName, () => dropzone.classList.add('active'), false);
|
797 |
+
});
|
798 |
+
['dragleave', 'drop'].forEach(eventName => {
|
799 |
+
chatContainer.addEventListener(eventName, () => dropzone.classList.remove('active'), false);
|
800 |
+
});
|
801 |
+
chatContainer.addEventListener('drop', handleDrop, false);
|
802 |
+
}
|
803 |
+
|
804 |
+
function handleDrop(e) {
|
805 |
+
const dt = e.dataTransfer;
|
806 |
+
handleFiles(dt.files);
|
807 |
+
}
|
808 |
+
|
809 |
+
function handleFileSelect(e) {
|
810 |
+
handleFiles(e.target.files);
|
811 |
+
}
|
812 |
+
|
813 |
+
function handleFiles(files) {
|
814 |
+
attachedFiles.push(...Array.from(files).filter(f => f.type.startsWith('image/')));
|
815 |
+
updateFileDisplay();
|
816 |
+
showNotification(`${files.length} รูปถูกแนบแล้ว`, 'success');
|
817 |
+
}
|
818 |
+
|
819 |
+
function updateFileDisplay() {
|
820 |
+
const fileNameEl = document.getElementById('fileName');
|
821 |
+
if (attachedFiles.length === 0) fileNameEl.textContent = '';
|
822 |
+
else if (attachedFiles.length === 1) fileNameEl.textContent = attachedFiles[0].name;
|
823 |
+
else fileNameEl.textContent = `${attachedFiles.length} ไฟล์`;
|
824 |
+
}
|
825 |
+
|
826 |
+
function handleKeyDown(e) {
|
827 |
+
if (e.key === 'Enter' && !e.shiftKey) {
|
828 |
+
e.preventDefault();
|
829 |
+
sendMessage();
|
830 |
+
}
|
831 |
+
}
|
832 |
+
|
833 |
+
async function sendMessage() {
|
834 |
+
const userInput = document.getElementById('userInput');
|
835 |
+
const message = userInput.value.trim();
|
836 |
+
if (!message && attachedFiles.length === 0 || isLoading) return;
|
837 |
+
|
838 |
+
setLoading(true);
|
839 |
+
const chatContainer = document.getElementById('chatContainer');
|
840 |
+
const userMessage = message;
|
841 |
+
const currentFiles = [...attachedFiles];
|
842 |
+
|
843 |
+
userInput.value = '';
|
844 |
+
attachedFiles = [];
|
845 |
+
updateFileDisplay();
|
846 |
+
|
847 |
+
if (userMessage) addMessage(userMessage, 'user');
|
848 |
+
currentFiles.forEach(file => addImageMessage(URL.createObjectURL(file), 'user'));
|
849 |
+
scrollToBottom(chatContainer);
|
850 |
+
|
851 |
+
try {
|
852 |
+
const response = await callHuggingFaceAPI(userMessage, currentFiles);
|
853 |
+
addMessage(response, 'ai');
|
854 |
+
} catch (error) {
|
855 |
+
console.error('Error:', error);
|
856 |
+
addMessage(`ขออภัย, เกิดข้อผิดพลาด: ${error.message}`, 'ai', true);
|
857 |
+
showNotification(`Error: ${error.message}`, 'error');
|
858 |
+
} finally {
|
859 |
+
setLoading(false);
|
860 |
+
scrollToBottom(chatContainer);
|
861 |
+
}
|
862 |
+
}
|
863 |
+
|
864 |
+
async function callHuggingFaceAPI(message, files) {
|
865 |
+
const model = document.getElementById('modelSelect').value;
|
866 |
+
const ocrModel = document.getElementById('ocrModelSelect').value;
|
867 |
+
let fullPrompt = `${localStorage.getItem('primarySystemPrompt') || prompts[0].value}\n\n`;
|
868 |
+
fullPrompt += `${localStorage.getItem('promptPrefix') || prompts[4].value}\n\nUser: ${message}`;
|
869 |
+
|
870 |
+
let imageBase64 = null;
|
871 |
+
if (files.length > 0) {
|
872 |
+
const file = files[0];
|
873 |
+
imageBase64 = await new Promise((resolve) => {
|
874 |
+
const reader = new FileReader();
|
875 |
+
reader.onloadend = () => resolve(reader.result.split(',')[1]);
|
876 |
+
reader.readAsDataURL(file);
|
877 |
+
});
|
878 |
+
|
879 |
+
if (ocrModel !== 'none') {
|
880 |
+
try {
|
881 |
+
const ocrText = await performOCR(file, ocrModel);
|
882 |
+
fullPrompt += `\n\n[Image Content: ${ocrText}]`;
|
883 |
+
} catch (error) {
|
884 |
+
console.warn('OCR failed:', error);
|
885 |
+
fullPrompt += `\n\n[Image attached, OCR failed]`;
|
886 |
+
}
|
887 |
+
} else {
|
888 |
+
fullPrompt += `\n\n[Image attached]`;
|
889 |
+
}
|
890 |
+
}
|
891 |
+
|
892 |
+
fullPrompt += `\n\n${localStorage.getItem('promptSuffix') || prompts[5].value}\n\nAI:`;
|
893 |
+
|
894 |
+
const payload = {
|
895 |
+
inputs: fullPrompt,
|
896 |
+
parameters: { max_new_tokens: 1500, temperature: 0.5, top_p: 0.9, do_sample: true, repetition_penalty: 1.1 }
|
897 |
+
};
|
898 |
+
|
899 |
+
// Note: HuggingFace Inference API doesn't have a standard way to send images + text
|
900 |
+
// for all models via JSON. Qwen-VL and Florence-2 might need specific formats or
|
901 |
+
// dedicated libraries/endpoints. This basic call mostly suits text models or
|
902 |
+
// text+OCR text. A real implementation might need adjustments.
|
903 |
+
if (imageBase64 && (model.includes('VL') || model.includes('Florence'))) {
|
904 |
+
// This part is tricky and model-dependent. HF API often prefers
|
905 |
+
// sending image data separately or using dedicated libs. We'll proceed
|
906 |
+
// with text + OCR for now as a fallback.
|
907 |
+
console.warn("Image sending via simple JSON is not standard. Sending text+OCR.");
|
908 |
+
}
|
909 |
+
|
910 |
+
const response = await fetch(`https://api-inference.huggingface.co/models/${model}`, {
|
911 |
+
method: 'POST',
|
912 |
+
headers: { 'Authorization': `Bearer ${HUGGINGFACE_TOKEN}`, 'Content-Type': 'application/json' },
|
913 |
+
body: JSON.stringify(payload)
|
914 |
+
});
|
915 |
+
|
916 |
+
if (!response.ok) {
|
917 |
+
const errorBody = await response.text();
|
918 |
+
throw new Error(`HTTP ${response.status}: ${errorBody}`);
|
919 |
+
}
|
920 |
+
|
921 |
+
const data = await response.json();
|
922 |
+
if (data.error) throw new Error(data.error);
|
923 |
+
let text = data[0]?.generated_text || 'No response.';
|
924 |
+
return text.replace(fullPrompt, '').trim(); // Remove prompt echo
|
925 |
+
}
|
926 |
+
|
927 |
+
async function performOCR(file, ocrModel) {
|
928 |
+
const response = await fetch(`https://api-inference.huggingface.co/models/${ocrModel}`, {
|
929 |
+
method: 'POST',
|
930 |
+
headers: { 'Authorization': `Bearer ${HUGGINGFACE_TOKEN}` },
|
931 |
+
body: file
|
932 |
+
});
|
933 |
+
if (!response.ok) throw new Error(`OCR failed: ${response.statusText}`);
|
934 |
+
const data = await response.json();
|
935 |
+
return data[0]?.generated_text || 'Could not extract text.';
|
936 |
+
}
|
937 |
+
|
938 |
+
|
939 |
+
function addMessage(content, sender, isError = false) {
|
940 |
+
const chatContainer = document.getElementById('chatContainer');
|
941 |
+
const messageDiv = document.createElement('div');
|
942 |
+
messageDiv.className = `message ${sender}`;
|
943 |
+
if (isError) messageDiv.style.borderColor = '#d32f2f';
|
944 |
+
|
945 |
+
if (sender === 'ai') {
|
946 |
+
messageDiv.innerHTML = marked.parse(content);
|
947 |
+
messageDiv.querySelectorAll('pre code').forEach(block => {
|
948 |
+
hljs.highlightElement(block);
|
949 |
+
addCodeTools(block.parentElement);
|
950 |
+
});
|
951 |
+
} else {
|
952 |
+
messageDiv.textContent = content;
|
953 |
+
}
|
954 |
+
chatContainer.appendChild(messageDiv);
|
955 |
+
scrollToBottom(chatContainer);
|
956 |
+
}
|
957 |
+
|
958 |
+
function addImageMessage(imageUrl, sender) {
|
959 |
+
const chatContainer = document.getElementById('chatContainer');
|
960 |
+
const messageDiv = document.createElement('div');
|
961 |
+
messageDiv.className = `message ${sender}`;
|
962 |
+
messageDiv.innerHTML = `<img src="${imageUrl}" alt="Uploaded image" style="max-width: 100%; max-height: 300px; border-radius: 4px;">`;
|
963 |
+
chatContainer.appendChild(messageDiv);
|
964 |
+
}
|
965 |
+
|
966 |
+
function addCodeTools(preElement) {
|
967 |
+
const toolsDiv = document.createElement('div');
|
968 |
+
toolsDiv.className = 'code-tools';
|
969 |
+
const copyBtn = document.createElement('button');
|
970 |
+
copyBtn.innerHTML = '<span class="material-icons">content_copy</span>';
|
971 |
+
copyBtn.onclick = () => {
|
972 |
+
navigator.clipboard.writeText(preElement.querySelector('code').innerText)
|
973 |
+
.then(() => showNotification('คัดลอกโค้ดแล้ว!', 'success'))
|
974 |
+
.catch(() => showNotification('คัดลอกไม่สำเร็จ!', 'error'));
|
975 |
+
};
|
976 |
+
toolsDiv.appendChild(copyBtn);
|
977 |
+
preElement.style.position = 'relative';
|
978 |
+
preElement.appendChild(toolsDiv);
|
979 |
+
}
|
980 |
+
|
981 |
+
function setLoading(loading) {
|
982 |
+
isLoading = loading;
|
983 |
+
const sendButton = document.getElementById('sendButton');
|
984 |
+
sendButton.innerHTML = loading ? '<div class="spinner"></div>' : '<span class="material-icons">send</span>';
|
985 |
+
sendButton.disabled = loading;
|
986 |
+
}
|
987 |
+
|
988 |
+
function toggleFullscreen() {
|
989 |
+
const icon = document.querySelector('#fullscreenToggle .material-icons');
|
990 |
+
if (!document.fullscreenElement) {
|
991 |
+
document.documentElement.requestFullscreen();
|
992 |
+
icon.textContent = 'fullscreen_exit';
|
993 |
+
} else {
|
994 |
+
document.exitFullscreen();
|
995 |
+
icon.textContent = 'fullscreen';
|
996 |
+
}
|
997 |
+
}
|
998 |
+
|
999 |
+
function showNotification(message, type = 'success') {
|
1000 |
+
const bar = document.getElementById('notificationBar');
|
1001 |
+
bar.textContent = message;
|
1002 |
+
bar.className = `notification ${type === 'error' ? 'error-message' : 'success-message'}`;
|
1003 |
+
bar.style.display = 'block';
|
1004 |
+
setTimeout(() => { bar.style.display = 'none'; }, 3400);
|
1005 |
+
}
|
1006 |
+
|
1007 |
+
function scrollToBottom(element) {
|
1008 |
+
element.scrollTo({ top: element.scrollHeight, behavior: 'smooth' });
|
1009 |
+
}
|
1010 |
+
|
1011 |
+
</script>
|
1012 |
</body>
|
1013 |
</html>
|