Spaces:
Sleeping
Sleeping
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Loomyloo AI Chat</title> | |
| <style> | |
| body { | |
| background-color: #121212; | |
| color: #e0e0e0; | |
| font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; | |
| display: flex; | |
| flex-direction: column; | |
| height: 100vh; | |
| margin: 0; | |
| } | |
| #chat-container { | |
| flex: 1; | |
| padding: 20px; | |
| overflow-y: auto; | |
| display: flex; | |
| flex-direction: column; | |
| gap: 10px; | |
| } | |
| .message { | |
| max-width: 80%; | |
| padding: 10px 15px; | |
| border-radius: 15px; | |
| line-height: 1.4; | |
| } | |
| .user-message { | |
| align-self: flex-end; | |
| background-color: #007bff; | |
| color: white; | |
| border-bottom-right-radius: 2px; | |
| } | |
| .ai-message { | |
| align-self: flex-start; | |
| background-color: #2c2c2c; | |
| color: #e0e0e0; | |
| border-bottom-left-radius: 2px; | |
| } | |
| #input-area { | |
| padding: 20px; | |
| background-color: #1e1e1e; | |
| display: flex; | |
| gap: 10px; | |
| } | |
| input[type="text"] { | |
| flex: 1; | |
| padding: 12px; | |
| border-radius: 25px; | |
| border: 1px solid #333; | |
| background-color: #2c2c2c; | |
| color: white; | |
| outline: none; | |
| } | |
| button { | |
| padding: 10px 20px; | |
| border-radius: 25px; | |
| border: none; | |
| background-color: #007bff; | |
| color: white; | |
| cursor: pointer; | |
| font-weight: bold; | |
| } | |
| button:hover { | |
| background-color: #0056b3; | |
| } | |
| #reset-btn { | |
| background-color: #dc3545; | |
| } | |
| #reset-btn:hover { | |
| background-color: #a71d2a; | |
| } | |
| .loading { | |
| opacity: 0.5; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div id="chat-container"> | |
| <div class="message ai-message">Hello! I am Loomyloo (v5) (running on Qwen2.5-Coder-14B-Instruct-Uncensored GGUF). I am powerful and uncensored! How can I help you?</div> | |
| </div> | |
| <div id="input-area"> | |
| <button id="reset-btn" onclick="resetMemory()" title="Clear Chat History">Reset</button> | |
| <input type="text" id="user-input" placeholder="Type a message..." onkeypress="handleKeyPress(event)"> | |
| <button onclick="sendMessage()">Send</button> | |
| </div> | |
| <script> | |
| async function resetMemory() { | |
| if(confirm("Are you sure you want to clear my memory?")) { | |
| await fetch('/reset'); | |
| const container = document.getElementById('chat-container'); | |
| container.innerHTML = '<div class="message ai-message">Memory cleared! Starting fresh.</div>'; | |
| } | |
| } | |
| async function sendMessage() { | |
| const input = document.getElementById('user-input'); | |
| const message = input.value.trim(); | |
| if (!message) return; | |
| // Add User Message | |
| addMessage(message, 'user-message'); | |
| input.value = ''; | |
| input.disabled = true; | |
| try { | |
| // Call the API | |
| const response = await fetch(`/ask?prompt=${encodeURIComponent(message)}`); | |
| const data = await response.json(); | |
| // Add AI Message | |
| // The API returns { "generated_text": "..." } | |
| const reply = data.generated_text || "Error: No response text"; | |
| addMessage(reply, 'ai-message'); | |
| } catch (error) { | |
| addMessage("Error connecting to API: " + error.message, 'ai-message'); | |
| } finally { | |
| input.disabled = false; | |
| input.focus(); | |
| } | |
| } | |
| function addMessage(text, className) { | |
| const container = document.getElementById('chat-container'); | |
| const div = document.createElement('div'); | |
| div.className = `message ${className}`; | |
| div.textContent = text; | |
| container.appendChild(div); | |
| container.scrollTop = container.scrollHeight; | |
| } | |
| function handleKeyPress(event) { | |
| if (event.key === 'Enter') { | |
| sendMessage(); | |
| } | |
| } | |
| </script> | |
| </body> | |
| </html> | |