Skip to content

Commit a281900

Browse files
committed
simplify
1 parent c72c16c commit a281900

43 files changed

Lines changed: 221 additions & 572 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/deploy.yml

Lines changed: 0 additions & 47 deletions
This file was deleted.

.nojekyll

Whitespace-only changes.

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Robotic Perception, Interaction, and Learning Lab
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# code-diffuser

app.js

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
// Precomputed point clouds
2+
const POINT_CLOUDS = {
3+
1: generateSphere(1000),
4+
2: generateCube(1000),
5+
3: generateTorus(1000),
6+
4: generateCylinder(1000),
7+
5: generatePyramid(1000)
8+
};
9+
10+
// Function to generate point cloud based on instruction
11+
async function processInstruction() {
12+
const apiKey = document.getElementById('apiKey').value;
13+
const instruction = document.getElementById('instruction').value;
14+
15+
if (!apiKey) {
16+
alert('Please enter your OpenAI API Key');
17+
return;
18+
}
19+
if (!instruction) {
20+
alert('Please enter an instruction');
21+
return;
22+
}
23+
24+
// Show loading spinner
25+
document.getElementById('loading').style.display = 'block';
26+
27+
try {
28+
// Call OpenAI API
29+
const response = await fetch('https://api.openai.com/v1/chat/completions', {
30+
method: 'POST',
31+
headers: {
32+
'Content-Type': 'application/json',
33+
'Authorization': `Bearer ${apiKey}`
34+
},
35+
body: JSON.stringify({
36+
model: "gpt-3.5-turbo",
37+
messages: [{
38+
role: "user",
39+
content: `Based on this instruction: "${instruction}", select the most appropriate 3D shape from these options:
40+
1: Sphere
41+
2: Cube
42+
3: Torus
43+
4: Cylinder
44+
5: Pyramid
45+
46+
Return only a JSON object with a single number: {"selection": number}`
47+
}]
48+
})
49+
});
50+
51+
const data = await response.json();
52+
if (!response.ok) {
53+
throw new Error(data.error?.message || 'API request failed');
54+
}
55+
56+
const selection = JSON.parse(data.choices[0].message.content).selection;
57+
if (selection >= 1 && selection <= 5) {
58+
visualizePointCloud(POINT_CLOUDS[selection]);
59+
} else {
60+
throw new Error('Invalid selection');
61+
}
62+
} catch (error) {
63+
console.error('Error:', error);
64+
alert('Error: ' + error.message);
65+
} finally {
66+
// Hide loading spinner
67+
document.getElementById('loading').style.display = 'none';
68+
}
69+
}
70+
71+
// Function to visualize point cloud using Plotly
72+
function visualizePointCloud(points) {
73+
const x = points.map(p => p[0]);
74+
const y = points.map(p => p[1]);
75+
const z = points.map(p => p[2]);
76+
77+
const trace = {
78+
type: 'scatter3d',
79+
mode: 'markers',
80+
x: x,
81+
y: y,
82+
z: z,
83+
marker: {
84+
size: 2,
85+
color: z,
86+
colorscale: 'Viridis',
87+
opacity: 0.8
88+
}
89+
};
90+
91+
const layout = {
92+
title: '3D Point Cloud Visualization',
93+
scene: {
94+
xaxis: { title: 'X' },
95+
yaxis: { title: 'Y' },
96+
zaxis: { title: 'Z' }
97+
},
98+
margin: {
99+
l: 0,
100+
r: 0,
101+
b: 0,
102+
t: 30
103+
}
104+
};
105+
106+
Plotly.newPlot('visualization', [trace], layout);
107+
}
108+
109+
// Point cloud generation functions
110+
function generateSphere(numPoints) {
111+
const points = [];
112+
for (let i = 0; i < numPoints; i++) {
113+
const theta = Math.random() * 2 * Math.PI;
114+
const phi = Math.acos(2 * Math.random() - 1);
115+
const r = 1;
116+
117+
const x = r * Math.sin(phi) * Math.cos(theta);
118+
const y = r * Math.sin(phi) * Math.sin(theta);
119+
const z = r * Math.cos(phi);
120+
121+
points.push([x, y, z]);
122+
}
123+
return points;
124+
}
125+
126+
function generateCube(numPoints) {
127+
const points = [];
128+
for (let i = 0; i < numPoints; i++) {
129+
const x = Math.random() * 2 - 1;
130+
const y = Math.random() * 2 - 1;
131+
const z = Math.random() * 2 - 1;
132+
points.push([x, y, z]);
133+
}
134+
return points;
135+
}
136+
137+
function generateTorus(numPoints) {
138+
const points = [];
139+
const R = 1; // major radius
140+
const r = 0.3; // minor radius
141+
for (let i = 0; i < numPoints; i++) {
142+
const theta = Math.random() * 2 * Math.PI;
143+
const phi = Math.random() * 2 * Math.PI;
144+
145+
const x = (R + r * Math.cos(phi)) * Math.cos(theta);
146+
const y = (R + r * Math.cos(phi)) * Math.sin(theta);
147+
const z = r * Math.sin(phi);
148+
149+
points.push([x, y, z]);
150+
}
151+
return points;
152+
}
153+
154+
function generateCylinder(numPoints) {
155+
const points = [];
156+
const height = 2;
157+
const radius = 0.5;
158+
for (let i = 0; i < numPoints; i++) {
159+
const theta = Math.random() * 2 * Math.PI;
160+
const h = Math.random() * height - height/2;
161+
162+
const x = radius * Math.cos(theta);
163+
const y = radius * Math.sin(theta);
164+
const z = h;
165+
166+
points.push([x, y, z]);
167+
}
168+
return points;
169+
}
170+
171+
function generatePyramid(numPoints) {
172+
const points = [];
173+
const size = 2;
174+
for (let i = 0; i < numPoints; i++) {
175+
const x = Math.random() * size - size/2;
176+
const y = Math.random() * size - size/2;
177+
const z = Math.random() * size;
178+
179+
// Create pyramid shape by scaling z based on distance from center
180+
const distFromCenter = Math.sqrt(x*x + y*y);
181+
const scale = 1 - (distFromCenter / (size/2));
182+
const finalZ = z * scale;
183+
184+
points.push([x, y, finalZ]);
185+
}
186+
return points;
187+
}
188+
189+
// Add event listener for Enter key
190+
document.getElementById('instruction').addEventListener('keypress', function(e) {
191+
if (e.key === 'Enter') {
192+
processInstruction();
193+
}
194+
});

dist/bundle.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

index.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
<div class="container">
3737
<h1 class="mb-4">3D Point Cloud Generator</h1>
3838

39+
<div class="input-group mb-3">
40+
<input type="password" id="apiKey" class="form-control" placeholder="Enter your OpenAI API Key">
41+
</div>
42+
3943
<div class="input-group">
4044
<input type="text" id="instruction" class="form-control" placeholder="Enter your instruction (e.g., 'Generate a sphere with 1000 points')">
4145
<button class="btn btn-primary" onclick="processInstruction()">Generate</button>
@@ -50,7 +54,7 @@ <h1 class="mb-4">3D Point Cloud Generator</h1>
5054
<div id="visualization"></div>
5155
</div>
5256

53-
<script src="dist/bundle.js"></script>
57+
<script src="app.js"></script>
5458
</body>
5559
</html>
5660

node_modules/babel-preset-current-node-syntax/.github/FUNDING.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

node_modules/babel-preset-current-node-syntax/.github/workflows/nodejs.yml

Lines changed: 0 additions & 49 deletions
This file was deleted.

node_modules/balanced-match/.github/FUNDING.yml

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)