Spaces:
Running
Running
Commit
·
0dc587b
1
Parent(s):
2f81b19
Update index.js
Browse files
index.js
CHANGED
|
@@ -1,79 +1,57 @@
|
|
| 1 |
-
|
| 2 |
|
| 3 |
-
// Since we will download the model from the Hugging Face Hub, we can skip the local model check
|
| 4 |
-
env.allowLocalModels = false;
|
| 5 |
|
| 6 |
-
|
| 7 |
-
const status = document.getElementById('status');
|
| 8 |
-
const fileUpload = document.getElementById('upload');
|
| 9 |
-
const imageContainer = document.getElementById('container');
|
| 10 |
-
const example = document.getElementById('example');
|
| 11 |
|
| 12 |
-
const EXAMPLE_URL = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/city-streets.jpg';
|
| 13 |
|
| 14 |
-
// Create a new object detection pipeline
|
| 15 |
-
status.textContent = 'Loading model...';
|
| 16 |
-
const detector = await pipeline('object-detection', 'Xenova/detr-resnet-50');
|
| 17 |
-
status.textContent = 'Ready';
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
fileUpload.addEventListener('change', function (e) {
|
| 25 |
-
const file = e.target.files[0];
|
| 26 |
-
if (!file) {
|
| 27 |
-
return;
|
| 28 |
-
}
|
| 29 |
|
| 30 |
-
const reader = new FileReader();
|
| 31 |
|
| 32 |
-
// Set up a callback when the file is loaded
|
| 33 |
-
reader.onload = e2 => detect(e2.target.result);
|
| 34 |
|
| 35 |
-
reader.readAsDataURL(file);
|
| 36 |
-
});
|
| 37 |
|
|
|
|
| 38 |
|
| 39 |
-
// Detect objects in the image
|
| 40 |
-
async function detect(img) {
|
| 41 |
-
imageContainer.innerHTML = '';
|
| 42 |
-
imageContainer.style.backgroundImage = `url(${img})`;
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
});
|
| 49 |
-
status.textContent = '';
|
| 50 |
-
output.forEach(renderBox);
|
| 51 |
-
}
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
|
| 2 |
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
<div id="cube-container"></div>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
|
|
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
#cube-container {
|
| 9 |
+
width: 100%;
|
| 10 |
+
height: 400px;
|
| 11 |
+
position: relative;
|
| 12 |
+
margin-top: 20px;
|
| 13 |
+
}
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
|
|
|
| 16 |
|
|
|
|
|
|
|
| 17 |
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
Java
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
// scripts.js
|
| 23 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 24 |
+
// Set up the scene, camera, and renderer as global variables.
|
| 25 |
+
var scene, camera, renderer, cube;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
+
init();
|
| 28 |
+
|
| 29 |
+
function init() {
|
| 30 |
+
// Add the scene.
|
| 31 |
+
scene = new THREE.Scene();
|
| 32 |
+
scene.background = new THREE.Color(0xf4f4f4);
|
| 33 |
+
|
| 34 |
+
// Add the camera.
|
| 35 |
+
camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
|
| 36 |
+
camera.position.z = 5;
|
| 37 |
+
|
| 38 |
+
// Add the renderer.
|
| 39 |
+
renderer = new THREE.WebGLRenderer({ antialias: true });
|
| 40 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 41 |
+
document.getElementById('cube-container').appendChild(renderer.domElement);
|
| 42 |
+
|
| 43 |
+
// Add the cube.
|
| 44 |
+
var geometry = new THREE.BoxGeometry(2, 2, 2);
|
| 45 |
+
var material = new THREE.MeshBasicMaterial({ color: 0x007bff, wireframe: false });
|
| 46 |
+
cube = new THREE.Mesh(geometry, material);
|
| 47 |
+
scene.add(cube);
|
| 48 |
+
|
| 49 |
+
// Render the scene/camera combination.
|
| 50 |
+
render();
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
function render() {
|
| 54 |
+
requestAnimationFrame(render);
|
| 55 |
+
|
| 56 |
+
// Rotate the cube.
|
| 57 |
+
cube.rotation.x +=
|