Vnmrsharma commited on
Commit
17d201b
·
1 Parent(s): 7672657

Updated README.md

Browse files
Files changed (1) hide show
  1. README.md +116 -121
README.md CHANGED
@@ -1,12 +1,11 @@
1
- # 3DAI CORE API
2
 
3
- This repository contains a FastAPI-based proxy service that integrates:
4
 
5
- - **Meshy Image-to-3D API** (v1) to generate 3D models from images
6
- - **Meshy Text-to-3D API** (v2) to generate 3D models from text prompts
7
- - **OpenAI Chat Completion API** to reframe user text into ideal 3D prompts
8
-
9
- It also includes a simple `frontend.html` for manual testing of all endpoints.
10
 
11
  ---
12
 
@@ -16,12 +15,15 @@ It also includes a simple `frontend.html` for manual testing of all endpoints.
16
  - [Installation](#installation)
17
  - [Configuration](#configuration)
18
  - [Running Locally](#running-locally)
19
- - [Docker Deployment (Hugging Face Spaces)](#docker-deployment-hugging-face-spaces)
20
  - [API Endpoints](#api-endpoints)
 
 
 
 
 
 
21
  - [Health Check](#health-check)
22
- - [Image-to-3D](#image-to-3d)
23
- - [Text-to-3D](#text-to-3d)
24
- - [Frontend Testing UI](#frontend-testing-ui)
25
 
26
  ---
27
 
@@ -29,7 +31,8 @@ It also includes a simple `frontend.html` for manual testing of all endpoints.
29
 
30
  - Python 3.10+
31
  - `pip`
32
- - Docker (for containerized deployment)
 
33
 
34
  ---
35
 
@@ -37,10 +40,9 @@ It also includes a simple `frontend.html` for manual testing of all endpoints.
37
 
38
  ```bash
39
  git clone <your-repo-url>
40
- cd <repo-folder>
41
- python -m venv .venv # optional but recommended
42
- source .venv/bin/activate
43
- pip install --upgrade pip
44
  pip install -r requirements.txt
45
  ```
46
 
@@ -48,166 +50,159 @@ pip install -r requirements.txt
48
 
49
  ## Configuration
50
 
51
- Create a `.env` file in the project root with:
52
 
53
  ```ini
 
 
54
  MESHY_API_KEY=msy_<your_meshy_key>
55
  OPENAI_API_KEY=sk-<your_openai_key>
56
  ```
57
 
58
- - `MESHY_API_KEY`: your API key from Meshy ([Image-to-3D docs](https://docs.meshy.ai/en/api/image-to-3d), [Text-to-3D docs](https://docs.meshy.ai/en/api/text-to-3d)).
59
- - `OPENAI_API_KEY`: your OpenAI key for the Chat Completion endpoint.
60
-
61
  ---
62
 
63
  ## Running Locally
64
 
65
- Start the FastAPI server on port 8000:
66
-
67
  ```bash
68
- export MESHY_API_KEY=msy_...
69
- export OPENAI_API_KEY=sk-...
 
 
70
  python main.py
71
  ```
72
 
73
  - Swagger UI: http://127.0.0.1:8000/docs
74
- - ReDoc: http://127.0.0.1:8000/redoc
75
-
76
- ---
77
-
78
- ## Docker Deployment (Hugging Face Spaces)
79
-
80
- This service is containerized for HF Spaces on port **7860**.
81
-
82
- 1. Commit `Dockerfile` as-is.
83
- 2. Push to your HF Space repository.
84
- 3. In Spaces UI, set repository secrets:
85
- - `MESHY_API_KEY`
86
- - `OPENAI_API_KEY`
87
- 4. Space will auto-build and serve at `https://<your-space>.hf.space`.
88
 
89
  ---
90
 
91
  ## API Endpoints
92
 
93
- ### Health Check
94
 
95
- - **URL**: `/`
96
- - **Method**: `GET`
 
97
 
98
- **Response**
 
 
 
99
 
100
- ```json
101
- { "status": "ok" }
102
- ```
 
103
 
104
  ---
105
 
106
- ### Image-to-3D
107
 
108
- #### 1) Create Task
 
 
109
 
110
- - **URL**: `/req-img-to-3d`
111
- - **Method**: `POST`
112
- - **Auth**: `Authorization: Bearer <MESHY_API_KEY>`
113
- - **Content-Type**: `multipart/form-data`
114
- - **Body**:
115
- - `image` (file, `.jpg|.png`)
116
 
117
- **Response** (201)
118
 
119
- ```json
120
- { "result": "<task_id>" }
121
- ```
122
 
123
- #### 2) Retrieve Task
 
 
 
 
 
 
 
 
 
 
124
 
125
- - **URL**: `/req-result-img-to-3d/{task_id}`
126
- - **Method**: `GET`
127
- - **Auth**: `Authorization: Bearer <MESHY_API_KEY>`
128
 
129
- **Response** (200)
130
 
131
- ```json
132
- {
133
- "id": "...",
134
- "model_urls": { "glb": "...", "obj": "...", ... },
135
- "thumbnail_url": "...",
136
- "progress": 100,
137
- "status": "SUCCEEDED",
138
- ...
139
- }
140
- ```
141
 
142
- #### 3) List Tasks
 
 
143
 
144
- - **URL**: `/list-img-to-3d-req`
145
- - **Method**: `GET`
146
- - **Auth**: `Authorization: Bearer <MESHY_API_KEY>`
147
 
148
- **Response**
 
 
 
149
 
150
- An array or paginated list of Image-to-3D task objects (same schema as retrieve).
 
 
151
 
152
- ---
 
 
153
 
154
- ### Text-to-3D
155
 
156
- #### 4) Create Task
157
 
158
- - **URL**: `/req-text-to-3d`
159
- - **Method**: `POST`
160
- - **Auth**: `Authorization: Bearer <MESHY_API_KEY>`
161
- - **Content-Type**: `application/json`
162
- - **Body**:
163
  ```json
164
- { "text": "Describe your object..." }
 
 
 
 
 
 
 
 
 
 
 
165
  ```
166
 
167
- **Behavior**:
168
- 1. Sends user text to OpenAI Chat Completion to reframe prompt.
169
- 2. Calls Meshy `/openapi/v2/text-to-3d` with `{ mode: "preview", prompt: <reframed> }`.
170
-
171
- **Response** (200)
172
-
173
- ```json
174
- { "result": "<task_id>" }
175
- ```
176
-
177
- #### 5) Retrieve Task
178
 
179
- - **URL**: `/req-result-text-to-3d/{task_id}`
180
- - **Method**: `GET`
181
- - **Auth**: `Authorization: Bearer <MESHY_API_KEY>`
182
-
183
- **Response**
184
 
185
- Full Text-to-3D Task Object (schema matches Image-to-3D with additional fields: `prompt`, `mode`, `video_url`, etc.)
186
 
187
- #### 6) List Tasks
 
 
188
 
189
- - **URL**: `/list-text-to-3d-req`
190
- - **Method**: `GET`
191
- - **Auth**: `Authorization: Bearer <MESHY_API_KEY>`
192
 
193
- **Response**
194
 
195
- Array of Text-to-3D Task Objects.
 
196
 
197
  ---
198
 
199
- ## Frontend Testing UI
200
-
201
- Open `frontend.html` in a browser (or serve via simple HTTP). It provides sections for:
202
 
203
- 1. **Setting HF Spaces Token** (for private deployment)
204
- 2. **Image-to-3D** create, retrieve, list
205
- 3. **Text-to-3D** create, retrieve, list
 
206
 
207
- Enter your Hugging Face token in step 0, then test each API live.
208
  ---
209
 
210
- ## References
211
- - Meshy Image-to-3D API docs: https://docs.meshy.ai/en/api/image-to-3d
212
- - Meshy Text-to-3D API docs: https://docs.meshy.ai/en/api/text-to-3d
213
- - OpenAI Chat Completion API: https://platform.openai.com/docs/api-reference/chat/create
 
1
+ # 3D E-Commerce Backend API
2
 
3
+ This repository contains a FastAPI backend for a robust 3D model e-commerce platform. It integrates:
4
 
5
+ - **Supabase** for authentication, user, and credit management
6
+ - **Meshy** for 3D model generation (Image-to-3D, Text-to-3D)
7
+ - **OpenAI** for prompt reframing
8
+ - Endpoints for user onboarding, credit-guarded model generation, credit purchase, order placement, and user dashboard
 
9
 
10
  ---
11
 
 
15
  - [Installation](#installation)
16
  - [Configuration](#configuration)
17
  - [Running Locally](#running-locally)
 
18
  - [API Endpoints](#api-endpoints)
19
+ - [Authentication](#authentication)
20
+ - [User Onboarding & Profile](#user-onboarding--profile)
21
+ - [Credits](#credits)
22
+ - [3D Model Generation](#3d-model-generation)
23
+ - [Orders](#orders)
24
+ - [User Dashboard](#user-dashboard)
25
  - [Health Check](#health-check)
26
+ - [References](#references)
 
 
27
 
28
  ---
29
 
 
31
 
32
  - Python 3.10+
33
  - `pip`
34
+ - Supabase project (with tables: User, User_Credit_Account, Generated_Models, Model_Order_History, Credit_Order_History)
35
+ - Meshy and OpenAI API keys
36
 
37
  ---
38
 
 
40
 
41
  ```bash
42
  git clone <your-repo-url>
43
+ cd api-backend
44
+ python -m venv venv
45
+ source venv/bin/activate
 
46
  pip install -r requirements.txt
47
  ```
48
 
 
50
 
51
  ## Configuration
52
 
53
+ Create a `.env` file in the project root:
54
 
55
  ```ini
56
+ SUPABASE_URL=https://<your-supabase>.supabase.co
57
+ SUPABASE_KEY=<your-supabase-service-role-key>
58
  MESHY_API_KEY=msy_<your_meshy_key>
59
  OPENAI_API_KEY=sk-<your_openai_key>
60
  ```
61
 
 
 
 
62
  ---
63
 
64
  ## Running Locally
65
 
 
 
66
  ```bash
67
+ export SUPABASE_URL=...
68
+ export SUPABASE_KEY=...
69
+ export MESHY_API_KEY=...
70
+ export OPENAI_API_KEY=...
71
  python main.py
72
  ```
73
 
74
  - Swagger UI: http://127.0.0.1:8000/docs
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
 
76
  ---
77
 
78
  ## API Endpoints
79
 
80
+ ### Authentication
81
 
82
+ - **POST `/auth/signup`**
83
+ Sign up a new user.
84
+ **Body:** `{ "email": "...", "password": "..." }`
85
 
86
+ - **POST `/auth/signin`**
87
+ Sign in and receive JWT.
88
+ **Body:** `{ "email": "...", "password": "..." }`
89
+ **Response:** `{ "access_token": "...", "user": {...} }`
90
 
91
+ - **POST `/auth/complete-profile`**
92
+ Complete user profile and initialize credits.
93
+ **Auth:** Bearer token
94
+ **Body:** `{ "address": "...", "fullname": "...", "phone_number": "..." }`
95
 
96
  ---
97
 
98
+ ### User Onboarding & Profile
99
 
100
+ - **GET `/user/profile`**
101
+ Get current user's profile.
102
+ **Auth:** Bearer token
103
 
104
+ ---
 
 
 
 
 
105
 
106
+ ### Credits
107
 
108
+ - **GET `/user/credits`**
109
+ Get available generation credits.
110
+ **Auth:** Bearer token
111
 
112
+ - **POST `/credits/purchase`**
113
+ Purchase credits, updates credit account and order history.
114
+ **Auth:** Bearer token
115
+ **Body:**
116
+ ```json
117
+ {
118
+ "number_of_generations": 10,
119
+ "price": 19.99,
120
+ "transaction_id": "txn_123"
121
+ }
122
+ ```
123
 
124
+ ---
 
 
125
 
126
+ ### 3D Model Generation
127
 
128
+ - **POST `/req-img-to-3d`**
129
+ Generate 3D model from image (costs 1 credit).
130
+ **Auth:** Bearer token
131
+ **Body:** `multipart/form-data` with `image` file
 
 
 
 
 
 
132
 
133
+ - **GET `/req-result-img-to-3d/{task_id}`**
134
+ Get status/result of image-to-3D task.
135
+ **Auth:** Bearer token
136
 
137
+ - **GET `/list-img-to-3d-req`**
138
+ List all image-to-3D tasks for user.
139
+ **Auth:** Bearer token
140
 
141
+ - **POST `/req-text-to-3d`**
142
+ Generate 3D model from text (costs 1 credit, prompt reframed by OpenAI).
143
+ **Auth:** Bearer token
144
+ **Body:** `{ "text": "..." }`
145
 
146
+ - **GET `/req-result-text-to-3d/{task_id}`**
147
+ Get status/result of text-to-3D task.
148
+ **Auth:** Bearer token
149
 
150
+ - **GET `/list-text-to-3d-req`**
151
+ List all text-to-3D tasks for user.
152
+ **Auth:** Bearer token
153
 
154
+ ---
155
 
156
+ ### Orders
157
 
158
+ - **POST `/orders/place`**
159
+ Place an order for a 3D model print.
160
+ **Auth:** Bearer token
161
+ **Body:**
 
162
  ```json
163
+ {
164
+ "generated_model_id": "...",
165
+ "price": 29.99,
166
+ "packaging_price": 5.00,
167
+ "material_price": 10.00,
168
+ "delivery_address": "...",
169
+ "order_status": "pending",
170
+ "estimated_delivery_date": "2024-07-01",
171
+ "shipping_tracking_id": "track_123",
172
+ "payment_status": "paid",
173
+ "transaction_id": "txn_456"
174
+ }
175
  ```
176
 
177
+ - **GET `/user/orders`**
178
+ Get all orders for the current user.
179
+ **Auth:** Bearer token
 
 
 
 
 
 
 
 
180
 
181
+ ---
 
 
 
 
182
 
183
+ ### User Dashboard
184
 
185
+ - **GET `/user/models`**
186
+ Get all generated models for the current user.
187
+ **Auth:** Bearer token
188
 
189
+ ---
 
 
190
 
191
+ ### Health Check
192
 
193
+ - **GET `/`**
194
+ Returns `{ "status": "ok" }`
195
 
196
  ---
197
 
198
+ ## References
 
 
199
 
200
+ - [Supabase Docs](https://supabase.com/docs)
201
+ - [Meshy Image-to-3D API](https://docs.meshy.ai/en/api/image-to-3d)
202
+ - [Meshy Text-to-3D API](https://docs.meshy.ai/en/api/text-to-3d)
203
+ - [OpenAI Chat API](https://platform.openai.com/docs/api-reference/chat/create)
204
 
 
205
  ---
206
 
207
+ **Note:** All endpoints requiring authentication expect a Bearer token in the `Authorization` header.
208
+ **Credit-guarded endpoints** will decrement user credits atomically and return an error if insufficient.