Learner / index.html
Sahil
Update index.html
31c58d7 verified
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ContinuumGPT Chat</title>
<script src="https://js.puter.com/v2/"></script>
<style>
body {
font-family: sans-serif;
max-width: 600px;
margin: 50px auto;
text-align: center;
}
#chat {
border: 1px solid #ddd;
padding: 15px;
height: 400px;
overflow-y: auto;
text-align: left;
}
.msg { margin: 10px 0; }
.user { color: #1a73e8; }
.bot { color: #2b7a0b; }
#status { font-size: 0.9em; color: gray; margin-bottom: 10px; }
#prompt { width: 80%; }
</style>
</head>
<body>
<h1>🧠 ContinuumGPT</h1>
<div id="status">Connecting to Puter...</div>
<div id="chat"></div>
<input id="prompt" placeholder="Ask something..." disabled />
<button id="sendBtn" onclick="sendPrompt()" disabled>Send</button>
<script>
let user = null;
async function initPuter() {
const status = document.getElementById("status");
try {
// Force authentication popup
status.textContent = "πŸ” Requesting Puter login...";
user = await puter.auth.requestAuth();
status.textContent = `βœ… Logged in as ${user?.username || "guest"}`;
// Enable chat input
document.getElementById("prompt").disabled = false;
document.getElementById("sendBtn").disabled = false;
} catch (err) {
console.error("Puter auth failed:", err);
status.textContent = "⚠️ Login failed β€” please refresh to try again.";
}
}
async function sendPrompt() {
const promptInput = document.getElementById("prompt");
const prompt = promptInput.value.trim();
if (!prompt) return;
appendMessage("user", prompt);
promptInput.value = "";
try {
// Use Puter.ai to generate response
const reply = await puter.ai.chat(prompt, { model: "gpt-4o-mini" });
const response = reply?.message || "No response";
appendMessage("bot", response);
// Save chat to Flask backend (writes to HF dataset)
await fetch("/save", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ prompt, response })
});
} catch (err) {
console.error(err);
appendMessage("bot", "⚠️ Error: " + err.message);
}
}
function appendMessage(role, text) {
const chat = document.getElementById("chat");
const div = document.createElement("div");
div.className = "msg " + role;
div.textContent = (role === "user" ? "πŸ‘€ " : "πŸ€– ") + text;
chat.appendChild(div);
chat.scrollTop = chat.scrollHeight;
}
// Initialize auth on load
window.onload = initPuter;
</script>
</body>
</html>