trip33 / index.html
vish85521's picture
Create index.html
fb9b836 verified
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TripoSR Free CPU API</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>TripoSR 3D Generator</h2>
<p>Upload a single image. The server will remove the background and generate a 3D model.</p>
<form id="uploadForm">
<div class="form-group">
<label for="image">Upload Image:</label>
<input type="file" id="image" 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 = 'Uploading and processing... This takes a few minutes on the free CPU tier. Please wait!';
resultDiv.innerHTML = '';
const formData = new FormData();
formData.append('image', document.getElementById('image').files[0]);
// ⚠️ IMPORTANT: Replace this with your actual Hugging Face Space URL!
const apiUrl = 'https://YOUR-SPACE-NAME.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.obj';
link.className = 'download-btn';
link.textContent = 'Download .obj File';
resultDiv.appendChild(link);
} catch (error) {
statusDiv.style.color = 'red';
statusDiv.textContent = `Error: ${error.message}`;
} finally {
submitBtn.disabled = false;
}
});
</script>
</body>
</html>