File size: 4,867 Bytes
2449939 |
1 2 3 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 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI Travel Assistant</title>
<style>
/* General Styles */
body {
font-family: 'Arial', sans-serif;
background-color: #f4f4f9;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
/* Chat Container */
.chat-container {
width: 400px;
background-color: #fff;
border-radius: 10px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
overflow: hidden;
display: flex;
flex-direction: column;
}
/* Chat Header */
.chat-header {
background-color: #007bff;
color: #fff;
padding: 15px;
text-align: center;
font-size: 18px;
font-weight: bold;
}
/* Chat Box */
#chat-box {
flex: 1;
padding: 15px;
overflow-y: auto;
border-bottom: 1px solid #ddd;
background-color: #f9f9f9;
}
/* Message Styles */
.message {
margin-bottom: 15px;
display: flex;
flex-direction: column;
}
.message.user {
align-items: flex-end;
}
.message.bot {
align-items: flex-start;
}
.message p {
max-width: 70%;
padding: 10px;
border-radius: 10px;
margin: 0;
}
.message.user p {
background-color: #007bff;
color: #fff;
}
.message.bot p {
background-color: #e9ecef;
color: #333;
}
/* Input Container */
.input-container {
display: flex;
padding: 10px;
background-color: #fff;
}
#user-input {
flex: 1;
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
outline: none;
}
#user-input:focus {
border-color: #007bff;
}
button {
margin-left: 10px;
padding: 10px 20px;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}
</style>
</head>
<body>
<div class="chat-container">
<!-- Chat Header -->
<div class="chat-header">
AI Travel Assistant
</div>
<!-- Chat Box -->
<div id="chat-box">
<!-- Chat messages will appear here -->
</div>
<!-- Input Container -->
<div class="input-container">
<input type="text" id="user-input" placeholder="Type your message here..." onkeypress="handleKeyPress(event)">
<button onclick="sendMessage()">Send</button>
</div>
</div>
<script>
let chatHistoryIds = null;
// Function to handle Enter key press
function handleKeyPress(event) {
if (event.key === "Enter") {
sendMessage();
}
}
// Function to send a message
async function sendMessage() {
const userInput = document.getElementById("user-input").value;
if (!userInput) return;
// Add user message to chat box
const chatBox = document.getElementById("chat-box");
chatBox.innerHTML += `
<div class="message user">
<p>${userInput}</p>
</div>
`;
// Clear input
document.getElementById("user-input").value = "";
// Send message to Flask backend
const response = await fetch("http://127.0.0.1:5000/chat", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
message: userInput,
chat_history_ids: chatHistoryIds
})
});
const data = await response.json();
// Add bot response to chat box
chatBox.innerHTML += `
<div class="message bot">
<p>${data.response}</p>
</div>
`;
// Update chat history
chatHistoryIds = data.chat_history_ids;
// Scroll to bottom
chatBox.scrollTop = chatBox.scrollHeight;
}
</script>
</body>
</html> |