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>π²π¦ Moroccan Tourism Assistant</title> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> | |
<style> | |
body { | |
font-family: Arial, sans-serif; | |
max-width: 800px; | |
margin: 20px auto; | |
padding: 0 20px; | |
} | |
.chat-container { | |
border: 1px solid #ccc; | |
border-radius: 5px; | |
padding: 20px; | |
height: 400px; | |
overflow-y: auto; | |
margin-bottom: 20px; | |
} | |
.message { | |
margin: 10px 0; | |
padding: 10px; | |
border-radius: 5px; | |
} | |
.user-message { | |
background-color: #e3f2fd; | |
margin-left: 20%; | |
} | |
.bot-message { | |
background-color: #f5f5f5; | |
margin-right: 20%; | |
} | |
.input-container { | |
display: flex; | |
gap: 10px; | |
} | |
#user-input { | |
flex-grow: 1; | |
padding: 10px; | |
border: 1px solid #ccc; | |
border-radius: 5px; | |
} | |
button { | |
padding: 10px 20px; | |
background-color: #007bff; | |
color: white; | |
border: none; | |
border-radius: 5px; | |
cursor: pointer; | |
} | |
button:hover { | |
background-color: #0056b3; | |
} | |
.loading { | |
display: none; | |
margin: 10px 0; | |
color: #666; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>π²π¦ Moroccan Tourism Assistant</h1> | |
<div class="chat-container" id="chat-container"></div> | |
<div class="loading" id="loading">Assistant is thinking...</div> | |
<div class="input-container"> | |
<input type="text" id="user-input" placeholder="Ask about tourism in Morocco..."> | |
<button onclick="sendMessage()">Send</button> | |
</div> | |
<script> | |
function addMessage(message, isUser) { | |
const chatContainer = document.getElementById('chat-container'); | |
const messageDiv = document.createElement('div'); | |
messageDiv.className = `message ${isUser ? 'user-message' : 'bot-message'}`; | |
messageDiv.textContent = message; | |
chatContainer.appendChild(messageDiv); | |
chatContainer.scrollTop = chatContainer.scrollHeight; | |
} | |
function sendMessage() { | |
const input = document.getElementById('user-input'); | |
const message = input.value.trim(); | |
if (message) { | |
addMessage(message, true); | |
input.value = ''; | |
document.getElementById('loading').style.display = 'block'; | |
fetch('/chat', { | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json', | |
}, | |
body: JSON.stringify({ message: message }) | |
}) | |
.then(response => response.json()) | |
.then(data => { | |
document.getElementById('loading').style.display = 'none'; | |
addMessage(data.response, false); | |
}) | |
.catch(error => { | |
document.getElementById('loading').style.display = 'none'; | |
addMessage('Sorry, an error occurred while processing your message.', false); | |
console.error('Error:', error); | |
}); | |
} | |
} | |
// Allow sending message with Enter key | |
document.getElementById('user-input').addEventListener('keypress', function(e) { | |
if (e.key === 'Enter') { | |
sendMessage(); | |
} | |
}); | |
</script> | |
</body> | |
</html> |