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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ===========================================================
|
| 2 |
+
# AI 3D Model Generator — Complete Setup & Deployment Guide
|
| 3 |
+
# ===========================================================
|
| 4 |
+
#
|
| 5 |
+
# This file contains step-by-step instructions for deploying
|
| 6 |
+
# the pipeline to Hugging Face Spaces and connecting it to n8n.
|
| 7 |
+
#
|
| 8 |
+
# Table of Contents:
|
| 9 |
+
# 1. Overview
|
| 10 |
+
# 2. Hugging Face Space Deployment
|
| 11 |
+
# 3. n8n Workflow Setup
|
| 12 |
+
# 4. Testing the Pipeline
|
| 13 |
+
# 5. API Reference
|
| 14 |
+
# ===========================================================
|
| 15 |
+
|
| 16 |
+
# ===========================================================
|
| 17 |
+
# 1. OVERVIEW
|
| 18 |
+
# ===========================================================
|
| 19 |
+
#
|
| 20 |
+
# Pipeline Flow:
|
| 21 |
+
#
|
| 22 |
+
# [n8n Webhook] ──▶ [Parse Request] ──▶ [Download Images]
|
| 23 |
+
# │ │
|
| 24 |
+
# ▼ ▼
|
| 25 |
+
# [Receive POST with] [Convert URLs to base64]
|
| 26 |
+
# [images + prompt] │
|
| 27 |
+
# ▼
|
| 28 |
+
# [Call HF Space Gradio API]
|
| 29 |
+
# │
|
| 30 |
+
# ▼
|
| 31 |
+
# [TripoSG Pipeline]
|
| 32 |
+
# ├─ Background Removal (RMBG-1.4)
|
| 33 |
+
# ├─ Best View Selection
|
| 34 |
+
# ├─ 3D Reconstruction
|
| 35 |
+
# ├─ Manifold Repair
|
| 36 |
+
# ├─ Dimension Scaling
|
| 37 |
+
# └─ (Optional) Part Segmentation
|
| 38 |
+
# │
|
| 39 |
+
# ▼
|
| 40 |
+
# [Download GLB/OBJ/STL File]
|
| 41 |
+
# │
|
| 42 |
+
# ▼
|
| 43 |
+
# [Respond with Binary File]
|
| 44 |
+
#
|
| 45 |
+
# ===========================================================
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
# ===========================================================
|
| 49 |
+
# 2. HUGGING FACE SPACE DEPLOYMENT
|
| 50 |
+
# ===========================================================
|
| 51 |
+
|
| 52 |
+
# Step 1: Create a new Hugging Face Space
|
| 53 |
+
# ----------------------------------------
|
| 54 |
+
# Go to: https://huggingface.co/new-space
|
| 55 |
+
# - Owner: your-username
|
| 56 |
+
# - Space name: ai-3d-generator
|
| 57 |
+
# - License: MIT
|
| 58 |
+
# - SDK: Gradio
|
| 59 |
+
# - Hardware: ZeroGPU (or GPU Basic for testing)
|
| 60 |
+
# - Click "Create Space"
|
| 61 |
+
|
| 62 |
+
# Step 2: Upload files via Git
|
| 63 |
+
# ----------------------------------------
|
| 64 |
+
# Clone your new space locally:
|
| 65 |
+
|
| 66 |
+
git clone https://huggingface.co/spaces/YOUR-USERNAME/ai-3d-generator
|
| 67 |
+
cd ai-3d-generator
|
| 68 |
+
|
| 69 |
+
# Copy all files from this directory:
|
| 70 |
+
cp /path/to/ai-3d-generation-print-ready/* .
|
| 71 |
+
|
| 72 |
+
# The following files should be in the space:
|
| 73 |
+
# ├── README.md (HF Space config — already has YAML frontmatter)
|
| 74 |
+
# ├── app.py (Main Gradio application)
|
| 75 |
+
# ├── mesh_utils.py (Mesh processing utilities)
|
| 76 |
+
# ├── requirements.txt (Python dependencies)
|
| 77 |
+
# └── workflow.json (n8n workflow — for your reference, not needed in Space)
|
| 78 |
+
|
| 79 |
+
# Push to Hugging Face:
|
| 80 |
+
git add .
|
| 81 |
+
git commit -m "Initial deployment: AI 3D Model Generator"
|
| 82 |
+
git push
|
| 83 |
+
|
| 84 |
+
# Step 3: Configure HF Space secrets (optional)
|
| 85 |
+
# ----------------------------------------
|
| 86 |
+
# Go to your Space Settings → Variables and Secrets
|
| 87 |
+
# Add if using private models:
|
| 88 |
+
# HF_TOKEN = hf_xxxxxxxxxxxxxxxxxxxxx
|
| 89 |
+
|
| 90 |
+
# Step 4: Wait for build
|
| 91 |
+
# ----------------------------------------
|
| 92 |
+
# The Space will automatically build and deploy.
|
| 93 |
+
# Watch the "Build" tab for progress (~5-10 minutes first time).
|
| 94 |
+
# Once running, your Space URL will be:
|
| 95 |
+
# https://YOUR-USERNAME-ai-3d-generator.hf.space
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
# ===========================================================
|
| 99 |
+
# 3. N8N WORKFLOW SETUP
|
| 100 |
+
# ===========================================================
|
| 101 |
+
|
| 102 |
+
# Step 1: Import the workflow
|
| 103 |
+
# ----------------------------------------
|
| 104 |
+
# In n8n, go to: Workflows → Import from File
|
| 105 |
+
# Select: workflow.json from this directory
|
| 106 |
+
# The workflow will be imported with all nodes pre-configured.
|
| 107 |
+
|
| 108 |
+
# Step 2: Configure variables
|
| 109 |
+
# ----------------------------------------
|
| 110 |
+
# In n8n, go to: Settings → Variables
|
| 111 |
+
# Add these variables:
|
| 112 |
+
#
|
| 113 |
+
# HF_SPACE_URL = YOUR-USERNAME-ai-3d-generator.hf.space
|
| 114 |
+
# HF_TOKEN = hf_xxxxxxxxxxxxxxxxxxxxx (your HF access token)
|
| 115 |
+
#
|
| 116 |
+
# Alternatively, set up HuggingFace API credentials in n8n:
|
| 117 |
+
# Settings → Credentials → Add Credential → Hugging Face API
|
| 118 |
+
|
| 119 |
+
# Step 3: Activate the workflow
|
| 120 |
+
# ----------------------------------------
|
| 121 |
+
# Toggle the workflow to "Active"
|
| 122 |
+
# Note your webhook URL:
|
| 123 |
+
# https://your-n8n-instance.com/webhook/generate-3d-model
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
# ===========================================================
|
| 127 |
+
# 4. TESTING THE PIPELINE
|
| 128 |
+
# ===========================================================
|
| 129 |
+
|
| 130 |
+
# Test via curl (images as URLs):
|
| 131 |
+
curl -X POST https://your-n8n-instance.com/webhook/generate-3d-model \
|
| 132 |
+
-H "Content-Type: application/json" \
|
| 133 |
+
-d '{
|
| 134 |
+
"images": [
|
| 135 |
+
"https://example.com/front-view.jpg",
|
| 136 |
+
"https://example.com/side-view.jpg",
|
| 137 |
+
"https://example.com/back-view.jpg"
|
| 138 |
+
],
|
| 139 |
+
"prompt": "Industrial bracket, base is 10cm x 5cm, M6 bolt holes on corners, matte steel finish",
|
| 140 |
+
"faces": 50000,
|
| 141 |
+
"format": "glb",
|
| 142 |
+
"modular": false
|
| 143 |
+
}' \
|
| 144 |
+
--output model.glb
|
| 145 |
+
|
| 146 |
+
# Test via curl (images as base64):
|
| 147 |
+
IMAGE_B64=$(base64 -w0 my_photo.jpg)
|
| 148 |
+
curl -X POST https://your-n8n-instance.com/webhook/generate-3d-model \
|
| 149 |
+
-H "Content-Type: application/json" \
|
| 150 |
+
-d "{
|
| 151 |
+
\"images\": [\"data:image/jpeg;base64,$IMAGE_B64\"],
|
| 152 |
+
\"prompt\": \"Phone stand, height: 12cm, modern minimalist design\",
|
| 153 |
+
\"faces\": 30000,
|
| 154 |
+
\"format\": \"stl\"
|
| 155 |
+
}" \
|
| 156 |
+
--output model.stl
|
| 157 |
+
|
| 158 |
+
# Test via Python:
|
| 159 |
+
# import requests
|
| 160 |
+
# response = requests.post(
|
| 161 |
+
# "https://your-n8n-instance.com/webhook/generate-3d-model",
|
| 162 |
+
# json={
|
| 163 |
+
# "images": ["https://example.com/object.jpg"],
|
| 164 |
+
# "prompt": "Coffee mug, diameter: 8cm, height: 10cm",
|
| 165 |
+
# "faces": 50000,
|
| 166 |
+
# "format": "glb",
|
| 167 |
+
# },
|
| 168 |
+
# )
|
| 169 |
+
# with open("model.glb", "wb") as f:
|
| 170 |
+
# f.write(response.content)
|
| 171 |
+
|
| 172 |
+
# Test the HF Space directly (without n8n):
|
| 173 |
+
# Open your Space URL in a browser and use the web UI directly.
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
# ===========================================================
|
| 177 |
+
# 5. API REFERENCE
|
| 178 |
+
# ===========================================================
|
| 179 |
+
|
| 180 |
+
# Webhook Request Format:
|
| 181 |
+
# POST /webhook/generate-3d-model
|
| 182 |
+
# Content-Type: application/json
|
| 183 |
+
#
|
| 184 |
+
# {
|
| 185 |
+
# "images": [ // Array of image sources
|
| 186 |
+
# "https://example.com/front.jpg", // Image URLs (auto-downloaded)
|
| 187 |
+
# "data:image/png;base64,iVBOR..." // Or base64 encoded images
|
| 188 |
+
# ],
|
| 189 |
+
# "prompt": "string", // Text instructions
|
| 190 |
+
# // Supports dimension extraction:
|
| 191 |
+
# // "base is 10cm"
|
| 192 |
+
# // "10cm x 5cm x 3cm"
|
| 193 |
+
# // "height: 200mm"
|
| 194 |
+
# // "scale 1:10"
|
| 195 |
+
# "faces": 50000, // Target face count (5000-90000)
|
| 196 |
+
# "format": "glb", // Export format: glb, obj, stl
|
| 197 |
+
# "modular": false // Split into modular parts
|
| 198 |
+
# }
|
| 199 |
+
#
|
| 200 |
+
# Response:
|
| 201 |
+
# 200 OK — Binary file (GLB/OBJ/STL)
|
| 202 |
+
# Headers:
|
| 203 |
+
# Content-Disposition: attachment; filename="model_20260224_120000.glb"
|
| 204 |
+
# Content-Type: model/gltf-binary
|
| 205 |
+
# X-Pipeline-Status: "✅ Complete in 45.2s — manifold: True, vertices: 12345, faces: 50000"
|
| 206 |
+
#
|
| 207 |
+
# Error Response:
|
| 208 |
+
# 500 Internal Server Error
|
| 209 |
+
# { "success": false, "error": "...", "message": "..." }
|
| 210 |
+
|
| 211 |
+
# ===========================================================
|
| 212 |
+
# SUPPORTED TEXT PROMPT PATTERNS
|
| 213 |
+
# ===========================================================
|
| 214 |
+
# The pipeline parses your text prompt to extract dimensions:
|
| 215 |
+
#
|
| 216 |
+
# Pattern Example
|
| 217 |
+
# ─────────────────────────────── ──────────────────────────────
|
| 218 |
+
# 3D dimensions: "10cm x 5cm x 3cm"
|
| 219 |
+
# Individual dims: "base is 10cm", "height: 200mm"
|
| 220 |
+
# Scale ratios: "scale 1:10", "ratio is 1:5"
|
| 221 |
+
# Materials (passed to model): "matte steel finish"
|
| 222 |
+
# Details (passed to model): "M6 bolt holes on each corner"
|
| 223 |
+
# Style (passed to model): "modern minimalist design"
|
| 224 |
+
#
|
| 225 |
+
# Units supported: mm, cm, m, in, inch, inches, ft, feet
|