dfrokido commited on
Commit
4f1d121
·
verified ·
1 Parent(s): 6e0bea2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -92
app.py CHANGED
@@ -166,96 +166,4 @@ with gr.Blocks(title="Persistent 3D Cortex Demo") as demo:
166
  outputs=[viewer_output, status_output]
167
  )
168
 
169
- demo.launch()
170
- def export_ply(self, path="output.ply"):
171
- # Prepare vertex data matching gsplat.js expected properties
172
- zeros = np.zeros((self.num, 3), dtype=np.float32)
173
- log_scales = np.log(self.scales.cpu().numpy()).astype(np.float32)
174
-
175
- vertex_data = np.core.records.fromarrays([
176
- self.positions.cpu().numpy().astype(np.float32),
177
- zeros, # normals (unused)
178
- self.colors.cpu().numpy().astype(np.float32),
179
- self.opacities.cpu().numpy().astype(np.float32),
180
- log_scales,
181
- self.rotations.cpu().numpy().astype(np.float32)
182
- ], names='x,y,z,nx,ny,nz,f_dc_0,f_dc_1,f_dc_2,opacity,scale_0,scale_1,scale_2,rot_0,rot_1,rot_2,rot_3')
183
-
184
- el = plyfile.PlyElement.describe(vertex_data, 'vertex')
185
- plyfile.PlyData([el], text=True).write(path)
186
- return os.path.abspath(path)
187
-
188
- def process(image: Image.Image, prompt: str = ""):
189
- cortex = PersistentCortex(num_gaussians=8000)
190
- cortex.evolve_from_image(image, steps=800)
191
- if prompt:
192
- cortex.condition_on_prompt(prompt)
193
-
194
- ply_path = cortex.export_ply("/tmp/output.ply")
195
-
196
- # In Hugging Face Spaces, /tmp files are automatically served under /files/
197
- viewer_html = f"""
198
- <div id="viewer" style="width:100%; height:600px; background:#000;"></div>
199
- <script type="module">
200
- import * as SPLAT from "https://cdn.jsdelivr.net/npm/gsplat@latest";
201
-
202
- const container = document.getElementById('viewer');
203
- const canvas = document.createElement('canvas');
204
- canvas.style.width = '100%';
205
- canvas.style.height = '100%';
206
- container.appendChild(canvas);
207
-
208
- const scene = new SPLAT.Scene();
209
- const camera = new SPLAT.Camera();
210
- const renderer = new SPLAT.WebGLRenderer({{ canvas }});
211
- const controls = new SPLAT.OrbitControls(camera, canvas);
212
-
213
- controls.autoRotate = false;
214
- controls.enableDamping = true;
215
- controls.dampingFactor = 0.05;
216
- controls.rotateSpeed = 1.0;
217
- controls.zoomSpeed = 1.2;
218
- controls.panSpeed = 0.8;
219
-
220
- await SPLAT.Loader.LoadAsync("/files/output.ply", scene);
221
-
222
- function animate() {{
223
- controls.update();
224
- renderer.render(scene, camera);
225
- requestAnimationFrame(animate);
226
- }}
227
- animate();
228
- </script>
229
- """
230
-
231
- status = "3D Gaussian splat generated and evolved from your image"
232
- if prompt:
233
- status += f" with prompt conditioning: '{prompt}'."
234
- else:
235
- status += "."
236
-
237
- return viewer_html, status
238
-
239
- with gr.Blocks(title="Persistent 3D Cortex Demo") as demo:
240
- gr.Markdown("# Persistent 3D Cortex – Interactive Demo")
241
- gr.Markdown("""
242
- Upload an image and optionally add a text prompt.
243
- The system evolves a persistent 3D Gaussian splat representation influenced by the image content and prompt.
244
- """)
245
-
246
- with gr.Row():
247
- img_input = gr.Image(type="pil", label="Input Image")
248
- prompt_input = gr.Textbox(label="Prompt (e.g., 'shiny red apple', 'futuristic city')", placeholder="Optional text prompt")
249
-
250
- generate_btn = gr.Button("Generate & Evolve 3D", variant="primary")
251
-
252
- viewer_output = gr.HTML(label="Interactive 3D Viewer")
253
- status_output = gr.Textbox(label="Status")
254
-
255
- generate_btn.click(
256
- fn=process,
257
- inputs=[img_input, prompt_input],
258
- outputs=[viewer_output, status_output]
259
- )
260
-
261
  demo.launch()
 
166
  outputs=[viewer_output, status_output]
167
  )
168
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  demo.launch()