Spaces:
Running
Running
| title: PromptAR Backend API | |
| emoji: π¨ | |
| colorFrom: blue | |
| colorTo: purple | |
| sdk: docker | |
| pinned: false | |
| license: mit | |
| app_port: 7860 | |
| # PromptAR Backend API | |
| FastAPI backend for generating 3D models from text prompts using AI, optimized for AR applications. | |
| ## Features | |
| - π¨ **Text-to-3D Generation**: Generate 3D models from text prompts using TRELLIS and Shap-E | |
| - π **Two Generation Modes**: | |
| - **Advanced Mode** (TRELLIS): High-quality textured models | |
| - **Basic Mode** (Shap-E): Fast generation with basic geometry | |
| - π¦ **GLB Format**: Direct export to GLB format optimized for AR | |
| - π§ **AR-Optimized**: Automatic brightness normalization for better AR visibility | |
| - π **Request Logging**: Built-in database for tracking API requests | |
| - π **CORS Enabled**: Ready for cross-origin requests from mobile and web apps | |
| ## API Endpoints | |
| ### π Root Endpoints | |
| - **GET `/`** - API information and status | |
| - **GET `/health`** - Health check endpoint | |
| ### π¨ Model Generation | |
| - **POST `/api/models/generate`** - Generate a 3D model from text | |
| ```json | |
| { | |
| "prompt": "wooden chair", | |
| "mode": "advanced" | |
| } | |
| ``` | |
| - **GET `/api/models/download/{model_id}`** - Download generated model | |
| ## Usage | |
| ### API Documentation | |
| Once deployed, visit: | |
| - Interactive docs: `https://your-space-url.hf.space/docs` | |
| - Alternative docs: `https://your-space-url.hf.space/redoc` | |
| ### Example Request | |
| ```bash | |
| curl -X POST "https://your-space-url.hf.space/api/models/generate" \ | |
| -H "Content-Type: application/json" \ | |
| -d '{"prompt": "a red sports car", "mode": "advanced"}' | |
| ``` | |
| ### Response | |
| ```json | |
| { | |
| "status": "success", | |
| "message": "3D model generated successfully using advanced mode", | |
| "model_id": "abc123-456def-789ghi", | |
| "download_url": "/api/models/download/abc123-456def-789ghi" | |
| } | |
| ``` | |
| ## Configuration | |
| The backend uses environment variables for configuration. In Hugging Face Spaces, set these in the **Settings > Repository Secrets**: | |
| ### Required | |
| - `HF_TOKEN` - Your Hugging Face API token (get it from [Settings](https://huggingface.co/settings/tokens)) | |
| ### Optional | |
| - `ALLOWED_ORIGINS` - CORS allowed origins (default: "*") | |
| - `MODEL_STORAGE_PATH` - Path for storing models (default: "./models") | |
| ## Architecture | |
| The backend is built with: | |
| - **FastAPI**: Modern Python web framework | |
| - **Gradio Client**: Integration with HF Spaces (TRELLIS, Shap-E) | |
| - **Pydantic**: Data validation | |
| - **SQLite**: Request logging database | |
| - **pygltflib**: 3D model processing | |
| ### Project Structure | |
| ``` | |
| backend/ | |
| βββ app/ # Application factory | |
| β βββ app.py # FastAPI app creation | |
| βββ routers/ # API route handlers | |
| β βββ root.py # Root endpoints | |
| β βββ models.py # Model generation endpoints | |
| βββ services/ # Business logic | |
| β βββ huggingface_service.py # AI model integration | |
| β βββ storage_service.py # Model storage | |
| β βββ ar_material_service.py # AR optimization | |
| β βββ database_service.py # Request logging | |
| βββ schemas/ # Request/response models | |
| βββ middleware/ # Custom middleware | |
| βββ utils/ # Utilities | |
| βββ config.py # Configuration | |
| βββ main.py # Entry point | |
| ``` | |
| ## 3D Model Generation | |
| ### Advanced Mode (TRELLIS) | |
| - High-quality textured 3D models | |
| - ~10-30 seconds generation time | |
| - Uses Microsoft's TRELLIS model | |
| - Optimized for AR applications | |
| ### Basic Mode (Shap-E) | |
| - Fast generation | |
| - ~5-10 seconds generation time | |
| - Uses OpenAI's Shap-E model | |
| - Basic geometry without textures | |
| ## Development | |
| To run locally: | |
| ```bash | |
| # Install dependencies | |
| pip install -r requirements.txt | |
| # Set environment variables | |
| export HF_TOKEN=your_token_here | |
| # Run the server | |
| python main.py | |
| ``` | |
| Visit `http://localhost:8000/docs` for API documentation. | |
| ## License | |
| MIT License - See LICENSE file for details | |
| ## Links | |
| - π [Project Repository](https://github.com/yourusername/prompt_ar) | |
| - π± [Flutter Frontend](https://github.com/yourusername/prompt_ar/tree/main/frontend_prompt_ar) | |
| - π [Full Documentation](https://github.com/yourusername/prompt_ar/blob/main/README.md) | |