Spaces:
Runtime error
Runtime error
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Chat with AI</title> | |
| <style> | |
| body { | |
| font-family: Arial, sans-serif; | |
| margin: 0; | |
| padding: 0; | |
| background-color: #f4f4f4; | |
| display: flex; | |
| flex-direction: column; | |
| justify-content: center; | |
| align-items: center; | |
| height: 100vh; | |
| } | |
| #chatbox { | |
| width: 80%; | |
| max-width: 500px; | |
| background: #fff; | |
| padding: 20px; | |
| border-radius: 10px; | |
| box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2); | |
| } | |
| #messages { | |
| height: 300px; | |
| overflow-y: auto; | |
| margin-bottom: 20px; | |
| border: 1px solid #ddd; | |
| padding: 10px; | |
| border-radius: 5px; | |
| background: #f9f9f9; | |
| } | |
| #input-box { | |
| display: flex; | |
| } | |
| input[type="text"] { | |
| flex: 1; | |
| padding: 10px; | |
| border: 1px solid #ddd; | |
| border-radius: 5px 0 0 5px; | |
| outline: none; | |
| } | |
| button { | |
| padding: 10px; | |
| border: none; | |
| background-color: #007bff; | |
| color: white; | |
| border-radius: 0 5px 5px 0; | |
| cursor: pointer; | |
| } | |
| button:hover { | |
| background-color: #0056b3; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div id="chatbox"> | |
| <div id="messages"></div> | |
| <div id="input-box"> | |
| <input id="userInput" type="text" placeholder="Type your message here..."> | |
| <button onclick="sendMessage()">Send</button> | |
| </div> | |
| </div> | |
| <script> | |
| async function sendMessage() { | |
| const userInput = document.getElementById('userInput').value; | |
| if (!userInput) return; | |
| const messagesDiv = document.getElementById('messages'); | |
| messagesDiv.innerHTML += `<div><strong>You:</strong> ${userInput}</div>`; | |
| const response = await fetch(`/get?msg=${encodeURIComponent(userInput)}`); | |
| const botResponse = await response.text(); | |
| messagesDiv.innerHTML += `<div><strong>Bot:</strong> ${botResponse}</div>`; | |
| document.getElementById('userInput').value = ''; | |
| messagesDiv.scrollTop = messagesDiv.scrollHeight; | |
| } | |
| </script> | |
| </body> | |
| </html> | |