SpringGeminiChat / src /index.html
github-actions[bot]
Space deploy: orphan commit with Docker config + LFS pointers
5a44b8b
raw
history blame
14 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Gemini Chat - Test UI</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.chat-container {
background: white;
border-radius: 20px;
box-shadow: 0 20px 40px rgba(0,0,0,0.1);
width: 90%;
max-width: 800px;
height: 600px;
display: flex;
flex-direction: column;
overflow: hidden;
}
.chat-header {
background: linear-gradient(45deg, #4CAF50, #45a049);
color: white;
padding: 20px;
text-align: center;
display: flex;
justify-content: space-between;
align-items: center;
}
.header-info {
display: flex;
flex-direction: column;
align-items: flex-start;
}
.status-indicator {
display: flex;
align-items: center;
gap: 8px;
font-size: 0.9em;
opacity: 0.9;
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #ff4444;
animation: pulse 2s infinite;
}
.status-dot.online {
background: #44ff44;
}
@keyframes pulse {
0% { opacity: 1; }
50% { opacity: 0.5; }
100% { opacity: 1; }
}
.chat-messages {
flex: 1;
padding: 20px;
overflow-y: auto;
background: #f8f9fa;
display: flex;
flex-direction: column;
gap: 15px;
}
.message {
display: flex;
gap: 10px;
animation: slideIn 0.3s ease-out;
}
@keyframes slideIn {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.message.user {
justify-content: flex-end;
}
.message-bubble {
max-width: 70%;
padding: 12px 18px;
border-radius: 18px;
word-wrap: break-word;
line-height: 1.4;
}
.message.user .message-bubble {
background: linear-gradient(45deg, #007bff, #0056b3);
color: white;
border-bottom-right-radius: 4px;
}
.message.bot .message-bubble {
background: white;
border: 1px solid #e0e0e0;
color: #333;
border-bottom-left-radius: 4px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.message-time {
font-size: 0.7em;
opacity: 0.7;
margin-top: 4px;
}
.typing-indicator {
display: none;
align-items: center;
gap: 10px;
padding: 15px 20px;
font-style: italic;
color: #666;
}
.typing-dots {
display: flex;
gap: 4px;
}
.typing-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #4CAF50;
animation: typingDot 1.4s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingDot {
0%, 60%, 100% { transform: translateY(0); }
30% { transform: translateY(-10px); }
}
.chat-input-container {
padding: 20px;
background: white;
border-top: 1px solid #e0e0e0;
}
.chat-input-form {
display: flex;
gap: 10px;
align-items: center;
}
.chat-input {
flex: 1;
padding: 12px 18px;
border: 2px solid #e0e0e0;
border-radius: 25px;
outline: none;
font-size: 16px;
transition: border-color 0.3s;
}
.chat-input:focus {
border-color: #4CAF50;
}
.send-button {
background: linear-gradient(45deg, #4CAF50, #45a049);
color: white;
border: none;
border-radius: 50%;
width: 50px;
height: 50px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
transition: transform 0.2s, box-shadow 0.2s;
font-size: 20px;
}
.send-button:hover {
transform: scale(1.05);
box-shadow: 0 5px 15px rgba(76, 175, 80, 0.4);
}
.send-button:disabled {
background: #ccc;
cursor: not-allowed;
transform: none;
box-shadow: none;
}
.error-message {
background: #ffebee;
color: #c62828;
padding: 10px;
border-radius: 5px;
margin: 10px 20px;
border-left: 4px solid #f44336;
display: none;
}
.health-status {
font-size: 0.8em;
opacity: 0.8;
}
/* Responsive Design */
@media (max-width: 600px) {
.chat-container {
width: 95%;
height: 90vh;
margin: 20px;
}
.chat-header {
padding: 15px;
}
.chat-messages {
padding: 15px;
}
.message-bubble {
max-width: 85%;
}
.chat-input-container {
padding: 15px;
}
}
/* Scrollbar Styling */
.chat-messages::-webkit-scrollbar {
width: 6px;
}
.chat-messages::-webkit-scrollbar-track {
background: #f1f1f1;
border-radius: 3px;
}
.chat-messages::-webkit-scrollbar-thumb {
background: #c1c1c1;
border-radius: 3px;
}
.chat-messages::-webkit-scrollbar-thumb:hover {
background: #a8a8a8;
}
</style>
</head>
<body>
<div class="chat-container">
<div class="chat-header">
<div class="header-info">
<h2>🤖 Gemini Chat Assistant</h2>
<div class="status-indicator">
<div class="status-dot" id="statusDot"></div>
<span id="statusText">Checking connection...</span>
</div>
</div>
<div class="health-status">
<button onclick="checkHealth()" style="background: rgba(255,255,255,0.2); border: 1px solid rgba(255,255,255,0.3); color: white; padding: 5px 10px; border-radius: 15px; cursor: pointer; font-size: 0.8em;">
🔄 Check Status
</button>
</div>
</div>
<div class="error-message" id="errorMessage"></div>
<div class="chat-messages" id="chatMessages">
<div class="message bot">
<div class="message-bubble">
👋 Hello! I'm your Gemini-powered chat assistant. How can I help you today?
<div class="message-time" id="welcomeTime"></div>
</div>
</div>
</div>
<div class="typing-indicator" id="typingIndicator">
<span>Gemini is thinking</span>
<div class="typing-dots">
<div class="typing-dot"></div>
<div class="typing-dot"></div>
<div class="typing-dot"></div>
</div>
</div>
<div class="chat-input-container">
<form class="chat-input-form" id="chatForm">
<input
type="text"
class="chat-input"
id="messageInput"
placeholder="Type your message here..."
autocomplete="off"
maxlength="1000"
>
<button type="submit" class="send-button" id="sendButton">
</button>
</form>
</div>
</div>
<script>
// Configuration
const API_BASE_URL = 'http://localhost:8080/api/chat';
// DOM Elements
const chatMessages = document.getElementById('chatMessages');
const messageInput = document.getElementById('messageInput');
const sendButton = document.getElementById('sendButton');
const chatForm = document.getElementById('chatForm');
const typingIndicator = document.getElementById('typingIndicator');
const errorMessage = document.getElementById('errorMessage');
const statusDot = document.getElementById('statusDot');
const statusText = document.getElementById('statusText');
// Initialize
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('welcomeTime').textContent = getCurrentTime();
checkHealth();
messageInput.focus();
});
// Event Listeners
chatForm.addEventListener('submit', function(e) {
e.preventDefault();
sendMessage();
});
messageInput.addEventListener('keypress', function(e) {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
sendMessage();
}
});
// Functions
function getCurrentTime() {
return new Date().toLocaleTimeString('en-US', {
hour12: true,
hour: 'numeric',
minute: '2-digit'
});
}
function showError(message) {
errorMessage.textContent = message;
errorMessage.style.display = 'block';
setTimeout(() => {
errorMessage.style.display = 'none';
}, 5000);
}
function updateStatus(online, message) {
statusDot.className = `status-dot ${online ? 'online' : ''}`;
statusText.textContent = message;
}
async function checkHealth() {
try {
const response = await fetch(`${API_BASE_URL}/health`);
if (response.ok) {
const data = await response.json();
updateStatus(true, `Connected • ${data.service}`);
} else {
updateStatus(false, 'Backend unavailable');
}
} catch (error) {
updateStatus(false, 'Connection failed');
console.error('Health check failed:', error);
}
}
function addMessage(content, isUser = false) {
const messageDiv = document.createElement('div');
messageDiv.className = `message ${isUser ? 'user' : 'bot'}`;
const bubbleDiv = document.createElement('div');
bubbleDiv.className = 'message-bubble';
bubbleDiv.innerHTML = `
${content}
<div class="message-time">${getCurrentTime()}</div>
`;
messageDiv.appendChild(bubbleDiv);
chatMessages.appendChild(messageDiv);
// Scroll to bottom
chatMessages.scrollTop = chatMessages.scrollHeight;
}
function showTypingIndicator() {
typingIndicator.style.display = 'flex';
chatMessages.scrollTop = chatMessages.scrollHeight;
}
function hideTypingIndicator() {
typingIndicator.style.display = 'none';
}
function setLoading(loading) {
sendButton.disabled = loading;
sendButton.textContent = loading ? '⏳' : '➤';
messageInput.disabled = loading;
if (loading) {
showTypingIndicator();
} else {
hideTypingIndicator();
}
}
async function sendMessage() {
const message = messageInput.value.trim();
if (!message) return;
// Add user message
addMessage(message, true);
messageInput.value = '';
setLoading(true);
try {
const response = await fetch(`${API_BASE_URL}/message`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ message: message })
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
if (data.success) {
// Format the response for better display
const formattedResponse = data.response
.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
.replace(/\n/g, '<br>');
addMessage(formattedResponse, false);
} else {
throw new Error(data.error || 'Unknown error occurred');
}
} catch (error) {
console.error('Error sending message:', error);
showError(`Failed to send message: ${error.message}`);
addMessage('😔 Sorry, I encountered an error. Please try again or check if the backend is running.', false);
} finally {
setLoading(false);
messageInput.focus();
}
}
// Auto-focus input when clicking anywhere in chat area
chatMessages.addEventListener('click', () => {
if (!messageInput.disabled) {
messageInput.focus();
}
});
// Check health status periodically
setInterval(checkHealth, 30000); // Check every 30 seconds
</script>
</body>
</html>