Spaces:
Running
Running
Update templates/index.html
Browse files- templates/index.html +119 -16
templates/index.html
CHANGED
@@ -3,29 +3,132 @@
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
-
<title>Python Parser</title>
|
7 |
<script src="https://cdn.tailwindcss.com"></script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
</head>
|
9 |
-
<body class="bg-gray-
|
10 |
-
<div class="bg-
|
11 |
-
<h1 class="text-3xl font-bold text-
|
12 |
-
|
13 |
-
<!--
|
14 |
-
<form
|
15 |
<div>
|
16 |
-
<label class="block text-sm font-medium text-gray-
|
17 |
-
<input type="file" name="file" accept=".py" class="w-full p-2 border rounded-lg
|
18 |
</div>
|
19 |
-
|
20 |
-
<!-- Paste Code -->
|
21 |
<div>
|
22 |
-
<label class="block text-sm font-medium text-gray-
|
23 |
-
<textarea name="code" rows="6" class="w-full p-2 border rounded-lg
|
24 |
-
<input type="text" name="filename" class="mt-2 w-full p-2 border rounded-lg" placeholder="Enter filename (e.g., script.py)">
|
25 |
</div>
|
26 |
-
|
27 |
-
<button type="submit" class="w-full bg-blue-600 text-white p-2 rounded-lg hover:bg-blue-700 transition">Parse</button>
|
28 |
</form>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
</body>
|
31 |
</html>
|
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Python Code Parser</title>
|
7 |
<script src="https://cdn.tailwindcss.com"></script>
|
8 |
+
<script src="https://unpkg.com/[email protected]"></script>
|
9 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r134/three.min.js"></script>
|
10 |
+
<style>
|
11 |
+
.table-container { overflow-x: auto; }
|
12 |
+
pre { white-space: pre-wrap; word-wrap: break-word; }
|
13 |
+
#point-cloud { display: none; width: 100%; height: 400px; }
|
14 |
+
#point-details { width: 100%; min-height: 100px; background: #1f2937; padding: 1rem; border-radius: 0.5rem; }
|
15 |
+
</style>
|
16 |
</head>
|
17 |
+
<body class="bg-gray-900 text-gray-200 min-h-screen p-8 font-sans">
|
18 |
+
<div class="max-w-7xl mx-auto bg-gray-800 p-6 rounded-xl shadow-2xl">
|
19 |
+
<h1 class="text-3xl font-bold text-blue-400 mb-6">Python Code Parser</h1>
|
20 |
+
|
21 |
+
<!-- Form -->
|
22 |
+
<form hx-post="/" hx-target="#results" hx-swap="innerHTML" class="space-y-6">
|
23 |
<div>
|
24 |
+
<label class="block text-sm font-medium text-gray-300 mb-2">Upload a Python File</label>
|
25 |
+
<input type="file" name="file" accept=".py" class="w-full p-2 border rounded-lg bg-gray-700 text-gray-200">
|
26 |
</div>
|
|
|
|
|
27 |
<div>
|
28 |
+
<label class="block text-sm font-medium text-gray-300 mb-2">Or Paste Your Code</label>
|
29 |
+
<textarea name="code" rows="6" class="w-full p-2 border rounded-lg bg-gray-700 text-gray-200" placeholder="Paste Python code here...">{{ code_input or '' }}</textarea>
|
30 |
+
<input type="text" name="filename" class="mt-2 w-full p-2 border rounded-lg bg-gray-700 text-gray-200" placeholder="Enter filename (e.g., script.py)" value="{{ filename or '' }}">
|
31 |
</div>
|
32 |
+
<button type="submit" class="w-full bg-blue-500 text-white p-2 rounded-lg hover:bg-blue-600 transition">Parse</button>
|
|
|
33 |
</form>
|
34 |
+
|
35 |
+
<!-- Results Section -->
|
36 |
+
<div id="results" class="mt-8">
|
37 |
+
{% if parts %}
|
38 |
+
{% include 'results_partial.html' %}
|
39 |
+
{% endif %}
|
40 |
+
</div>
|
41 |
</div>
|
42 |
+
|
43 |
+
<!-- Three.js Point Cloud Script -->
|
44 |
+
<script>
|
45 |
+
let scene, camera, renderer, points, raycaster, mouse, hoveredPoint = null;
|
46 |
+
const pointDetails = document.getElementById('point-details');
|
47 |
+
|
48 |
+
function initPointCloud(parts) {
|
49 |
+
scene = new THREE.Scene();
|
50 |
+
camera = new THREE.PerspectiveCamera(75, window.innerWidth / 400, 0.1, 1000);
|
51 |
+
renderer = new THREE.WebGLRenderer({ canvas: document.getElementById('point-cloud') });
|
52 |
+
renderer.setSize(window.innerWidth * 0.9, 400);
|
53 |
+
|
54 |
+
const positions = [];
|
55 |
+
const colors = [];
|
56 |
+
parts.forEach((part, index) => {
|
57 |
+
const vector = part.vector;
|
58 |
+
const x = vector[0] * 10; // category_id
|
59 |
+
const y = vector[1] * 10; // level
|
60 |
+
const z = vector[2] * 100; // center_pos
|
61 |
+
positions.push(x, y, z);
|
62 |
+
colors.push(1, 0.5, 0); // Orange points
|
63 |
+
part.pointIndex = index * 3; // Store index for lookup
|
64 |
+
});
|
65 |
+
|
66 |
+
const geometry = new THREE.BufferGeometry();
|
67 |
+
geometry.setAttribute('position', new THREE.Float32BufferAttribute(positions, 3));
|
68 |
+
geometry.setAttribute('color', new THREE.Float32BufferAttribute(colors, 3));
|
69 |
+
const material = new THREE.PointsMaterial({ size: 5, vertexColors: true });
|
70 |
+
points = new THREE.Points(geometry, material);
|
71 |
+
scene.add(points);
|
72 |
+
|
73 |
+
camera.position.z = 100;
|
74 |
+
raycaster = new THREE.Raycaster();
|
75 |
+
mouse = new THREE.Vector2();
|
76 |
+
|
77 |
+
animate();
|
78 |
+
}
|
79 |
+
|
80 |
+
function animate() {
|
81 |
+
requestAnimationFrame(animate);
|
82 |
+
points.rotation.y += 0.005;
|
83 |
+
renderer.render(scene, camera);
|
84 |
+
}
|
85 |
+
|
86 |
+
function onMouseMove(event) {
|
87 |
+
const rect = renderer.domElement.getBoundingClientRect();
|
88 |
+
mouse.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
|
89 |
+
mouse.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
|
90 |
+
|
91 |
+
raycaster.setFromCamera(mouse, camera);
|
92 |
+
const intersects = raycaster.intersectObject(points);
|
93 |
+
if (intersects.length > 0) {
|
94 |
+
const index = intersects[0].index;
|
95 |
+
const part = window.parts.find(p => p.pointIndex === index * 3);
|
96 |
+
if (part && hoveredPoint !== part) {
|
97 |
+
hoveredPoint = part;
|
98 |
+
pointDetails.innerHTML = `
|
99 |
+
<div class="text-gray-200">
|
100 |
+
<strong>Category:</strong> ${part.category}<br>
|
101 |
+
<strong>Node ID:</strong> ${part.node_id}<br>
|
102 |
+
<strong>Parent Path:</strong> ${part.parent_path}<br>
|
103 |
+
<strong>Level:</strong> ${part.level}<br>
|
104 |
+
<strong>Location:</strong> Lines ${part.location[0]} to ${part.location[1]}<br>
|
105 |
+
<strong>Vector:</strong> [${part.vector.join(', ')}]<br>
|
106 |
+
<strong>Code:</strong><pre class="text-xs text-gray-300">${part.source}</pre>
|
107 |
+
</div>
|
108 |
+
`;
|
109 |
+
}
|
110 |
+
} else {
|
111 |
+
hoveredPoint = null;
|
112 |
+
pointDetails.innerHTML = '<p class="text-gray-400">Hover over a point to see details</p>';
|
113 |
+
}
|
114 |
+
}
|
115 |
+
|
116 |
+
function togglePointCloud() {
|
117 |
+
const canvas = document.getElementById('point-cloud');
|
118 |
+
const table = document.getElementById('results-table');
|
119 |
+
if (canvas.style.display === 'none') {
|
120 |
+
canvas.style.display = 'block';
|
121 |
+
table.style.display = 'none';
|
122 |
+
if (!scene && window.parts) {
|
123 |
+
initPointCloud(window.parts);
|
124 |
+
document.addEventListener('mousemove', onMouseMove);
|
125 |
+
}
|
126 |
+
} else {
|
127 |
+
canvas.style.display = 'none';
|
128 |
+
table.style.display = 'block';
|
129 |
+
document.removeEventListener('mousemove', onMouseMove);
|
130 |
+
}
|
131 |
+
}
|
132 |
+
</script>
|
133 |
</body>
|
134 |
</html>
|