Spaces:
Runtime error
Runtime error
Create index.html
Browse files- index.html +119 -0
index.html
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>SHIELD v1.0</title>
|
| 7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
+
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
|
| 9 |
+
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;700&display=swap" rel="stylesheet">
|
| 10 |
+
<style>
|
| 11 |
+
body { font-family: 'JetBrains Mono', monospace; background-color: #050505; color: #00ff41; }
|
| 12 |
+
.glass { background: rgba(20, 20, 20, 0.8); backdrop-filter: blur(12px); border: 1px solid rgba(0, 255, 65, 0.2); }
|
| 13 |
+
.user-msg { background: rgba(0, 255, 65, 0.1); border: 1px solid #00ff41; color: #fff; }
|
| 14 |
+
.ai-msg { background: rgba(255, 255, 255, 0.05); border-left: 3px solid #00ff41; color: #ccc; }
|
| 15 |
+
.typing-dot { animation: pulse 1.5s infinite; }
|
| 16 |
+
@keyframes pulse { 0%, 100% { opacity: 0.3; } 50% { opacity: 1; } }
|
| 17 |
+
/* Scrollbar */
|
| 18 |
+
::-webkit-scrollbar { width: 8px; }
|
| 19 |
+
::-webkit-scrollbar-thumb { background: #333; border-radius: 4px; }
|
| 20 |
+
</style>
|
| 21 |
+
</head>
|
| 22 |
+
<body class="h-screen flex flex-col overflow-hidden selection:bg-green-900 selection:text-white">
|
| 23 |
+
|
| 24 |
+
<header class="p-4 flex justify-between items-center glass border-b-0 z-50">
|
| 25 |
+
<div class="flex items-center gap-3">
|
| 26 |
+
<div class="w-3 h-3 bg-green-500 rounded-full shadow-[0_0_10px_#00ff41]"></div>
|
| 27 |
+
<h1 class="text-xl font-bold tracking-widest text-white">SHIELD<span class="text-green-500">_API</span></h1>
|
| 28 |
+
</div>
|
| 29 |
+
<div class="text-xs text-gray-500">SECURE_CHANNEL: ENCRYPTED</div>
|
| 30 |
+
</header>
|
| 31 |
+
|
| 32 |
+
<main id="chat-box" class="flex-1 overflow-y-auto p-6 space-y-6 pb-32">
|
| 33 |
+
<div class="ai-msg p-4 rounded-r-xl rounded-bl-xl max-w-3xl">
|
| 34 |
+
<p>System Online. Secure logging active. How can I assist you today?</p>
|
| 35 |
+
</div>
|
| 36 |
+
</main>
|
| 37 |
+
|
| 38 |
+
<footer class="fixed bottom-0 w-full p-4 bg-gradient-to-t from-black via-black to-transparent">
|
| 39 |
+
<div class="max-w-4xl mx-auto glass rounded-xl flex items-center p-2 gap-2">
|
| 40 |
+
<input id="user-input" type="text" placeholder="Enter command or query..."
|
| 41 |
+
class="bg-transparent flex-1 outline-none text-white px-4 py-3 placeholder-gray-700"
|
| 42 |
+
onkeydown="if(event.key === 'Enter') sendMessage()">
|
| 43 |
+
|
| 44 |
+
<button onclick="sendMessage()" class="bg-green-600 hover:bg-green-500 text-black font-bold px-6 py-3 rounded-lg transition shadow-[0_0_15px_rgba(0,255,65,0.3)]">
|
| 45 |
+
SEND
|
| 46 |
+
</button>
|
| 47 |
+
</div>
|
| 48 |
+
<div class="text-center text-[10px] text-gray-700 mt-2">MONITORED BY TiDB CLOUD • v1.0.5</div>
|
| 49 |
+
</footer>
|
| 50 |
+
|
| 51 |
+
<script>
|
| 52 |
+
const chatBox = document.getElementById('chat-box');
|
| 53 |
+
const userInput = document.getElementById('user-input');
|
| 54 |
+
|
| 55 |
+
async function sendMessage() {
|
| 56 |
+
const text = userInput.value.trim();
|
| 57 |
+
if (!text) return;
|
| 58 |
+
|
| 59 |
+
// 1. Add User Message
|
| 60 |
+
appendMessage('user', text);
|
| 61 |
+
userInput.value = '';
|
| 62 |
+
|
| 63 |
+
// 2. Add Loading State
|
| 64 |
+
const loadingId = 'loading-' + Date.now();
|
| 65 |
+
chatBox.innerHTML += `
|
| 66 |
+
<div id="${loadingId}" class="ai-msg p-4 rounded-r-xl rounded-bl-xl max-w-3xl flex gap-1">
|
| 67 |
+
<span class="typing-dot">●</span><span class="typing-dot" style="animation-delay:0.2s">●</span><span class="typing-dot" style="animation-delay:0.4s">●</span>
|
| 68 |
+
</div>`;
|
| 69 |
+
chatBox.scrollTo(0, chatBox.scrollHeight);
|
| 70 |
+
|
| 71 |
+
try {
|
| 72 |
+
// 3. Send to your Python Shield
|
| 73 |
+
const response = await fetch('/v1/chat/completions', {
|
| 74 |
+
method: 'POST',
|
| 75 |
+
headers: { 'Content-Type': 'application/json' },
|
| 76 |
+
body: JSON.stringify({
|
| 77 |
+
model: "gemini-pro", // Default model
|
| 78 |
+
messages: [{ role: "user", content: text }]
|
| 79 |
+
})
|
| 80 |
+
});
|
| 81 |
+
|
| 82 |
+
const data = await response.json();
|
| 83 |
+
document.getElementById(loadingId).remove();
|
| 84 |
+
|
| 85 |
+
if (response.status === 403) {
|
| 86 |
+
// Handle Policy Block
|
| 87 |
+
appendMessage('error', "🚫 ACCESS DENIED: " + data.error.message);
|
| 88 |
+
} else if (data.choices) {
|
| 89 |
+
// Handle Success
|
| 90 |
+
appendMessage('ai', data.choices[0].message.content);
|
| 91 |
+
} else {
|
| 92 |
+
appendMessage('error', "System Error: " + JSON.stringify(data));
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
} catch (err) {
|
| 96 |
+
document.getElementById(loadingId).remove();
|
| 97 |
+
appendMessage('error', "CONNECTION_LOST: " + err.message);
|
| 98 |
+
}
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
function appendMessage(role, text) {
|
| 102 |
+
const div = document.createElement('div');
|
| 103 |
+
if (role === 'user') {
|
| 104 |
+
div.className = "flex justify-end";
|
| 105 |
+
div.innerHTML = `<div class="user-msg p-4 rounded-l-xl rounded-br-xl max-w-[80%]">${text.replace(/</g, "<")}</div>`;
|
| 106 |
+
} else if (role === 'error') {
|
| 107 |
+
div.className = "flex justify-start";
|
| 108 |
+
div.innerHTML = `<div class="bg-red-900/30 border border-red-500 text-red-400 p-4 rounded-r-xl rounded-bl-xl max-w-3xl font-bold">${text}</div>`;
|
| 109 |
+
} else {
|
| 110 |
+
div.className = "flex justify-start";
|
| 111 |
+
// Parse Markdown for AI response
|
| 112 |
+
div.innerHTML = `<div class="ai-msg p-4 rounded-r-xl rounded-bl-xl max-w-3xl prose prose-invert prose-p:text-gray-300 prose-code:text-green-400">${marked.parse(text)}</div>`;
|
| 113 |
+
}
|
| 114 |
+
chatBox.appendChild(div);
|
| 115 |
+
chatBox.scrollTo(0, chatBox.scrollHeight);
|
| 116 |
+
}
|
| 117 |
+
</script>
|
| 118 |
+
</body>
|
| 119 |
+
</html>
|