Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -58,11 +58,11 @@ ELEVATION_MAP = {
|
|
| 58 |
60: "high-angle shot"
|
| 59 |
}
|
| 60 |
|
| 61 |
-
# Distance mappings (3 positions)
|
| 62 |
DISTANCE_MAP = {
|
| 63 |
0.6: "close-up",
|
| 64 |
1.0: "medium shot",
|
| 65 |
-
1.
|
| 66 |
}
|
| 67 |
|
| 68 |
|
|
@@ -195,7 +195,7 @@ class CameraControl3D(gr.HTML):
|
|
| 195 |
scene.background = new THREE.Color(0x1a1a1a);
|
| 196 |
|
| 197 |
const camera = new THREE.PerspectiveCamera(50, wrapper.clientWidth / wrapper.clientHeight, 0.1, 1000);
|
| 198 |
-
camera.position.set(
|
| 199 |
camera.lookAt(0, 0.75, 0);
|
| 200 |
|
| 201 |
const renderer = new THREE.WebGLRenderer({ antialias: true });
|
|
@@ -212,21 +212,21 @@ class CameraControl3D(gr.HTML):
|
|
| 212 |
// Grid
|
| 213 |
scene.add(new THREE.GridHelper(8, 16, 0x333333, 0x222222));
|
| 214 |
|
| 215 |
-
// Constants
|
| 216 |
const CENTER = new THREE.Vector3(0, 0.75, 0);
|
| 217 |
-
const BASE_DISTANCE = 2.
|
| 218 |
-
const AZIMUTH_RADIUS = 2.
|
| 219 |
-
const ELEVATION_RADIUS =
|
| 220 |
|
| 221 |
// State
|
| 222 |
let azimuthAngle = props.value?.azimuth || 0;
|
| 223 |
let elevationAngle = props.value?.elevation || 0;
|
| 224 |
let distanceFactor = props.value?.distance || 1.0;
|
| 225 |
|
| 226 |
-
// Mappings
|
| 227 |
const azimuthSteps = [0, 45, 90, 135, 180, 225, 270, 315];
|
| 228 |
const elevationSteps = [-30, 0, 30, 60];
|
| 229 |
-
const distanceSteps = [0.6, 1.0, 1.
|
| 230 |
|
| 231 |
const azimuthNames = {
|
| 232 |
0: 'front view', 45: 'front-right quarter view', 90: 'right side view',
|
|
@@ -234,7 +234,7 @@ class CameraControl3D(gr.HTML):
|
|
| 234 |
270: 'left side view', 315: 'front-left quarter view'
|
| 235 |
};
|
| 236 |
const elevationNames = { '-30': 'low-angle shot', '0': 'eye-level shot', '30': 'elevated shot', '60': 'high-angle shot' };
|
| 237 |
-
const distanceNames = { '0.6': 'close-up', '1': 'medium shot', '1.
|
| 238 |
|
| 239 |
function snapToNearest(value, steps) {
|
| 240 |
return steps.reduce((prev, curr) => Math.abs(curr - value) < Math.abs(prev - value) ? curr : prev);
|
|
@@ -481,7 +481,7 @@ class CameraControl3D(gr.HTML):
|
|
| 481 |
}
|
| 482 |
} else if (dragTarget.userData.type === 'distance') {
|
| 483 |
const deltaY = mouse.y - dragStartMouse.y;
|
| 484 |
-
distanceFactor = THREE.MathUtils.clamp(dragStartDistance - deltaY * 1.5, 0.6, 1.
|
| 485 |
}
|
| 486 |
updatePositions();
|
| 487 |
} else {
|
|
@@ -571,13 +571,26 @@ class CameraControl3D(gr.HTML):
|
|
| 571 |
|
| 572 |
wrapper._updateTexture = updateTextureFromUrl;
|
| 573 |
|
| 574 |
-
// Watch for imageUrl
|
| 575 |
let lastImageUrl = props.imageUrl;
|
|
|
|
| 576 |
setInterval(() => {
|
|
|
|
| 577 |
if (props.imageUrl !== lastImageUrl) {
|
| 578 |
lastImageUrl = props.imageUrl;
|
| 579 |
updateTextureFromUrl(props.imageUrl);
|
| 580 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 581 |
}, 100);
|
| 582 |
};
|
| 583 |
|
|
@@ -646,10 +659,10 @@ with gr.Blocks(css=css, theme=gr.themes.Soft()) as demo:
|
|
| 646 |
distance_slider = gr.Slider(
|
| 647 |
label="Distance",
|
| 648 |
minimum=0.6,
|
| 649 |
-
maximum=1.
|
| 650 |
-
step=0.
|
| 651 |
value=1.0,
|
| 652 |
-
info="0.6=close-up, 1.0=medium, 1.
|
| 653 |
)
|
| 654 |
|
| 655 |
prompt_preview = gr.Textbox(
|
|
|
|
| 58 |
60: "high-angle shot"
|
| 59 |
}
|
| 60 |
|
| 61 |
+
# Distance mappings (3 positions) - reduced wide shot
|
| 62 |
DISTANCE_MAP = {
|
| 63 |
0.6: "close-up",
|
| 64 |
1.0: "medium shot",
|
| 65 |
+
1.4: "wide shot"
|
| 66 |
}
|
| 67 |
|
| 68 |
|
|
|
|
| 195 |
scene.background = new THREE.Color(0x1a1a1a);
|
| 196 |
|
| 197 |
const camera = new THREE.PerspectiveCamera(50, wrapper.clientWidth / wrapper.clientHeight, 0.1, 1000);
|
| 198 |
+
camera.position.set(4.5, 3, 4.5);
|
| 199 |
camera.lookAt(0, 0.75, 0);
|
| 200 |
|
| 201 |
const renderer = new THREE.WebGLRenderer({ antialias: true });
|
|
|
|
| 212 |
// Grid
|
| 213 |
scene.add(new THREE.GridHelper(8, 16, 0x333333, 0x222222));
|
| 214 |
|
| 215 |
+
// Constants - reduced distances for tighter framing
|
| 216 |
const CENTER = new THREE.Vector3(0, 0.75, 0);
|
| 217 |
+
const BASE_DISTANCE = 2.0;
|
| 218 |
+
const AZIMUTH_RADIUS = 2.4;
|
| 219 |
+
const ELEVATION_RADIUS = 1.8;
|
| 220 |
|
| 221 |
// State
|
| 222 |
let azimuthAngle = props.value?.azimuth || 0;
|
| 223 |
let elevationAngle = props.value?.elevation || 0;
|
| 224 |
let distanceFactor = props.value?.distance || 1.0;
|
| 225 |
|
| 226 |
+
// Mappings - reduced wide shot multiplier
|
| 227 |
const azimuthSteps = [0, 45, 90, 135, 180, 225, 270, 315];
|
| 228 |
const elevationSteps = [-30, 0, 30, 60];
|
| 229 |
+
const distanceSteps = [0.6, 1.0, 1.4];
|
| 230 |
|
| 231 |
const azimuthNames = {
|
| 232 |
0: 'front view', 45: 'front-right quarter view', 90: 'right side view',
|
|
|
|
| 234 |
270: 'left side view', 315: 'front-left quarter view'
|
| 235 |
};
|
| 236 |
const elevationNames = { '-30': 'low-angle shot', '0': 'eye-level shot', '30': 'elevated shot', '60': 'high-angle shot' };
|
| 237 |
+
const distanceNames = { '0.6': 'close-up', '1': 'medium shot', '1.4': 'wide shot' };
|
| 238 |
|
| 239 |
function snapToNearest(value, steps) {
|
| 240 |
return steps.reduce((prev, curr) => Math.abs(curr - value) < Math.abs(prev - value) ? curr : prev);
|
|
|
|
| 481 |
}
|
| 482 |
} else if (dragTarget.userData.type === 'distance') {
|
| 483 |
const deltaY = mouse.y - dragStartMouse.y;
|
| 484 |
+
distanceFactor = THREE.MathUtils.clamp(dragStartDistance - deltaY * 1.5, 0.6, 1.4);
|
| 485 |
}
|
| 486 |
updatePositions();
|
| 487 |
} else {
|
|
|
|
| 571 |
|
| 572 |
wrapper._updateTexture = updateTextureFromUrl;
|
| 573 |
|
| 574 |
+
// Watch for prop changes (imageUrl and value)
|
| 575 |
let lastImageUrl = props.imageUrl;
|
| 576 |
+
let lastValue = JSON.stringify(props.value);
|
| 577 |
setInterval(() => {
|
| 578 |
+
// Check imageUrl changes
|
| 579 |
if (props.imageUrl !== lastImageUrl) {
|
| 580 |
lastImageUrl = props.imageUrl;
|
| 581 |
updateTextureFromUrl(props.imageUrl);
|
| 582 |
}
|
| 583 |
+
// Check value changes (from sliders)
|
| 584 |
+
const currentValue = JSON.stringify(props.value);
|
| 585 |
+
if (currentValue !== lastValue) {
|
| 586 |
+
lastValue = currentValue;
|
| 587 |
+
if (props.value && typeof props.value === 'object') {
|
| 588 |
+
azimuthAngle = props.value.azimuth ?? azimuthAngle;
|
| 589 |
+
elevationAngle = props.value.elevation ?? elevationAngle;
|
| 590 |
+
distanceFactor = props.value.distance ?? distanceFactor;
|
| 591 |
+
updatePositions();
|
| 592 |
+
}
|
| 593 |
+
}
|
| 594 |
}, 100);
|
| 595 |
};
|
| 596 |
|
|
|
|
| 659 |
distance_slider = gr.Slider(
|
| 660 |
label="Distance",
|
| 661 |
minimum=0.6,
|
| 662 |
+
maximum=1.4,
|
| 663 |
+
step=0.4,
|
| 664 |
value=1.0,
|
| 665 |
+
info="0.6=close-up, 1.0=medium, 1.4=wide"
|
| 666 |
)
|
| 667 |
|
| 668 |
prompt_preview = gr.Textbox(
|