| <!doctype html> |
| <html lang="en"> |
| <head> |
| <meta charset="utf-8"> |
| <meta name="viewport" content="width=device-width, initial-scale=1"> |
| <title>AI Chat Agent</title> |
| <link href="/static/styles.css" rel="stylesheet"> |
| <style> |
| body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background: #f0f2f5; margin: 0; display: flex; flex-direction: column; height: 100vh; } |
| #chat-header { background: #0078d4; color: white; padding: 15px; text-align: center; font-weight: bold; } |
| #chat-container { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 10px; } |
| .msg { max-width: 80%; padding: 10px 15px; border-radius: 18px; line-height: 1.4; } |
| .user { align-self: flex-end; background: #0078d4; color: white; } |
| .bot { align-self: flex-start; background: white; color: #333; border: 1px solid #ddd; } |
| #input-area { background: white; padding: 15px; display: flex; border-top: 1px solid #ddd; } |
| input { flex: 1; border: 1px solid #ccc; padding: 10px; border-radius: 20px; outline: none; } |
| button { background: #0078d4; color: white; border: none; padding: 10px 20px; margin-left: 10px; border-radius: 20px; cursor: pointer; } |
| button:hover { background: #005a9e; } |
| </style> |
| </head> |
| <body> |
| <div id="chat-header">AI Chat Assistant (Qwen 72B)</div> |
| <div id="chat-container"></div> |
| <div id="input-area"> |
| <input type="text" id="user-input" placeholder="اكتب رسالتك هنا..." onkeypress="if(event.key==='Enter') sendMessage()"> |
| <button onclick="sendMessage()">إرسال</button> |
| </div> |
|
|
| <script> |
| const container = document.getElementById('chat-container'); |
| async function sendMessage() { |
| const input = document.getElementById('user-input'); |
| const text = input.value.trim(); |
| if (!text) return; |
| |
| |
| container.innerHTML += `<div class="msg user">${text}</div>`; |
| input.value = ''; |
| container.scrollTop = container.scrollHeight; |
| |
| try { |
| const response = await fetch('/chat', { |
| method: 'POST', |
| headers: { 'Content-Type': 'application/json' }, |
| body: JSON.stringify({ messages: [{ role: 'user', content: text }] }) |
| }); |
| const data = await response.json(); |
| const botMsg = data.choices[0].message.content; |
| |
| |
| container.innerHTML += `<div class="msg bot">${botMsg}</div>`; |
| container.scrollTop = container.scrollHeight; |
| } catch (e) { |
| container.innerHTML += `<div class="msg bot" style="color:red">خطأ في الاتصال بالسيرفر</div>`; |
| } |
| } |
| </script> |
| </body> |
| </html> |
|
|