prithivMLmods commited on
Commit
554b401
·
verified ·
1 Parent(s): 14cbd2b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -32
app.py CHANGED
@@ -147,7 +147,7 @@ def update_dimensions_on_upload(image):
147
  # --- 3D Lighting Control Component ---
148
  class LightingControl3D(gr.HTML):
149
  """
150
- An enhanced 3D lighting control component using Three.js with orbit controls and shadows.
151
  Outputs: { azimuth: number, elevation: number }
152
  Accepts imageUrl prop to display user's uploaded image on the plane.
153
  """
@@ -168,7 +168,7 @@ class LightingControl3D(gr.HTML):
168
 
169
  // Wait for THREE to load
170
  const initScene = () => {
171
- if (typeof THREE === 'undefined' || typeof THREE.OrbitControls === 'undefined') {
172
  setTimeout(initScene, 100);
173
  return;
174
  }
@@ -188,29 +188,20 @@ class LightingControl3D(gr.HTML):
188
  renderer.shadowMap.type = THREE.PCFSoftShadowMap;
189
  wrapper.insertBefore(renderer.domElement, promptOverlay);
190
 
191
- // Orbit controls
192
- const controls = new THREE.OrbitControls(camera, renderer.domElement);
193
- controls.target.set(0, 0.75, 0);
194
- controls.enableDamping = true;
195
- controls.dampingFactor = 0.05;
196
- controls.update();
197
-
198
  // Lighting
199
  scene.add(new THREE.AmbientLight(0xffffff, 0.3));
200
 
201
- // Ground
202
- const groundGeo = new THREE.PlaneGeometry(10, 10);
203
- const groundMat = new THREE.ShadowMaterial({ opacity: 0.3 });
204
- const ground = new THREE.Mesh(groundGeo, groundMat);
205
- ground.rotation.x = -Math.PI / 2;
206
- ground.position.y = 0;
207
- ground.receiveShadow = true;
208
- scene.add(ground);
209
-
210
  // Grid
211
- const grid = new THREE.GridHelper(10, 20, 0x888888, 0x444444);
212
- grid.position.y = 0.01;
213
- scene.add(grid);
 
 
 
 
 
 
 
214
 
215
  // Constants
216
  const CENTER = new THREE.Vector3(0, 0.75, 0);
@@ -332,12 +323,12 @@ class LightingControl3D(gr.HTML):
332
  const bulbMat = new THREE.MeshStandardMaterial({ color: 0xffff00, emissive: 0xffff00, emissiveIntensity: 1 });
333
  const bulb = new THREE.Mesh(new THREE.SphereGeometry(0.15, 16, 16), bulbMat);
334
  lightGroup.add(bulb);
335
- const pointLight = new THREE.PointLight(0xffffff, 5, 0);
336
  pointLight.castShadow = true;
337
  pointLight.shadow.mapSize.width = 1024;
338
  pointLight.shadow.mapSize.height = 1024;
339
  pointLight.shadow.camera.near = 0.1;
340
- pointLight.shadow.camera.far = 20;
341
  lightGroup.add(pointLight);
342
  scene.add(lightGroup);
343
 
@@ -436,7 +427,6 @@ class LightingControl3D(gr.HTML):
436
  dragTarget.scale.setScalar(1.3);
437
  dragStartMouse.copy(mouse);
438
  canvas.style.cursor = 'grabbing';
439
- controls.enabled = false; // Disable orbit while dragging handles
440
  }
441
  });
442
 
@@ -514,7 +504,6 @@ class LightingControl3D(gr.HTML):
514
  isDragging = false;
515
  dragTarget = null;
516
  canvas.style.cursor = 'default';
517
- controls.enabled = true; // Re-enable orbit
518
  };
519
 
520
  canvas.addEventListener('mouseup', onMouseUp);
@@ -536,7 +525,6 @@ class LightingControl3D(gr.HTML):
536
  dragTarget.material.emissiveIntensity = 1.0;
537
  dragTarget.scale.setScalar(1.3);
538
  dragStartMouse.copy(mouse);
539
- controls.enabled = false;
540
  }
541
  }, { passive: false });
542
 
@@ -584,7 +572,6 @@ class LightingControl3D(gr.HTML):
584
  // Render loop
585
  function render() {
586
  requestAnimationFrame(render);
587
- controls.update();
588
  renderer.render(scene, camera);
589
  }
590
  render();
@@ -650,9 +637,9 @@ css = '''
650
  '''
651
  with gr.Blocks(css=css, theme=gr.themes.Soft()) as demo:
652
  gr.Markdown("""
653
- # 🎬 Qwen Image Edit 2511 — Enhanced 3D Lighting Control
654
 
655
- Control lighting directions using the **3D viewport** or **sliders**. Now with orbit controls (drag to rotate view) and shadows for better visualization.
656
  Using [dx8152/Qwen-Edit-2509-Multi-Angle-Lighting] for precise lighting control.
657
  """)
658
 
@@ -661,8 +648,8 @@ with gr.Blocks(css=css, theme=gr.themes.Soft()) as demo:
661
  with gr.Column(scale=1):
662
  image = gr.Image(label="Input Image", type="pil", height=300)
663
 
664
- gr.Markdown("### 🎮 Enhanced 3D Lighting Control")
665
- gr.Markdown("*Drag the colored handles: 🟢 Azimuth (Direction), 🩷 Elevation (Height). Orbit the view by dragging the background.*")
666
 
667
  lighting_3d = LightingControl3D(
668
  value={"azimuth": 0, "elevation": 0},
@@ -789,6 +776,6 @@ with gr.Blocks(css=css, theme=gr.themes.Soft()) as demo:
789
  )
790
 
791
  if __name__ == "__main__":
792
- head = '<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script><script src="https://cdn.jsdelivr.net/npm/three@0.128/examples/js/controls/OrbitControls.js"></script>'
793
  css = '.fillable{max-width: 1200px !important}'
794
  demo.launch(head=head, css=css)
 
147
  # --- 3D Lighting Control Component ---
148
  class LightingControl3D(gr.HTML):
149
  """
150
+ A 3D lighting control component using Three.js.
151
  Outputs: { azimuth: number, elevation: number }
152
  Accepts imageUrl prop to display user's uploaded image on the plane.
153
  """
 
168
 
169
  // Wait for THREE to load
170
  const initScene = () => {
171
+ if (typeof THREE === 'undefined') {
172
  setTimeout(initScene, 100);
173
  return;
174
  }
 
188
  renderer.shadowMap.type = THREE.PCFSoftShadowMap;
189
  wrapper.insertBefore(renderer.domElement, promptOverlay);
190
 
 
 
 
 
 
 
 
191
  // Lighting
192
  scene.add(new THREE.AmbientLight(0xffffff, 0.3));
193
 
 
 
 
 
 
 
 
 
 
194
  // Grid
195
+ scene.add(new THREE.GridHelper(8, 16, 0x333333, 0x222222));
196
+
197
+ // Floor for shadows
198
+ const floorGeo = new THREE.PlaneGeometry(10, 10);
199
+ const floorMat = new THREE.ShadowMaterial({ opacity: 0.3 });
200
+ const floor = new THREE.Mesh(floorGeo, floorMat);
201
+ floor.rotation.x = -Math.PI / 2;
202
+ floor.position.y = 0;
203
+ floor.receiveShadow = true;
204
+ scene.add(floor);
205
 
206
  // Constants
207
  const CENTER = new THREE.Vector3(0, 0.75, 0);
 
323
  const bulbMat = new THREE.MeshStandardMaterial({ color: 0xffff00, emissive: 0xffff00, emissiveIntensity: 1 });
324
  const bulb = new THREE.Mesh(new THREE.SphereGeometry(0.15, 16, 16), bulbMat);
325
  lightGroup.add(bulb);
326
+ const pointLight = new THREE.PointLight(0xffffff, 10, 0);
327
  pointLight.castShadow = true;
328
  pointLight.shadow.mapSize.width = 1024;
329
  pointLight.shadow.mapSize.height = 1024;
330
  pointLight.shadow.camera.near = 0.1;
331
+ pointLight.shadow.camera.far = 50;
332
  lightGroup.add(pointLight);
333
  scene.add(lightGroup);
334
 
 
427
  dragTarget.scale.setScalar(1.3);
428
  dragStartMouse.copy(mouse);
429
  canvas.style.cursor = 'grabbing';
 
430
  }
431
  });
432
 
 
504
  isDragging = false;
505
  dragTarget = null;
506
  canvas.style.cursor = 'default';
 
507
  };
508
 
509
  canvas.addEventListener('mouseup', onMouseUp);
 
525
  dragTarget.material.emissiveIntensity = 1.0;
526
  dragTarget.scale.setScalar(1.3);
527
  dragStartMouse.copy(mouse);
 
528
  }
529
  }, { passive: false });
530
 
 
572
  // Render loop
573
  function render() {
574
  requestAnimationFrame(render);
 
575
  renderer.render(scene, camera);
576
  }
577
  render();
 
637
  '''
638
  with gr.Blocks(css=css, theme=gr.themes.Soft()) as demo:
639
  gr.Markdown("""
640
+ # 🎬 Qwen Image Edit 2511 — 3D Lighting Control
641
 
642
+ Control lighting directions using the **3D viewport** or **sliders**.
643
  Using [dx8152/Qwen-Edit-2509-Multi-Angle-Lighting] for precise lighting control.
644
  """)
645
 
 
648
  with gr.Column(scale=1):
649
  image = gr.Image(label="Input Image", type="pil", height=300)
650
 
651
+ gr.Markdown("### 🎮 3D Lighting Control")
652
+ gr.Markdown("*Drag the colored handles: 🟢 Azimuth (Direction), 🩷 Elevation (Height)*")
653
 
654
  lighting_3d = LightingControl3D(
655
  value={"azimuth": 0, "elevation": 0},
 
776
  )
777
 
778
  if __name__ == "__main__":
779
+ head = '<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>'
780
  css = '.fillable{max-width: 1200px !important}'
781
  demo.launch(head=head, css=css)