let chart;
async function fetchMessages() {
const res = await fetch("http://127.0.0.1:8000/get_messages");
const data = await res.json();
const container = document.getElementById("chat-container");
container.innerHTML = "";
data.forEach(msg => {
const div = document.createElement("div");
div.className = "chat-card";
let color = "gray";
if (msg.sentiment === "Positive") color = "green";
else if (msg.sentiment === "Negative") color = "red";
else color = "orange";
div.innerHTML = `
${msg.author}: ${msg.text}
${msg.sentiment} (${msg.confidence})