Spaces:
Sleeping

edi.chat.test / index.html
Claude Code Bot
Claude
Upgrade to real AI responses using local Ollama
8ad2676
Raw History Blame Contribute Delete
10.8 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>edi.chat - UGA AI Assistant</title>
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #BA0C2F 0%, #000000 100%);
min-height: 100vh;
display: flex;
flex-direction: column;
}
.header {
background: rgba(255,255,255,0.95);
padding: 20px;
text-align: center;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.header h1 { color: #BA0C2F; font-size: 2.5rem; margin-bottom: 10px; }
.header p { color: #666; font-size: 1.2rem; }
.chat-container {
flex: 1;
max-width: 800px;
margin: 20px auto;
background: rgba(255,255,255,0.95);
border-radius: 15px;
display: flex;
flex-direction: column;
overflow: hidden;
box-shadow: 0 8px 25px rgba(0,0,0,0.15);
}
.chat-messages {
flex: 1;
padding: 20px;
overflow-y: auto;
min-height: 400px;
max-height: 500px;
}
.message {
margin-bottom: 15px;
display: flex;
gap: 10px;
}
.message.user { justify-content: flex-end; }
.message-content {
max-width: 70%;
padding: 12px 16px;
border-radius: 20px;
font-size: 14px;
line-height: 1.4;
}
.message.user .message-content {
background: #BA0C2F;
color: white;
}
.message.bot .message-content {
background: #f0f0f0;
color: #333;
}
.chat-input {
display: flex;
gap: 10px;
padding: 20px;
background: #f9f9f9;
border-top: 1px solid #eee;
}
.chat-input input {
flex: 1;
padding: 12px 16px;
border: 2px solid #ddd;
border-radius: 25px;
font-size: 14px;
outline: none;
transition: border-color 0.3s;
}
.chat-input input:focus {
border-color: #BA0C2F;
}
.chat-input button {
padding: 12px 24px;
background: #BA0C2F;
color: white;
border: none;
border-radius: 25px;
font-size: 14px;
font-weight: bold;
cursor: pointer;
transition: background 0.3s;
}
.chat-input button:hover {
background: #9a0a27;
}
.status {
text-align: center;
padding: 20px;
color: #666;
font-style: italic;
}
.ai-status {
background: #f0f8ff;
border: 1px solid #dde7f0;
border-radius: 8px;
padding: 10px;
margin: 10px 20px;
font-size: 12px;
text-align: center;
}
.ai-status.connected {
background: #f0fff0;
border-color: #90ee90;
color: #006400;
}
.ai-status.error {
background: #fff0f0;
border-color: #ffa0a0;
color: #8b0000;
}
.typing-indicator {
display: none;
margin: 10px 0;
text-align: left;
}
.typing-dots {
display: inline-block;
width: 4px;
height: 4px;
border-radius: 50%;
background-color: #999;
animation: typing 1.4s infinite ease-in-out;
margin: 0 1px;
}
.typing-dots:nth-child(1) { animation-delay: -0.32s; }
.typing-dots:nth-child(2) { animation-delay: -0.16s; }
@keyframes typing {
0%, 80%, 100% { transform: scale(0); opacity: 0.5; }
40% { transform: scale(1); opacity: 1; }
}
</style>
</head>
<body>
<div class="header">
<h1>πŸŽ“ edi.chat</h1>
<p>University of Georgia AI Assistant</p>
</div>
<div class="chat-container">
<div class="ai-status" id="aiStatus">
πŸ€– Connecting to local AI...
</div>
<div class="chat-messages" id="messages">
<div class="message bot">
<div class="message-content">
πŸŽ“ <strong>Welcome to edi.chat!</strong><br><br>
I'm your UGA AI Assistant powered by <strong>local Ollama AI</strong>. I can help with:<br>
β€’ Course information and registration<br>
β€’ Campus dining and services<br>
β€’ UGA events and activities<br>
β€’ Academic resources and support<br><br>
<em>Ask me anything about UGA!</em>
</div>
</div>
<div class="typing-indicator" id="typingIndicator">
<div class="message bot">
<div class="message-content">
πŸŽ“ <span class="typing-dots"></span><span class="typing-dots"></span><span class="typing-dots"></span>
</div>
</div>
</div>
</div>
<div class="chat-input">
<input type="text" id="messageInput" placeholder="Ask me anything about UGA..." maxlength="500">
<button onclick="sendMessage()" id="sendButton">Send</button>
</div>
</div>
<div class="status" id="statusBar">
<small>πŸ€– Connecting to AI...</small>
</div>
<script>
const messagesDiv = document.getElementById('messages');
const messageInput = document.getElementById('messageInput');
const sendButton = document.getElementById('sendButton');
const aiStatus = document.getElementById('aiStatus');
const typingIndicator = document.getElementById('typingIndicator');
function addMessage(content, isUser = false) {
const messageDiv = document.createElement('div');
messageDiv.className = `message ${isUser ? 'user' : 'bot'}`;
const contentDiv = document.createElement('div');
contentDiv.className = 'message-content';
contentDiv.innerHTML = content;
messageDiv.appendChild(contentDiv);
messagesDiv.insertBefore(messageDiv, typingIndicator);
messagesDiv.scrollTop = messagesDiv.scrollHeight;
}
function showTyping() {
typingIndicator.style.display = 'block';
messagesDiv.scrollTop = messagesDiv.scrollHeight;
}
function hideTyping() {
typingIndicator.style.display = 'none';
}
function updateAIStatus(status, message) {
aiStatus.className = `ai-status ${status}`;
aiStatus.innerHTML = message;
}
async function checkAIStatus() {
try {
const response = await fetch('/health');
const data = await response.json();
if (data.ai === 'ollama') {
updateAIStatus('connected', 'πŸ€– Local Ollama AI - Connected & Ready');
} else {
updateAIStatus('error', 'πŸ€– AI Status: ' + (data.ai || 'Unknown'));
}
} catch (error) {
updateAIStatus('error', 'πŸ€– AI Connection Error - Check server status');
}
}
let isProcessing = false;
async function sendMessage() {
const message = messageInput.value.trim();
if (!message || isProcessing) return;
// Prevent double sends
isProcessing = true;
// Disable input while processing
messageInput.disabled = true;
sendButton.disabled = true;
sendButton.textContent = 'Thinking...';
// Add user message
addMessage(message, true);
messageInput.value = '';
// Show typing indicator
showTyping();
try {
const response = await fetch('/api/chat', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ message })
});
// Hide typing indicator
hideTyping();
if (response.status === 429) {
const data = await response.json().catch(() => ({}));
const retryAfter = data.retryAfter || 10;
addMessage(`πŸŽ“ Please wait ${retryAfter} seconds before sending another message.`);
return;
}
if (!response.ok) {
throw new Error(`HTTP ${response.status}`);
}
const data = await response.json();
if (data.success && data.response) {
addMessage(data.response);
// Update AI status if provided
if (data.aiType === 'ollama') {
updateAIStatus('connected', 'πŸ€– Local Ollama AI - Connected & Active');
}
} else {
addMessage('πŸŽ“ I apologize, but I encountered an issue processing your message. Please try again.');
}
} catch (error) {
hideTyping();
addMessage('πŸŽ“ I\'m having trouble connecting right now. Please check your connection and try again.');
updateAIStatus('error', 'πŸ€– AI Connection Error - Please check server status');
}
// Re-enable input
messageInput.disabled = false;
sendButton.disabled = false;
sendButton.textContent = 'Send';
messageInput.focus();
isProcessing = false;
}
messageInput.addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
e.preventDefault(); // Prevent form submission or other default behavior
sendMessage();
}
});
// Focus input when page loads and check AI status
document.addEventListener('DOMContentLoaded', function() {
messageInput.focus();
checkAIStatus();
// Check AI status every 30 seconds
setInterval(checkAIStatus, 30000);
});
</script>
</body>
</html>