CIHIRIS commited on
Commit
2c33eda
·
verified ·
1 Parent(s): 77b618c

Add 3 files

Browse files
Files changed (3) hide show
  1. README.md +7 -5
  2. index.html +766 -19
  3. prompts.txt +3 -0
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: 2d To 3d Model Generator
3
- emoji: 🚀
4
- colorFrom: indigo
5
- colorTo: purple
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: 2d-to-3d-model-generator
3
+ emoji: 🐳
4
+ colorFrom: gray
5
+ colorTo: green
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite
10
  ---
11
 
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
index.html CHANGED
@@ -1,19 +1,766 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Trellis3D - 2D to 3D Conversion</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <script src="https://cdn.jsdelivr.net/npm/[email protected]/build/three.min.js"></script>
9
+ <script src="https://cdn.jsdelivr.net/npm/[email protected]/examples/js/controls/OrbitControls.js"></script>
10
+ <script src="https://cdn.jsdelivr.net/npm/[email protected]/examples/js/loaders/GLTFLoader.js"></script>
11
+ <script src="https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]/dist/tf.min.js"></script>
12
+ <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/rembg.min.js"></script>
13
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
14
+ <style>
15
+ #preview-container {
16
+ width: 100%;
17
+ height: 400px;
18
+ background-color: #f0f0f0;
19
+ border-radius: 0.5rem;
20
+ overflow: hidden;
21
+ position: relative;
22
+ }
23
+
24
+ .dark #preview-container {
25
+ background-color: #2d3748;
26
+ }
27
+
28
+ .loading-overlay {
29
+ position: absolute;
30
+ top: 0;
31
+ left: 0;
32
+ width: 100%;
33
+ height: 100%;
34
+ background-color: rgba(0,0,0,0.7);
35
+ display: flex;
36
+ flex-direction: column;
37
+ justify-content: center;
38
+ align-items: center;
39
+ color: white;
40
+ z-index: 10;
41
+ }
42
+
43
+ .progress-bar {
44
+ width: 80%;
45
+ height: 8px;
46
+ background-color: #4a5568;
47
+ border-radius: 4px;
48
+ margin-top: 1rem;
49
+ overflow: hidden;
50
+ }
51
+
52
+ .progress-fill {
53
+ height: 100%;
54
+ background-color: #4299e1;
55
+ width: 0%;
56
+ transition: width 0.3s ease;
57
+ }
58
+
59
+ .dropzone {
60
+ border: 2px dashed #cbd5e0;
61
+ border-radius: 0.5rem;
62
+ padding: 2rem;
63
+ text-align: center;
64
+ cursor: pointer;
65
+ transition: all 0.3s ease;
66
+ }
67
+
68
+ .dark .dropzone {
69
+ border-color: #4a5568;
70
+ }
71
+
72
+ .dropzone:hover {
73
+ border-color: #4299e1;
74
+ background-color: rgba(66, 153, 225, 0.05);
75
+ }
76
+
77
+ .dark .dropzone:hover {
78
+ background-color: rgba(66, 153, 225, 0.1);
79
+ }
80
+
81
+ .dropzone.active {
82
+ border-color: #4299e1;
83
+ background-color: rgba(66, 153, 225, 0.1);
84
+ }
85
+
86
+ .dark .dropzone.active {
87
+ background-color: rgba(66, 153, 225, 0.2);
88
+ }
89
+
90
+ .model-view-toggle {
91
+ display: flex;
92
+ justify-content: center;
93
+ margin-top: 1rem;
94
+ }
95
+
96
+ .view-btn {
97
+ padding: 0.5rem 1rem;
98
+ background-color: #e2e8f0;
99
+ border: none;
100
+ cursor: pointer;
101
+ transition: all 0.2s ease;
102
+ }
103
+
104
+ .dark .view-btn {
105
+ background-color: #4a5568;
106
+ color: white;
107
+ }
108
+
109
+ .view-btn:first-child {
110
+ border-radius: 0.25rem 0 0 0.25rem;
111
+ }
112
+
113
+ .view-btn:last-child {
114
+ border-radius: 0 0.25rem 0.25rem 0;
115
+ }
116
+
117
+ .view-btn.active {
118
+ background-color: #4299e1;
119
+ color: white;
120
+ }
121
+
122
+ .dark .view-btn.active {
123
+ background-color: #3182ce;
124
+ }
125
+
126
+ #image-preview {
127
+ max-width: 100%;
128
+ max-height: 200px;
129
+ border-radius: 0.25rem;
130
+ margin-bottom: 1rem;
131
+ }
132
+
133
+ #depth-map {
134
+ position: absolute;
135
+ top: 0;
136
+ left: 0;
137
+ width: 100%;
138
+ height: 100%;
139
+ object-fit: contain;
140
+ display: none;
141
+ }
142
+ </style>
143
+ </head>
144
+ <body class="bg-gray-100 dark:bg-gray-900 text-gray-900 dark:text-gray-100 transition-colors duration-200">
145
+ <div class="min-h-screen">
146
+ <header class="bg-white dark:bg-gray-800 shadow-md">
147
+ <div class="container mx-auto px-4 py-6 flex justify-between items-center">
148
+ <div class="flex items-center space-x-2">
149
+ <div class="w-8 h-8 bg-blue-500 rounded-md flex items-center justify-center">
150
+ <i class="fas fa-cube text-white"></i>
151
+ </div>
152
+ <h1 class="text-xl font-bold">Trellis3D</h1>
153
+ </div>
154
+ <div class="flex items-center space-x-4">
155
+ <button id="theme-toggle" class="p-2 rounded-full hover:bg-gray-200 dark:hover:bg-gray-700">
156
+ <i class="fas fa-moon dark:hidden"></i>
157
+ <i class="fas fa-sun hidden dark:block"></i>
158
+ </button>
159
+ <button class="px-4 py-2 bg-blue-500 hover:bg-blue-600 text-white rounded-md transition-colors">
160
+ <i class="fas fa-user mr-2"></i>
161
+ Sign In
162
+ </button>
163
+ </div>
164
+ </div>
165
+ </header>
166
+
167
+ <main class="container mx-auto px-4 py-8">
168
+ <div class="max-w-4xl mx-auto">
169
+ <div class="text-center mb-8">
170
+ <h2 class="text-3xl font-bold mb-2">2D to 3D Conversion</h2>
171
+ <p class="text-gray-600 dark:text-gray-400">Transform your 2D images into stunning 3D models with our AI-powered technology</p>
172
+ </div>
173
+
174
+ <div class="bg-white dark:bg-gray-800 rounded-xl shadow-lg p-6 mb-8">
175
+ <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
176
+ <div>
177
+ <h3 class="text-lg font-semibold mb-4">Upload Image</h3>
178
+
179
+ <div id="dropzone" class="dropzone">
180
+ <div class="flex flex-col items-center justify-center">
181
+ <i class="fas fa-cloud-upload-alt text-4xl text-gray-400 mb-4"></i>
182
+ <p class="mb-2">Drag & drop your image here</p>
183
+ <p class="text-sm text-gray-500 dark:text-gray-400 mb-4">or</p>
184
+ <label for="file-upload" class="px-4 py-2 bg-blue-500 hover:bg-blue-600 text-white rounded-md cursor-pointer transition-colors">
185
+ <i class="fas fa-folder-open mr-2"></i>
186
+ Browse Files
187
+ </label>
188
+ <input id="file-upload" type="file" accept="image/*" class="hidden">
189
+ </div>
190
+ </div>
191
+
192
+ <div class="mt-4">
193
+ <div class="flex items-center mb-2">
194
+ <input id="remove-bg" type="checkbox" class="rounded text-blue-500 focus:ring-blue-500" checked>
195
+ <label for="remove-bg" class="ml-2">Remove background</label>
196
+ </div>
197
+
198
+ <div class="mb-4">
199
+ <label class="block mb-2">Model Quality</label>
200
+ <div class="flex space-x-2">
201
+ <button class="quality-btn px-3 py-1 rounded-md border border-gray-300 dark:border-gray-600" data-quality="low">Low</button>
202
+ <button class="quality-btn px-3 py-1 rounded-md border border-gray-300 dark:border-gray-600 active bg-blue-500 text-white border-blue-500" data-quality="medium">Medium</button>
203
+ <button class="quality-btn px-3 py-1 rounded-md border border-gray-300 dark:border-gray-600" data-quality="high">High</button>
204
+ </div>
205
+ </div>
206
+
207
+ <button id="convert-btn" class="w-full py-3 bg-blue-500 hover:bg-blue-600 text-white rounded-md font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed" disabled>
208
+ <i class="fas fa-magic mr-2"></i>
209
+ Convert to 3D
210
+ </button>
211
+ </div>
212
+ </div>
213
+
214
+ <div>
215
+ <h3 class="text-lg font-semibold mb-4">3D Preview</h3>
216
+ <div id="preview-container">
217
+ <div id="loading-overlay" class="loading-overlay hidden">
218
+ <i class="fas fa-spinner fa-spin text-3xl mb-2"></i>
219
+ <p id="loading-text">Processing your image...</p>
220
+ <div class="progress-bar">
221
+ <div id="progress-fill" class="progress-fill"></div>
222
+ </div>
223
+ </div>
224
+ <div id="preview-placeholder" class="flex flex-col items-center justify-center h-full">
225
+ <i class="fas fa-cube text-4xl text-gray-400 mb-4"></i>
226
+ <p class="text-gray-500 dark:text-gray-400">Your 3D model will appear here</p>
227
+ </div>
228
+ <canvas id="preview-canvas" class="hidden"></canvas>
229
+ <img id="depth-map" alt="Depth map preview">
230
+ </div>
231
+
232
+ <div id="view-controls" class="hidden">
233
+ <div class="model-view-toggle">
234
+ <button class="view-btn active" data-view="textured">
235
+ <i class="fas fa-paint-brush mr-2"></i>
236
+ Textured
237
+ </button>
238
+ <button class="view-btn" data-view="white">
239
+ <i class="fas fa-square mr-2"></i>
240
+ White
241
+ </button>
242
+ <button class="view-btn" data-view="wireframe">
243
+ <i class="fas fa-border-none mr-2"></i>
244
+ Wireframe
245
+ </button>
246
+ </div>
247
+
248
+ <div class="flex justify-between mt-4">
249
+ <button id="download-btn" class="px-4 py-2 bg-green-500 hover:bg-green-600 text-white rounded-md">
250
+ <i class="fas fa-download mr-2"></i>
251
+ Download
252
+ </button>
253
+ <button id="reset-btn" class="px-4 py-2 bg-gray-500 hover:bg-gray-600 text-white rounded-md">
254
+ <i class="fas fa-redo mr-2"></i>
255
+ Reset
256
+ </button>
257
+ </div>
258
+ </div>
259
+ </div>
260
+ </div>
261
+ </div>
262
+
263
+ <div class="bg-white dark:bg-gray-800 rounded-xl shadow-lg p-6">
264
+ <h3 class="text-lg font-semibold mb-4">How It Works</h3>
265
+ <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
266
+ <div class="bg-gray-100 dark:bg-gray-700 rounded-lg p-4">
267
+ <div class="w-12 h-12 bg-blue-500 rounded-full flex items-center justify-center mb-3 mx-auto">
268
+ <i class="fas fa-upload text-white"></i>
269
+ </div>
270
+ <h4 class="font-medium text-center mb-2">1. Upload Image</h4>
271
+ <p class="text-sm text-gray-600 dark:text-gray-300 text-center">Upload any 2D image you want to convert to 3D</p>
272
+ </div>
273
+ <div class="bg-gray-100 dark:bg-gray-700 rounded-lg p-4">
274
+ <div class="w-12 h-12 bg-blue-500 rounded-full flex items-center justify-center mb-3 mx-auto">
275
+ <i class="fas fa-robot text-white"></i>
276
+ </div>
277
+ <h4 class="font-medium text-center mb-2">2. AI Processing</h4>
278
+ <p class="text-sm text-gray-600 dark:text-gray-300 text-center">Our AI analyzes the image and creates a depth map</p>
279
+ </div>
280
+ <div class="bg-gray-100 dark:bg-gray-700 rounded-lg p-4">
281
+ <div class="w-12 h-12 bg-blue-500 rounded-full flex items-center justify-center mb-3 mx-auto">
282
+ <i class="fas fa-cube text-white"></i>
283
+ </div>
284
+ <h4 class="font-medium text-center mb-2">3. 3D Model</h4>
285
+ <p class="text-sm text-gray-600 dark:text-gray-300 text-center">Download your 3D model in various formats</p>
286
+ </div>
287
+ </div>
288
+ </div>
289
+ </div>
290
+ </main>
291
+
292
+ <footer class="bg-white dark:bg-gray-800 border-t border-gray-200 dark:border-gray-700 mt-12">
293
+ <div class="container mx-auto px-4 py-6">
294
+ <div class="flex flex-col md:flex-row justify-between items-center">
295
+ <div class="flex items-center space-x-2 mb-4 md:mb-0">
296
+ <div class="w-6 h-6 bg-blue-500 rounded-md flex items-center justify-center">
297
+ <i class="fas fa-cube text-white text-xs"></i>
298
+ </div>
299
+ <span class="font-medium">Trellis3D</span>
300
+ </div>
301
+ <div class="flex space-x-6">
302
+ <a href="#" class="text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white">Terms</a>
303
+ <a href="#" class="text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white">Privacy</a>
304
+ <a href="#" class="text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white">Help</a>
305
+ </div>
306
+ </div>
307
+ <div class="mt-4 text-center md:text-left text-sm text-gray-500 dark:text-gray-400">
308
+ © 2023 Trellis3D. All rights reserved.
309
+ </div>
310
+ </div>
311
+ </footer>
312
+ </div>
313
+
314
+ <script>
315
+ // Theme toggle
316
+ const themeToggle = document.getElementById('theme-toggle');
317
+ const html = document.documentElement;
318
+
319
+ if (localStorage.getItem('theme') === 'dark' || (!localStorage.getItem('theme') && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
320
+ html.classList.add('dark');
321
+ }
322
+
323
+ themeToggle.addEventListener('click', () => {
324
+ html.classList.toggle('dark');
325
+ localStorage.setItem('theme', html.classList.contains('dark') ? 'dark' : 'light');
326
+ });
327
+
328
+ // File upload and dropzone
329
+ const dropzone = document.getElementById('dropzone');
330
+ const fileInput = document.getElementById('file-upload');
331
+ const convertBtn = document.getElementById('convert-btn');
332
+ let selectedFile = null;
333
+ let processedImage = null;
334
+
335
+ dropzone.addEventListener('click', () => fileInput.click());
336
+
337
+ fileInput.addEventListener('change', (e) => {
338
+ if (e.target.files.length) {
339
+ handleFileSelection(e.target.files[0]);
340
+ }
341
+ });
342
+
343
+ ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
344
+ dropzone.addEventListener(eventName, preventDefaults, false);
345
+ });
346
+
347
+ function preventDefaults(e) {
348
+ e.preventDefault();
349
+ e.stopPropagation();
350
+ }
351
+
352
+ ['dragenter', 'dragover'].forEach(eventName => {
353
+ dropzone.addEventListener(eventName, highlight, false);
354
+ });
355
+
356
+ ['dragleave', 'drop'].forEach(eventName => {
357
+ dropzone.addEventListener(eventName, unhighlight, false);
358
+ });
359
+
360
+ function highlight() {
361
+ dropzone.classList.add('active');
362
+ }
363
+
364
+ function unhighlight() {
365
+ dropzone.classList.remove('active');
366
+ }
367
+
368
+ dropzone.addEventListener('drop', (e) => {
369
+ const dt = e.dataTransfer;
370
+ const file = dt.files[0];
371
+ if (file && file.type.match('image.*')) {
372
+ handleFileSelection(file);
373
+ }
374
+ });
375
+
376
+ function handleFileSelection(file) {
377
+ selectedFile = file;
378
+ convertBtn.disabled = false;
379
+
380
+ // Show preview of selected image
381
+ const reader = new FileReader();
382
+ reader.onload = (e) => {
383
+ dropzone.innerHTML = `
384
+ <div class="flex flex-col items-center">
385
+ <img src="${e.target.result}" id="image-preview" class="rounded-md mb-2" alt="Preview">
386
+ <p class="text-sm text-gray-600 dark:text-gray-400">${file.name}</p>
387
+ </div>
388
+ `;
389
+ };
390
+ reader.readAsDataURL(file);
391
+ }
392
+
393
+ // Model quality selection
394
+ const qualityBtns = document.querySelectorAll('.quality-btn');
395
+ let selectedQuality = 'medium';
396
+
397
+ qualityBtns.forEach(btn => {
398
+ btn.addEventListener('click', () => {
399
+ qualityBtns.forEach(b => b.classList.remove('active', 'bg-blue-500', 'text-white', 'border-blue-500'));
400
+ btn.classList.add('active', 'bg-blue-500', 'text-white', 'border-blue-500');
401
+ selectedQuality = btn.dataset.quality;
402
+ });
403
+ });
404
+
405
+ // 3D Preview setup
406
+ const previewContainer = document.getElementById('preview-container');
407
+ const previewCanvas = document.getElementById('preview-canvas');
408
+ const previewPlaceholder = document.getElementById('preview-placeholder');
409
+ const loadingOverlay = document.getElementById('loading-overlay');
410
+ const loadingText = document.getElementById('loading-text');
411
+ const progressFill = document.getElementById('progress-fill');
412
+ const viewControls = document.getElementById('view-controls');
413
+ const depthMap = document.getElementById('depth-map');
414
+
415
+ let scene, camera, renderer, controls, model;
416
+
417
+ function initThreeJS() {
418
+ const width = previewContainer.clientWidth;
419
+ const height = previewContainer.clientHeight;
420
+
421
+ scene = new THREE.Scene();
422
+ scene.background = new THREE.Color(0xf0f0f0);
423
+
424
+ camera = new THREE.PerspectiveCamera(75, width / height, 0.1, 1000);
425
+ camera.position.z = 5;
426
+
427
+ renderer = new THREE.WebGLRenderer({
428
+ canvas: previewCanvas,
429
+ antialias: true,
430
+ alpha: true
431
+ });
432
+ renderer.setSize(width, height);
433
+ renderer.setPixelRatio(window.devicePixelRatio);
434
+
435
+ controls = new THREE.OrbitControls(camera, renderer.domElement);
436
+ controls.enableDamping = true;
437
+ controls.dampingFactor = 0.25;
438
+
439
+ // Add lights
440
+ const ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
441
+ scene.add(ambientLight);
442
+
443
+ const directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
444
+ directionalLight.position.set(1, 1, 1);
445
+ scene.add(directionalLight);
446
+
447
+ // Add a simple grid helper
448
+ const gridHelper = new THREE.GridHelper(10, 10);
449
+ scene.add(gridHelper);
450
+
451
+ animate();
452
+ }
453
+
454
+ function animate() {
455
+ requestAnimationFrame(animate);
456
+ controls.update();
457
+ renderer.render(scene, camera);
458
+ }
459
+
460
+ window.addEventListener('resize', () => {
461
+ const width = previewContainer.clientWidth;
462
+ const height = previewContainer.clientHeight;
463
+
464
+ camera.aspect = width / height;
465
+ camera.updateProjectionMatrix();
466
+ renderer.setSize(width, height);
467
+ });
468
+
469
+ // View mode toggles
470
+ const viewBtns = document.querySelectorAll('.view-btn');
471
+
472
+ viewBtns.forEach(btn => {
473
+ btn.addEventListener('click', () => {
474
+ viewBtns.forEach(b => b.classList.remove('active'));
475
+ btn.classList.add('active');
476
+
477
+ if (model) {
478
+ const viewMode = btn.dataset.view;
479
+
480
+ if (viewMode === 'textured') {
481
+ model.traverse(child => {
482
+ if (child.isMesh) {
483
+ child.material = child.userData.originalMaterial;
484
+ child.material.wireframe = false;
485
+ }
486
+ });
487
+ } else if (viewMode === 'white') {
488
+ const whiteMaterial = new THREE.MeshStandardMaterial({ color: 0xffffff });
489
+ model.traverse(child => {
490
+ if (child.isMesh) {
491
+ child.material = whiteMaterial;
492
+ child.material.wireframe = false;
493
+ }
494
+ });
495
+ } else if (viewMode === 'wireframe') {
496
+ model.traverse(child => {
497
+ if (child.isMesh) {
498
+ child.material.wireframe = true;
499
+ }
500
+ });
501
+ }
502
+ }
503
+ });
504
+ });
505
+
506
+ // Convert button handler
507
+ convertBtn.addEventListener('click', async () => {
508
+ if (!selectedFile) return;
509
+
510
+ // Show loading state
511
+ loadingOverlay.classList.remove('hidden');
512
+ previewPlaceholder.classList.add('hidden');
513
+ previewCanvas.classList.remove('hidden');
514
+
515
+ // Initialize Three.js if not already done
516
+ if (!renderer) {
517
+ initThreeJS();
518
+ }
519
+
520
+ // Process the image
521
+ await processImage();
522
+ });
523
+
524
+ async function processImage() {
525
+ let progress = 0;
526
+ const interval = setInterval(() => {
527
+ progress += Math.random() * 10;
528
+ if (progress > 100) progress = 100;
529
+
530
+ progressFill.style.width = `${progress}%`;
531
+ loadingText.textContent = getLoadingMessage(progress);
532
+
533
+ if (progress === 100) {
534
+ clearInterval(interval);
535
+ setTimeout(showResult, 500);
536
+ }
537
+ }, 300);
538
+
539
+ // Load the image
540
+ const image = await loadImage(selectedFile);
541
+
542
+ // Remove background if selected
543
+ const removeBg = document.getElementById('remove-bg').checked;
544
+ if (removeBg) {
545
+ try {
546
+ // In a real app, you would use REMBG here
547
+ // For this demo, we'll simulate background removal with a simple effect
548
+ processedImage = await simulateRemoveBackground(image);
549
+ } catch (error) {
550
+ console.error("Background removal failed:", error);
551
+ processedImage = image; // Fallback to original image
552
+ }
553
+ } else {
554
+ processedImage = image;
555
+ }
556
+
557
+ // Generate depth map (simulated)
558
+ const depthMapUrl = await generateDepthMap(processedImage);
559
+ depthMap.src = depthMapUrl;
560
+ }
561
+
562
+ function loadImage(file) {
563
+ return new Promise((resolve) => {
564
+ const reader = new FileReader();
565
+ reader.onload = (e) => {
566
+ const img = new Image();
567
+ img.onload = () => resolve(img);
568
+ img.src = e.target.result;
569
+ };
570
+ reader.readAsDataURL(file);
571
+ });
572
+ }
573
+
574
+ function simulateRemoveBackground(image) {
575
+ return new Promise((resolve) => {
576
+ // In a real app, you would use REMBG here
577
+ // This is just a simulation with a canvas effect
578
+ const canvas = document.createElement('canvas');
579
+ canvas.width = image.width;
580
+ canvas.height = image.height;
581
+ const ctx = canvas.getContext('2d');
582
+ ctx.drawImage(image, 0, 0);
583
+
584
+ // Simple background removal simulation
585
+ const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
586
+ const data = imageData.data;
587
+
588
+ // Make a simple assumption that edges are background
589
+ for (let i = 0; i < data.length; i += 4) {
590
+ const x = (i / 4) % canvas.width;
591
+ const y = Math.floor((i / 4) / canvas.width);
592
+
593
+ // If pixel is near the edge, make it transparent
594
+ if (x < 10 || x > canvas.width - 10 || y < 10 || y > canvas.height - 10) {
595
+ data[i + 3] = 0; // Set alpha to 0
596
+ }
597
+ }
598
+
599
+ ctx.putImageData(imageData, 0, 0);
600
+
601
+ const result = new Image();
602
+ result.onload = () => resolve(result);
603
+ result.src = canvas.toDataURL();
604
+ });
605
+ }
606
+
607
+ function generateDepthMap(image) {
608
+ return new Promise((resolve) => {
609
+ // In a real app, you would use a proper depth estimation model
610
+ // This is just a simulation with a canvas effect
611
+ const canvas = document.createElement('canvas');
612
+ canvas.width = image.width;
613
+ canvas.height = image.height;
614
+ const ctx = canvas.getContext('2d');
615
+ ctx.drawImage(image, 0, 0);
616
+
617
+ // Create a simple depth map simulation
618
+ const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
619
+ const data = imageData.data;
620
+ const depthData = new Uint8ClampedArray(canvas.width * canvas.height * 4);
621
+
622
+ for (let i = 0; i < data.length; i += 4) {
623
+ const x = (i / 4) % canvas.width;
624
+ const y = Math.floor((i / 4) / canvas.width);
625
+
626
+ // Simple depth simulation based on brightness and position
627
+ const brightness = (data[i] + data[i + 1] + data[i + 2]) / 3;
628
+ const depth = (brightness / 255) * 0.5 + (1 - (y / canvas.height)) * 0.5;
629
+ const depthValue = Math.floor(depth * 255);
630
+
631
+ depthData[i] = depthValue;
632
+ depthData[i + 1] = depthValue;
633
+ depthData[i + 2] = depthValue;
634
+ depthData[i + 3] = data[i + 3]; // Preserve alpha
635
+ }
636
+
637
+ const depthImageData = new ImageData(new Uint8ClampedArray(depthData), canvas.width, canvas.height);
638
+ ctx.putImageData(depthImageData, 0, 0);
639
+
640
+ resolve(canvas.toDataURL());
641
+ });
642
+ }
643
+
644
+ function getLoadingMessage(progress) {
645
+ if (progress < 30) return "Analyzing image...";
646
+ if (progress < 60) return "Generating depth map...";
647
+ if (progress < 90) return "Creating 3D model...";
648
+ return "Finalizing...";
649
+ }
650
+
651
+ function showResult() {
652
+ loadingOverlay.classList.add('hidden');
653
+ viewControls.classList.remove('hidden');
654
+
655
+ // Clear previous model if exists
656
+ if (model) {
657
+ scene.remove(model);
658
+ }
659
+
660
+ // Create a 3D model from the processed image
661
+ create3DModelFromImage(processedImage);
662
+ }
663
+
664
+ function create3DModelFromImage(image) {
665
+ const textureLoader = new THREE.TextureLoader();
666
+ textureLoader.load(image.src, (texture) => {
667
+ // Create a plane geometry with the image dimensions
668
+ const aspectRatio = image.width / image.height;
669
+ const width = 3;
670
+ const height = width / aspectRatio;
671
+
672
+ const geometry = new THREE.PlaneGeometry(width, height, 64, 64);
673
+
674
+ // Apply the depth map to create a 3D effect
675
+ applyDepthMapToGeometry(geometry, image);
676
+
677
+ // Create material with the image texture
678
+ const material = new THREE.MeshStandardMaterial({
679
+ map: texture,
680
+ side: THREE.DoubleSide,
681
+ transparent: true
682
+ });
683
+
684
+ model = new THREE.Mesh(geometry, material);
685
+
686
+ // Store original material for textured view
687
+ model.traverse(child => {
688
+ if (child.isMesh) {
689
+ child.userData.originalMaterial = child.material;
690
+ }
691
+ });
692
+
693
+ scene.add(model);
694
+
695
+ // Add some rotation animation
696
+ function animateRotation() {
697
+ requestAnimationFrame(animateRotation);
698
+ model.rotation.y += 0.005;
699
+ }
700
+ animateRotation();
701
+ });
702
+ }
703
+
704
+ function applyDepthMapToGeometry(geometry, image) {
705
+ // In a real app, you would use the actual depth map
706
+ // This is a simplified version that creates some depth variation
707
+ const positions = geometry.attributes.position.array;
708
+ const depthIntensity = selectedQuality === 'low' ? 0.3 :
709
+ selectedQuality === 'medium' ? 0.6 : 1.0;
710
+
711
+ for (let i = 0; i < positions.length; i += 3) {
712
+ const x = positions[i];
713
+ const y = positions[i + 1];
714
+
715
+ // Normalize coordinates to [0,1] range
716
+ const u = (x / geometry.parameters.width) + 0.5;
717
+ const v = (y / geometry.parameters.height) + 0.5;
718
+
719
+ if (u >= 0 && u <= 1 && v >= 0 && v <= 1) {
720
+ // Simple depth effect based on position
721
+ const depth = (Math.sin(u * Math.PI * 2) * Math.sin(v * Math.PI * 2)) * 0.5 + 0.5;
722
+ positions[i + 2] = depth * depthIntensity;
723
+ }
724
+ }
725
+
726
+ geometry.attributes.position.needsUpdate = true;
727
+ geometry.computeVertexNormals();
728
+ }
729
+
730
+ // Reset button
731
+ document.getElementById('reset-btn').addEventListener('click', () => {
732
+ selectedFile = null;
733
+ processedImage = null;
734
+ convertBtn.disabled = true;
735
+
736
+ dropzone.innerHTML = `
737
+ <div class="flex flex-col items-center justify-center">
738
+ <i class="fas fa-cloud-upload-alt text-4xl text-gray-400 mb-4"></i>
739
+ <p class="mb-2">Drag & drop your image here</p>
740
+ <p class="text-sm text-gray-500 dark:text-gray-400 mb-4">or</p>
741
+ <label for="file-upload" class="px-4 py-2 bg-blue-500 hover:bg-blue-600 text-white rounded-md cursor-pointer transition-colors">
742
+ <i class="fas fa-folder-open mr-2"></i>
743
+ Browse Files
744
+ </label>
745
+ </div>
746
+ `;
747
+
748
+ fileInput.value = '';
749
+ previewPlaceholder.classList.remove('hidden');
750
+ previewCanvas.classList.add('hidden');
751
+ viewControls.classList.add('hidden');
752
+ depthMap.style.display = 'none';
753
+
754
+ if (model) {
755
+ scene.remove(model);
756
+ model = null;
757
+ }
758
+ });
759
+
760
+ // Download button (simulated)
761
+ document.getElementById('download-btn').addEventListener('click', () => {
762
+ alert('In a real application, this would download your 3D model file (GLB, OBJ, etc.).');
763
+ });
764
+ </script>
765
+ <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=CIHIRIS/2d-to-3d-model-generator" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
766
+ </html>
prompts.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ fix tthis app up
2
+ create a Microsoft Trellis 2d to 3d image conversion application with beautiful interface and light and dark mode. There should be a3d model preview after processing that allows a toggle to view mesh in textured, white and wireframe. Image should have background removed if the user wants by using remove background option. User should also be able to choose model quality for output low, medium and high to simplify it.
3
+ the 3d render pipeline is just creating a cube so I'm thinking the image is not having background removed properly. lets use REMBG