| <!DOCTYPE html> |
| <html lang="en"> |
| <head> |
| <meta charset="UTF-8"> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| <title>Hunyuan3D-2 API Tester</title> |
| <style> |
| body { font-family: Arial, sans-serif; max-width: 600px; margin: 40px auto; padding: 20px; } |
| .form-group { margin-bottom: 15px; } |
| label { display: block; font-weight: bold; margin-bottom: 5px; } |
| input[type="file"] { display: block; margin-bottom: 10px; } |
| button { padding: 10px 20px; background-color: #007bff; color: white; border: none; cursor: pointer; font-size: 16px; } |
| button:disabled { background-color: #cccccc; } |
| #status { margin-top: 20px; font-weight: bold; } |
| #result { margin-top: 20px; } |
| a.download-btn { display: inline-block; padding: 10px 20px; background-color: #28a745; color: white; text-decoration: none; border-radius: 5px; } |
| </style> |
| </head> |
| <body> |
|
|
| <h2>Hunyuan3D-2 Multi-View Generator</h2> |
| <p>Upload 4 structured views to generate a 3D model.</p> |
|
|
| <form id="uploadForm"> |
| <div class="form-group"> |
| <label for="front">Front View:</label> |
| <input type="file" id="front" accept="image/*" required> |
| </div> |
| <div class="form-group"> |
| <label for="back">Back View:</label> |
| <input type="file" id="back" accept="image/*" required> |
| </div> |
| <div class="form-group"> |
| <label for="left">Left View:</label> |
| <input type="file" id="left" accept="image/*" required> |
| </div> |
| <div class="form-group"> |
| <label for="right">Right View:</label> |
| <input type="file" id="right" accept="image/*" required> |
| </div> |
|
|
| <button type="submit" id="submitBtn">Generate 3D Model</button> |
| </form> |
|
|
| <div id="status"></div> |
| <div id="result"></div> |
|
|
| <script> |
| document.getElementById('uploadForm').addEventListener('submit', async (e) => { |
| e.preventDefault(); |
| |
| const submitBtn = document.getElementById('submitBtn'); |
| const statusDiv = document.getElementById('status'); |
| const resultDiv = document.getElementById('result'); |
| |
| submitBtn.disabled = true; |
| statusDiv.style.color = 'black'; |
| statusDiv.textContent = 'Processing... This may take a few minutes on the GPU.'; |
| resultDiv.innerHTML = ''; |
| |
| const formData = new FormData(); |
| formData.append('front', document.getElementById('front').files[0]); |
| formData.append('back', document.getElementById('back').files[0]); |
| formData.append('left', document.getElementById('left').files[0]); |
| formData.append('right', document.getElementById('right').files[0]); |
| |
| |
| const apiUrl = 'https://vish85521-3d.hf.space/generate-3d'; |
| |
| try { |
| const response = await fetch(apiUrl, { |
| method: 'POST', |
| body: formData |
| }); |
| |
| if (!response.ok) { |
| const errorText = await response.text(); |
| throw new Error(`Server Error (${response.status}): ${errorText}`); |
| } |
| |
| const blob = await response.blob(); |
| const downloadUrl = URL.createObjectURL(blob); |
| |
| statusDiv.style.color = 'green'; |
| statusDiv.textContent = 'Success! Model generated.'; |
| |
| const link = document.createElement('a'); |
| link.href = downloadUrl; |
| link.download = 'generated_model.glb'; |
| link.className = 'download-btn'; |
| link.textContent = 'Download .glb File'; |
| resultDiv.appendChild(link); |
| |
| } catch (error) { |
| statusDiv.style.color = 'red'; |
| statusDiv.textContent = `Error: ${error.message}`; |
| } finally { |
| submitBtn.disabled = false; |
| } |
| }); |
| </script> |
| </body> |
| </html> |