Update templates/index.html
Browse files- templates/index.html +118 -52
templates/index.html
CHANGED
|
@@ -1,52 +1,118 @@
|
|
| 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>AI Plotting
|
| 7 |
-
<link href="/static/tailwind.css" rel="stylesheet">
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
</
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
<div class="w-full
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
</div>
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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>AI Plotting Chatbot</title>
|
| 7 |
+
<link href="/static/tailwind.css" rel="stylesheet">
|
| 8 |
+
<style>
|
| 9 |
+
/* Ensure input fields and buttons resize nicely on mobile keyboard pop-up */
|
| 10 |
+
html, body { height: 100%; margin: 0; padding: 0; }
|
| 11 |
+
body { display: flex; flex-direction: column; justify-content: flex-start; align-items: center; }
|
| 12 |
+
#chatContainer { max-width: 600px; width: 100%; flex: 1; display: flex; flex-direction: column; overflow-y: auto; margin-bottom: 1rem; }
|
| 13 |
+
.message { padding: 0.5rem 1rem; border-radius: 12px; margin-bottom: 0.5rem; max-width: 80%; }
|
| 14 |
+
.userMsg { background-color: #3b82f6; color: white; align-self: flex-end; }
|
| 15 |
+
.botMsg { background-color: #f3f4f6; color: #111827; align-self: flex-start; }
|
| 16 |
+
</style>
|
| 17 |
+
</head>
|
| 18 |
+
<body class="bg-gray-100 p-4">
|
| 19 |
+
|
| 20 |
+
<h1 class="text-2xl font-bold mb-4 text-center">AI Plotting Chatbot</h1>
|
| 21 |
+
|
| 22 |
+
<div class="w-full max-w-lg flex flex-col items-center mb-4">
|
| 23 |
+
<input id="excelFile" type="file" accept=".xlsx" class="w-full mb-2 p-2 border rounded-xl shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-400" />
|
| 24 |
+
<div class="flex w-full">
|
| 25 |
+
<input id="userQuery" type="text" placeholder="Enter plot request..." class="flex-1 p-2 border rounded-l-xl shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-400" />
|
| 26 |
+
<button onclick="sendMessage()" class="bg-blue-600 text-white px-4 rounded-r-xl">➡</button>
|
| 27 |
+
</div>
|
| 28 |
+
</div>
|
| 29 |
+
|
| 30 |
+
<div id="chatContainer" class="w-full max-w-lg bg-white p-4 rounded-xl shadow flex flex-col">
|
| 31 |
+
<!-- Messages will appear here -->
|
| 32 |
+
</div>
|
| 33 |
+
|
| 34 |
+
<div class="w-full max-w-lg bg-white p-4 rounded-xl shadow mt-4">
|
| 35 |
+
<h2 class="font-bold mb-2">Plot Output</h2>
|
| 36 |
+
<img id="plotImg" class="w-full rounded-xl shadow" />
|
| 37 |
+
</div>
|
| 38 |
+
|
| 39 |
+
<div class="w-full max-w-lg bg-white p-4 rounded-xl shadow mt-4 mb-8">
|
| 40 |
+
<h2 class="font-bold mb-2">Generated Code & Console</h2>
|
| 41 |
+
<pre id="consoleOutput" class="overflow-x-auto text-sm"></pre>
|
| 42 |
+
</div>
|
| 43 |
+
|
| 44 |
+
<script>
|
| 45 |
+
const chatContainer = document.getElementById("chatContainer");
|
| 46 |
+
|
| 47 |
+
function addMessage(content, type="botMsg") {
|
| 48 |
+
const msg = document.createElement("div");
|
| 49 |
+
msg.className = `message ${type}`;
|
| 50 |
+
msg.textContent = content;
|
| 51 |
+
chatContainer.appendChild(msg);
|
| 52 |
+
chatContainer.scrollTop = chatContainer.scrollHeight;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
async function sendMessage() {
|
| 56 |
+
const fileInput = document.getElementById("excelFile");
|
| 57 |
+
const queryInput = document.getElementById("userQuery");
|
| 58 |
+
|
| 59 |
+
if (!fileInput.files.length) { alert("Please upload a file."); return; }
|
| 60 |
+
if (!queryInput.value.trim()) { return; }
|
| 61 |
+
|
| 62 |
+
// Add user message
|
| 63 |
+
addMessage(queryInput.value.trim(), "userMsg");
|
| 64 |
+
|
| 65 |
+
const formData = new FormData();
|
| 66 |
+
formData.append("file", fileInput.files[0]);
|
| 67 |
+
formData.append("query", queryInput.value.trim());
|
| 68 |
+
|
| 69 |
+
// Clear input
|
| 70 |
+
queryInput.value = "";
|
| 71 |
+
|
| 72 |
+
// Add bot loading message
|
| 73 |
+
const loadingMsg = document.createElement("div");
|
| 74 |
+
loadingMsg.className = "message botMsg";
|
| 75 |
+
loadingMsg.textContent = "Processing...";
|
| 76 |
+
chatContainer.appendChild(loadingMsg);
|
| 77 |
+
chatContainer.scrollTop = chatContainer.scrollHeight;
|
| 78 |
+
|
| 79 |
+
try {
|
| 80 |
+
const response = await fetch("/generate_plot_file", {
|
| 81 |
+
method: "POST",
|
| 82 |
+
body: formData
|
| 83 |
+
});
|
| 84 |
+
const data = await response.json();
|
| 85 |
+
|
| 86 |
+
// Remove loading
|
| 87 |
+
chatContainer.removeChild(loadingMsg);
|
| 88 |
+
|
| 89 |
+
// Display bot message
|
| 90 |
+
addMessage("Plot generated.", "botMsg");
|
| 91 |
+
|
| 92 |
+
// Display plot
|
| 93 |
+
if(data.success){
|
| 94 |
+
document.getElementById("plotImg").src = "data:image/png;base64," + data.plot;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
// Display code
|
| 98 |
+
document.getElementById("consoleOutput").textContent = data.code;
|
| 99 |
+
|
| 100 |
+
} catch (err) {
|
| 101 |
+
chatContainer.removeChild(loadingMsg);
|
| 102 |
+
addMessage("Error generating plot: " + err.message, "botMsg");
|
| 103 |
+
}
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
// Handle mobile keyboard resize
|
| 107 |
+
window.addEventListener('resize', () => {
|
| 108 |
+
chatContainer.scrollTop = chatContainer.scrollHeight;
|
| 109 |
+
});
|
| 110 |
+
|
| 111 |
+
// Enter key triggers send
|
| 112 |
+
document.getElementById("userQuery").addEventListener("keypress", function(e) {
|
| 113 |
+
if (e.key === "Enter") sendMessage();
|
| 114 |
+
});
|
| 115 |
+
</script>
|
| 116 |
+
|
| 117 |
+
</body>
|
| 118 |
+
</html>
|