vishnumeher commited on
Commit
317e664
·
verified ·
1 Parent(s): 6574312

Add 2 files

Browse files
Files changed (2) hide show
  1. README.md +6 -4
  2. index.html +613 -19
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: Vhn 3d
3
- emoji: 👁
4
- colorFrom: purple
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: vhn-3d
3
+ emoji: 🐳
4
+ colorFrom: gray
5
  colorTo: purple
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,613 @@
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>AI 3D Model Generator</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
9
+ <style>
10
+ .dropzone {
11
+ border: 2px dashed #6366f1;
12
+ border-radius: 0.75rem;
13
+ transition: all 0.3s ease;
14
+ }
15
+ .dropzone.active {
16
+ border-color: #4f46e5;
17
+ background-color: rgba(99, 102, 241, 0.1);
18
+ }
19
+ .result-container {
20
+ transition: all 0.5s ease;
21
+ max-height: 0;
22
+ overflow: hidden;
23
+ }
24
+ .result-container.show {
25
+ max-height: 1000px;
26
+ }
27
+ .model-card {
28
+ transition: all 0.3s ease;
29
+ }
30
+ .model-card:hover {
31
+ transform: translateY(-5px);
32
+ box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
33
+ }
34
+ .model-card.selected {
35
+ border-color: #6366f1;
36
+ background-color: rgba(99, 102, 241, 0.05);
37
+ }
38
+ .spinner {
39
+ animation: spin 1s linear infinite;
40
+ }
41
+ @keyframes spin {
42
+ from { transform: rotate(0deg); }
43
+ to { transform: rotate(360deg); }
44
+ }
45
+ canvas {
46
+ max-width: 100%;
47
+ border-radius: 0.5rem;
48
+ box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
49
+ }
50
+ .model-badge {
51
+ position: absolute;
52
+ top: 10px;
53
+ right: 10px;
54
+ background-color: rgba(0, 0, 0, 0.7);
55
+ color: white;
56
+ padding: 2px 8px;
57
+ border-radius: 12px;
58
+ font-size: 12px;
59
+ }
60
+ .progress-text {
61
+ position: absolute;
62
+ top: 50%;
63
+ left: 50%;
64
+ transform: translate(-50%, -50%);
65
+ color: white;
66
+ font-weight: bold;
67
+ text-shadow: 0 0 3px rgba(0, 0, 0, 0.5);
68
+ }
69
+ </style>
70
+ </head>
71
+ <body class="bg-gray-50 min-h-screen">
72
+ <div class="container mx-auto px-4 py-12">
73
+ <div class="text-center mb-12">
74
+ <h1 class="text-4xl font-bold text-indigo-600 mb-3">AI 3D Model Generator</h1>
75
+ <p class="text-lg text-gray-600 max-w-2xl mx-auto">Transform your 2D images into high-quality 3D models using cutting-edge AI models</p>
76
+ </div>
77
+
78
+ <div class="bg-white rounded-xl shadow-lg p-6 max-w-4xl mx-auto">
79
+ <!-- Upload Section -->
80
+ <div id="upload-section" class="mb-8">
81
+ <h2 class="text-2xl font-semibold text-gray-800 mb-4">Upload Your Image</h2>
82
+ <div id="dropzone" class="dropzone p-12 text-center cursor-pointer">
83
+ <div class="flex flex-col items-center justify-center">
84
+ <i class="fas fa-cloud-upload-alt text-5xl text-indigo-500 mb-4"></i>
85
+ <p class="text-lg text-gray-600 mb-2">Drag & drop your image here</p>
86
+ <p class="text-sm text-gray-500 mb-4">or</p>
87
+ <label for="file-upload" class="px-6 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition cursor-pointer">
88
+ Browse Files
89
+ </label>
90
+ <input id="file-upload" type="file" accept="image/*" class="hidden">
91
+ </div>
92
+ </div>
93
+ <div id="preview-container" class="mt-6 hidden">
94
+ <h3 class="text-lg font-medium text-gray-700 mb-3">Image Preview</h3>
95
+ <div class="flex items-center">
96
+ <div class="relative">
97
+ <img id="image-preview" src="" alt="Preview" class="max-w-xs rounded-lg shadow">
98
+ <div id="model-badge" class="model-badge hidden">
99
+ <span id="selected-model-name">TripoSR</span>
100
+ </div>
101
+ </div>
102
+ <button id="change-image" class="ml-4 px-4 py-2 bg-gray-200 text-gray-700 rounded-lg hover:bg-gray-300 transition">
103
+ <i class="fas fa-redo mr-2"></i>Change Image
104
+ </button>
105
+ </div>
106
+ </div>
107
+ </div>
108
+
109
+ <!-- Model Selection -->
110
+ <div id="model-selection" class="mb-8 hidden">
111
+ <h2 class="text-2xl font-semibold text-gray-800 mb-4">Select AI Model</h2>
112
+ <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
113
+ <div class="model-card p-4 border-2 border-gray-200 rounded-xl cursor-pointer" data-model="triposr">
114
+ <div class="flex flex-col items-center text-center">
115
+ <div class="w-16 h-16 bg-indigo-100 rounded-full flex items-center justify-center mb-3">
116
+ <i class="fas fa-cube text-2xl text-indigo-600"></i>
117
+ </div>
118
+ <h3 class="font-medium text-gray-800 mb-1">TripoSR</h3>
119
+ <p class="text-sm text-gray-500 mb-2">Fast feed-forward 3D object reconstruction</p>
120
+ <div class="text-xs text-indigo-600 bg-indigo-50 px-2 py-1 rounded">
121
+ <i class="fas fa-bolt mr-1"></i> Fast processing
122
+ </div>
123
+ </div>
124
+ </div>
125
+ <div class="model-card p-4 border-2 border-gray-200 rounded-xl cursor-pointer" data-model="real3d">
126
+ <div class="flex flex-col items-center text-center">
127
+ <div class="w-16 h-16 bg-indigo-100 rounded-full flex items-center justify-center mb-3">
128
+ <i class="fas fa-user text-2xl text-indigo-600"></i>
129
+ </div>
130
+ <h3 class="font-medium text-gray-800 mb-1">Real3D</h3>
131
+ <p class="text-sm text-gray-500 mb-2">High-quality 3D face reconstruction</p>
132
+ <div class="text-xs text-indigo-600 bg-indigo-50 px-2 py-1 rounded">
133
+ <i class="fas fa-star mr-1"></i> High quality
134
+ </div>
135
+ </div>
136
+ </div>
137
+ </div>
138
+ <div class="mt-6">
139
+ <button id="generate-btn" class="w-full md:w-auto px-6 py-3 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition font-medium hidden">
140
+ <i class="fas fa-magic mr-2"></i> Generate 3D Model
141
+ </button>
142
+ </div>
143
+ </div>
144
+
145
+ <!-- Processing Section -->
146
+ <div id="processing-section" class="hidden">
147
+ <div class="flex flex-col items-center justify-center py-8">
148
+ <div class="relative w-24 h-24 mb-4">
149
+ <div class="w-full h-full border-4 border-indigo-500 border-t-transparent rounded-full spinner"></div>
150
+ <div id="progress-text" class="progress-text">0%</div>
151
+ </div>
152
+ <h3 class="text-xl font-medium text-gray-800 mb-2">Processing Your Image</h3>
153
+ <p class="text-gray-600 text-center max-w-md" id="processing-message">Initializing the AI model...</p>
154
+ <div class="w-full bg-gray-200 rounded-full h-2.5 mt-4 max-w-md">
155
+ <div id="progress-bar" class="bg-indigo-600 h-2.5 rounded-full" style="width: 0%"></div>
156
+ </div>
157
+ </div>
158
+ </div>
159
+
160
+ <!-- Results Section -->
161
+ <div id="result-section" class="result-container">
162
+ <div class="border-t border-gray-200 pt-6 mt-6">
163
+ <div class="flex justify-between items-center mb-4">
164
+ <h2 class="text-2xl font-semibold text-gray-800">Your 3D Model</h2>
165
+ <span id="model-used" class="text-sm bg-indigo-100 text-indigo-800 px-3 py-1 rounded-full"></span>
166
+ </div>
167
+ <div class="flex flex-col md:flex-row gap-8">
168
+ <div class="flex-1">
169
+ <div class="bg-gray-100 p-4 rounded-lg relative">
170
+ <canvas id="3d-viewer"></canvas>
171
+ <div id="viewer-controls" class="absolute bottom-4 left-4 flex gap-2">
172
+ <button id="rotate-toggle" class="bg-white p-2 rounded-full shadow-md">
173
+ <i class="fas fa-sync-alt"></i>
174
+ </button>
175
+ <button id="reset-view" class="bg-white p-2 rounded-full shadow-md">
176
+ <i class="fas fa-expand"></i>
177
+ </button>
178
+ </div>
179
+ </div>
180
+ <div class="mt-4 grid grid-cols-3 gap-2">
181
+ <button id="view-front" class="bg-gray-200 p-2 rounded text-sm">
182
+ <i class="fas fa-arrow-up mr-1"></i> Front
183
+ </button>
184
+ <button id="view-side" class="bg-gray-200 p-2 rounded text-sm">
185
+ <i class="fas fa-arrow-right mr-1"></i> Side
186
+ </button>
187
+ <button id="view-top" class="bg-gray-200 p-2 rounded text-sm">
188
+ <i class="fas fa-arrow-down mr-1"></i> Top
189
+ </button>
190
+ </div>
191
+ </div>
192
+ <div class="flex-1">
193
+ <h3 class="text-lg font-medium text-gray-800 mb-3">Model Information</h3>
194
+ <div class="bg-white border border-gray-200 rounded-lg p-4 mb-4">
195
+ <div class="flex justify-between mb-2">
196
+ <span class="text-gray-600">Model:</span>
197
+ <span id="model-type" class="font-medium">TripoSR</span>
198
+ </div>
199
+ <div class="flex justify-between mb-2">
200
+ <span class="text-gray-600">Vertices:</span>
201
+ <span id="vertex-count" class="font-medium">12,456</span>
202
+ </div>
203
+ <div class="flex justify-between mb-2">
204
+ <span class="text-gray-600">Faces:</span>
205
+ <span id="face-count" class="font-medium">6,228</span>
206
+ </div>
207
+ <div class="flex justify-between">
208
+ <span class="text-gray-600">Processing Time:</span>
209
+ <span id="processing-time" class="font-medium">4.2s</span>
210
+ </div>
211
+ </div>
212
+ <div class="flex flex-wrap gap-3">
213
+ <button id="download-obj" class="px-4 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition flex items-center">
214
+ <i class="fas fa-download mr-2"></i> Download OBJ
215
+ </button>
216
+ <button id="download-stl" class="px-4 py-2 bg-gray-200 text-gray-700 rounded-lg hover:bg-gray-300 transition flex items-center">
217
+ <i class="fas fa-download mr-2"></i> Download STL
218
+ </button>
219
+ <button id="download-gltf" class="px-4 py-2 bg-gray-200 text-gray-700 rounded-lg hover:bg-gray-300 transition flex items-center">
220
+ <i class="fas fa-download mr-2"></i> Download GLTF
221
+ </button>
222
+ <button id="new-conversion" class="px-4 py-2 bg-gray-200 text-gray-700 rounded-lg hover:bg-gray-300 transition flex items-center">
223
+ <i class="fas fa-redo mr-2"></i> New Conversion
224
+ </button>
225
+ </div>
226
+ </div>
227
+ </div>
228
+ </div>
229
+ </div>
230
+ </div>
231
+
232
+ <div class="mt-12 text-center text-gray-500 text-sm">
233
+ <p>Powered by <a href="https://huggingface.co/stabilityai/TripoSR" class="text-indigo-600 hover:underline" target="_blank">TripoSR</a> and <a href="https://huggingface.co/spaces/hwjiang/Real3D" class="text-indigo-600 hover:underline" target="_blank">Real3D</a> AI models</p>
234
+ </div>
235
+ </div>
236
+
237
+ <!-- Three.js for 3D preview -->
238
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
239
+ <script src="https://cdn.jsdelivr.net/npm/[email protected]/examples/js/controls/OrbitControls.min.js"></script>
240
+ <script src="https://cdn.jsdelivr.net/npm/[email protected]/examples/js/loaders/GLTFLoader.min.js"></script>
241
+ <script src="https://cdn.jsdelivr.net/npm/[email protected]/examples/js/loaders/OBJLoader.min.js"></script>
242
+
243
+ <script>
244
+ // DOM Elements
245
+ const dropzone = document.getElementById('dropzone');
246
+ const fileUpload = document.getElementById('file-upload');
247
+ const previewContainer = document.getElementById('preview-container');
248
+ const imagePreview = document.getElementById('image-preview');
249
+ const changeImageBtn = document.getElementById('change-image');
250
+ const modelSelection = document.getElementById('model-selection');
251
+ const modelCards = document.querySelectorAll('.model-card');
252
+ const generateBtn = document.getElementById('generate-btn');
253
+ const processingSection = document.getElementById('processing-section');
254
+ const progressBar = document.getElementById('progress-bar');
255
+ const progressText = document.getElementById('progress-text');
256
+ const processingMessage = document.getElementById('processing-message');
257
+ const resultSection = document.getElementById('result-section');
258
+ const newConversionBtn = document.getElementById('new-conversion');
259
+ const modelBadge = document.getElementById('model-badge');
260
+ const modelUsed = document.getElementById('model-used');
261
+
262
+ // Variables
263
+ let selectedFile = null;
264
+ let selectedModel = null;
265
+ let threeScene = null;
266
+ let threeControls = null;
267
+ let threeCamera = null;
268
+ let threeRenderer = null;
269
+ let threeModel = null;
270
+ let autoRotate = true;
271
+
272
+ // Event Listeners
273
+ dropzone.addEventListener('click', () => fileUpload.click());
274
+
275
+ fileUpload.addEventListener('change', (e) => {
276
+ if (e.target.files.length) {
277
+ handleFileUpload(e.target.files[0]);
278
+ }
279
+ });
280
+
281
+ dropzone.addEventListener('dragover', (e) => {
282
+ e.preventDefault();
283
+ dropzone.classList.add('active');
284
+ });
285
+
286
+ dropzone.addEventListener('dragleave', () => {
287
+ dropzone.classList.remove('active');
288
+ });
289
+
290
+ dropzone.addEventListener('drop', (e) => {
291
+ e.preventDefault();
292
+ dropzone.classList.remove('active');
293
+
294
+ if (e.dataTransfer.files.length) {
295
+ handleFileUpload(e.dataTransfer.files[0]);
296
+ }
297
+ });
298
+
299
+ changeImageBtn.addEventListener('click', () => {
300
+ selectedFile = null;
301
+ previewContainer.classList.add('hidden');
302
+ modelSelection.classList.add('hidden');
303
+ generateBtn.classList.add('hidden');
304
+ fileUpload.value = '';
305
+ modelBadge.classList.add('hidden');
306
+ });
307
+
308
+ modelCards.forEach(card => {
309
+ card.addEventListener('click', () => {
310
+ modelCards.forEach(c => c.classList.remove('selected'));
311
+ card.classList.add('selected');
312
+ selectedModel = card.getAttribute('data-model');
313
+
314
+ // Update model badge
315
+ const modelName = card.querySelector('h3').textContent;
316
+ document.getElementById('selected-model-name').textContent = modelName;
317
+ modelBadge.classList.remove('hidden');
318
+
319
+ // Show generate button
320
+ generateBtn.classList.remove('hidden');
321
+ });
322
+ });
323
+
324
+ generateBtn.addEventListener('click', () => {
325
+ if (!selectedFile || !selectedModel) return;
326
+
327
+ // Show processing section
328
+ processingSection.classList.remove('hidden');
329
+
330
+ // Set appropriate processing message
331
+ processingMessage.textContent = selectedModel === 'triposr'
332
+ ? "Processing with TripoSR model (this may take 20-30 seconds)..."
333
+ : "Processing with Real3D model (this may take 1-2 minutes)...";
334
+
335
+ // Start processing
336
+ processImageWithModel(selectedModel, selectedFile);
337
+ });
338
+
339
+ newConversionBtn.addEventListener('click', resetForm);
340
+
341
+ // 3D Viewer Controls
342
+ document.getElementById('rotate-toggle').addEventListener('click', () => {
343
+ autoRotate = !autoRotate;
344
+ if (threeControls) threeControls.autoRotate = autoRotate;
345
+ });
346
+
347
+ document.getElementById('reset-view').addEventListener('click', () => {
348
+ if (threeControls && threeCamera) {
349
+ threeControls.reset();
350
+ threeCamera.position.z = 5;
351
+ }
352
+ });
353
+
354
+ document.getElementById('view-front').addEventListener('click', () => {
355
+ if (threeControls && threeCamera) {
356
+ threeControls.reset();
357
+ threeCamera.position.set(0, 0, 5);
358
+ }
359
+ });
360
+
361
+ document.getElementById('view-side').addEventListener('click', () => {
362
+ if (threeControls && threeCamera) {
363
+ threeControls.reset();
364
+ threeCamera.position.set(5, 0, 0);
365
+ }
366
+ });
367
+
368
+ document.getElementById('view-top').addEventListener('click', () => {
369
+ if (threeControls && threeCamera) {
370
+ threeControls.reset();
371
+ threeCamera.position.set(0, 5, 0);
372
+ }
373
+ });
374
+
375
+ // Functions
376
+ function handleFileUpload(file) {
377
+ if (!file.type.match('image.*')) {
378
+ alert('Please upload an image file');
379
+ return;
380
+ }
381
+
382
+ selectedFile = file;
383
+
384
+ // Show preview
385
+ const reader = new FileReader();
386
+ reader.onload = (e) => {
387
+ imagePreview.src = e.target.result;
388
+ previewContainer.classList.remove('hidden');
389
+ modelSelection.classList.remove('hidden');
390
+ };
391
+ reader.readAsDataURL(file);
392
+ }
393
+
394
+ async function processImageWithModel(modelType, file) {
395
+ // Simulate progress for demo purposes
396
+ let progress = 0;
397
+ const interval = setInterval(() => {
398
+ progress += Math.random() * 5;
399
+ if (progress > 100) progress = 100;
400
+ progressBar.style.width = `${progress}%`;
401
+ progressText.textContent = `${Math.floor(progress)}%`;
402
+
403
+ // Update messages based on progress
404
+ if (progress < 30) {
405
+ processingMessage.textContent = modelType === 'triposr'
406
+ ? "Uploading image to TripoSR model..."
407
+ : "Uploading image to Real3D model...";
408
+ } else if (progress < 70) {
409
+ processingMessage.textContent = modelType === 'triposr'
410
+ ? "Generating 3D reconstruction..."
411
+ : "Creating high-quality 3D face model...";
412
+ } else {
413
+ processingMessage.textContent = "Finalizing and preparing your 3D model...";
414
+ }
415
+
416
+ if (progress === 100) {
417
+ clearInterval(interval);
418
+ setTimeout(() => {
419
+ processingSection.classList.add('hidden');
420
+ showResults(modelType);
421
+ }, 1000);
422
+ }
423
+ }, 500);
424
+
425
+ // In a real implementation, you would call the Hugging Face API here
426
+ // For example:
427
+ /*
428
+ try {
429
+ const formData = new FormData();
430
+ formData.append('image', file);
431
+
432
+ const endpoint = modelType === 'triposr'
433
+ ? 'https://api-inference.huggingface.co/models/stabilityai/TripoSR'
434
+ : 'https://api-inference.huggingface.co/models/hwjiang/Real3D';
435
+
436
+ const response = await fetch(endpoint, {
437
+ method: 'POST',
438
+ headers: {
439
+ 'Authorization': 'Bearer YOUR_HUGGINGFACE_TOKEN',
440
+ },
441
+ body: formData
442
+ });
443
+
444
+ const result = await response.json();
445
+ return result;
446
+ } catch (error) {
447
+ console.error('Error:', error);
448
+ throw error;
449
+ }
450
+ */
451
+ }
452
+
453
+ function showResults(modelType) {
454
+ // Update model info
455
+ const modelName = modelType === 'triposr' ? 'TripoSR' : 'Real3D';
456
+ document.getElementById('model-type').textContent = modelName;
457
+ modelUsed.textContent = modelName;
458
+
459
+ // Generate random stats for demo
460
+ const vertices = modelType === 'triposr'
461
+ ? Math.floor(Math.random() * 15000 + 5000)
462
+ : Math.floor(Math.random() * 25000 + 10000);
463
+
464
+ const faces = modelType === 'triposr'
465
+ ? Math.floor(Math.random() * 7500 + 2500)
466
+ : Math.floor(Math.random() * 12500 + 5000);
467
+
468
+ const time = modelType === 'triposr'
469
+ ? (Math.random() * 10 + 20).toFixed(1)
470
+ : (Math.random() * 30 + 60).toFixed(1);
471
+
472
+ document.getElementById('vertex-count').textContent = vertices.toLocaleString();
473
+ document.getElementById('face-count').textContent = faces.toLocaleString();
474
+ document.getElementById('processing-time').textContent = `${time}s`;
475
+
476
+ // Initialize 3D viewer with appropriate model
477
+ init3DViewer(modelType);
478
+
479
+ // Show results
480
+ resultSection.classList.add('show');
481
+ }
482
+
483
+ function init3DViewer(modelType) {
484
+ const canvas = document.getElementById('3d-viewer');
485
+
486
+ // Clear previous renderer if exists
487
+ if (threeRenderer) {
488
+ threeRenderer.dispose();
489
+ }
490
+
491
+ threeRenderer = new THREE.WebGLRenderer({
492
+ canvas,
493
+ antialias: true,
494
+ alpha: true
495
+ });
496
+ threeRenderer.setSize(canvas.clientWidth, canvas.clientHeight);
497
+ threeRenderer.setClearColor(0xf0f0f0, 1);
498
+
499
+ threeScene = new THREE.Scene();
500
+
501
+ threeCamera = new THREE.PerspectiveCamera(45, canvas.clientWidth / canvas.clientHeight, 0.1, 1000);
502
+ threeCamera.position.z = 5;
503
+
504
+ threeControls = new THREE.OrbitControls(threeCamera, canvas);
505
+ threeControls.enableDamping = true;
506
+ threeControls.dampingFactor = 0.25;
507
+ threeControls.autoRotate = autoRotate;
508
+
509
+ // Add lights
510
+ const ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
511
+ threeScene.add(ambientLight);
512
+
513
+ const directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
514
+ directionalLight.position.set(1, 1, 1);
515
+ threeScene.add(directionalLight);
516
+
517
+ // Create different models based on selected type
518
+ if (modelType === 'real3d') {
519
+ // Create a face-like geometry for Real3D
520
+ const geometry = new THREE.SphereGeometry(1, 64, 64);
521
+
522
+ // Create texture from uploaded image
523
+ const texture = new THREE.Texture(imagePreview);
524
+ texture.needsUpdate = true;
525
+
526
+ const material = new THREE.MeshPhongMaterial({
527
+ map: texture,
528
+ specular: 0x111111,
529
+ shininess: 30,
530
+ side: THREE.DoubleSide
531
+ });
532
+
533
+ threeModel = new THREE.Mesh(geometry, material);
534
+ } else {
535
+ // Create a more complex object for TripoSR
536
+ const geometry = new THREE.TorusKnotGeometry(0.7, 0.2, 100, 16);
537
+
538
+ // Create texture from uploaded image
539
+ const texture = new THREE.Texture(imagePreview);
540
+ texture.needsUpdate = true;
541
+
542
+ const material = new THREE.MeshPhongMaterial({
543
+ map: texture,
544
+ specular: 0x111111,
545
+ shininess: 30
546
+ });
547
+
548
+ threeModel = new THREE.Mesh(geometry, material);
549
+ }
550
+
551
+ threeScene.add(threeModel);
552
+
553
+ // Animation loop
554
+ function animate() {
555
+ requestAnimationFrame(animate);
556
+
557
+ if (threeControls) {
558
+ threeControls.update();
559
+ }
560
+
561
+ threeRenderer.render(threeScene, threeCamera);
562
+ }
563
+
564
+ animate();
565
+
566
+ // Handle resize
567
+ window.addEventListener('resize', () => {
568
+ threeCamera.aspect = canvas.clientWidth / canvas.clientHeight;
569
+ threeCamera.updateProjectionMatrix();
570
+ threeRenderer.setSize(canvas.clientWidth, canvas.clientHeight);
571
+ });
572
+ }
573
+
574
+ function resetForm() {
575
+ selectedFile = null;
576
+ selectedModel = null;
577
+
578
+ previewContainer.classList.add('hidden');
579
+ modelSelection.classList.add('hidden');
580
+ generateBtn.classList.add('hidden');
581
+ processingSection.classList.add('hidden');
582
+ resultSection.classList.remove('show');
583
+ modelBadge.classList.add('hidden');
584
+
585
+ fileUpload.value = '';
586
+ modelCards.forEach(c => c.classList.remove('selected'));
587
+
588
+ // Reset progress bar
589
+ progressBar.style.width = '0%';
590
+ progressText.textContent = '0%';
591
+
592
+ // Clear 3D viewer if exists
593
+ if (threeScene && threeModel) {
594
+ threeScene.remove(threeModel);
595
+ threeModel = null;
596
+ }
597
+ }
598
+
599
+ // Download buttons functionality (simulated)
600
+ document.getElementById('download-obj').addEventListener('click', () => {
601
+ alert('In a real implementation, this would download the OBJ file generated by the model');
602
+ });
603
+
604
+ document.getElementById('download-stl').addEventListener('click', () => {
605
+ alert('In a real implementation, this would download the STL file generated by the model');
606
+ });
607
+
608
+ document.getElementById('download-gltf').addEventListener('click', () => {
609
+ alert('In a real implementation, this would download the GLTF file generated by the model');
610
+ });
611
+ </script>
612
+ <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=vishnumeher/vhn-3d" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
613
+ </html>