Spaces:
Sleeping
Sleeping
Update templates/index.html
Browse files- templates/index.html +78 -0
templates/index.html
CHANGED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 Excel Analyzer</title>
|
| 7 |
+
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
| 8 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 9 |
+
</head>
|
| 10 |
+
<body class="bg-gray-100 flex items-center justify-center min-h-screen">
|
| 11 |
+
<div class="bg-white/20 backdrop-blur-md rounded-2xl p-8 shadow-lg w-full max-w-4xl">
|
| 12 |
+
<h1 class="text-3xl font-bold text-center text-white mb-6">AI Excel Analyzer</h1>
|
| 13 |
+
|
| 14 |
+
<form id="uploadForm" class="mb-6">
|
| 15 |
+
<input type="file" name="file" id="fileInput" class="mb-4 p-2 rounded border">
|
| 16 |
+
<button type="submit" class="bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600">Upload & Analyze</button>
|
| 17 |
+
</form>
|
| 18 |
+
|
| 19 |
+
<div id="metadataSection" class="text-white mb-4"></div>
|
| 20 |
+
<div id="suggestionsSection" class="text-white mb-4"></div>
|
| 21 |
+
|
| 22 |
+
<div class="bg-white/10 p-4 rounded-lg">
|
| 23 |
+
<canvas id="chartCanvas" class="w-full h-96"></canvas>
|
| 24 |
+
</div>
|
| 25 |
+
</div>
|
| 26 |
+
|
| 27 |
+
<script>
|
| 28 |
+
const uploadForm = document.getElementById("uploadForm");
|
| 29 |
+
const metadataSection = document.getElementById("metadataSection");
|
| 30 |
+
const suggestionsSection = document.getElementById("suggestionsSection");
|
| 31 |
+
let uploadedFilePath = "";
|
| 32 |
+
|
| 33 |
+
uploadForm.addEventListener("submit", async (e) => {
|
| 34 |
+
e.preventDefault();
|
| 35 |
+
const fileInput = document.getElementById("fileInput");
|
| 36 |
+
const formData = new FormData();
|
| 37 |
+
formData.append("file", fileInput.files[0]);
|
| 38 |
+
|
| 39 |
+
const response = await fetch("/upload", { method: "POST", body: formData });
|
| 40 |
+
const data = await response.json();
|
| 41 |
+
uploadedFilePath = data.file_path;
|
| 42 |
+
|
| 43 |
+
metadataSection.innerHTML = `<pre>${JSON.stringify(data.metadata, null, 2)}</pre>`;
|
| 44 |
+
suggestionsSection.innerHTML = "<h3>Select a suggestion:</h3>";
|
| 45 |
+
|
| 46 |
+
data.analysis.Suggestion.forEach((s, i) => {
|
| 47 |
+
const btn = document.createElement("button");
|
| 48 |
+
btn.textContent = `Suggestion ${i+1}`;
|
| 49 |
+
btn.className = "bg-green-500 text-white px-3 py-1 m-1 rounded hover:bg-green-600";
|
| 50 |
+
btn.addEventListener("click", () => generatePlot(s));
|
| 51 |
+
suggestionsSection.appendChild(btn);
|
| 52 |
+
});
|
| 53 |
+
});
|
| 54 |
+
|
| 55 |
+
async function generatePlot(command) {
|
| 56 |
+
const formData = new FormData();
|
| 57 |
+
formData.append("command", command);
|
| 58 |
+
formData.append("file_path", uploadedFilePath);
|
| 59 |
+
|
| 60 |
+
const response = await fetch("/generate_plot", { method: "POST", body: formData });
|
| 61 |
+
const vizData = await response.json();
|
| 62 |
+
|
| 63 |
+
const ctx = document.getElementById("chartCanvas").getContext("2d");
|
| 64 |
+
if(window.myChart) window.myChart.destroy();
|
| 65 |
+
|
| 66 |
+
const data = JSON.parse(vizData.code); // Assuming Gemini outputs JSON data
|
| 67 |
+
window.myChart = new Chart(ctx, {
|
| 68 |
+
type: vizData.type,
|
| 69 |
+
data: {
|
| 70 |
+
labels: data.labels,
|
| 71 |
+
datasets: [{ label: vizData.explanation, data: data.values, backgroundColor: "rgba(255,255,255,0.6)" }]
|
| 72 |
+
},
|
| 73 |
+
options: { responsive: true, plugins: { legend: { labels: { color: "white" }}}}
|
| 74 |
+
});
|
| 75 |
+
}
|
| 76 |
+
</script>
|
| 77 |
+
</body>
|
| 78 |
+
</html>
|