Spaces:
Sleeping
Sleeping
File size: 7,127 Bytes
ee0bba4 cb429c5 ee0bba4 9f9a4dd ee0bba4 9557505 b3094b0 ee0bba4 cb429c5 9f9a4dd b3094b0 cb429c5 9557505 cb429c5 bafd3be cb429c5 bafd3be cb429c5 bafd3be cb429c5 b3094b0 9557505 cb429c5 ee0bba4 cb429c5 ee0bba4 cb429c5 9f9a4dd 9557505 b3094b0 cb429c5 ee0bba4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
import "reflect-metadata";
import express from "express";
import cors from "cors";
import dotenv from "dotenv";
import swaggerJsdoc from "swagger-jsdoc";
import swaggerUi from "swagger-ui-express";
import { AppDataSource } from "./utils/dataSource";
import authRoute from "./routes/auth";
import uploadRoute from "./routes/upload";
import suggestRoute from "./routes/suggest";
import wardrobeRoute from "./routes/wardrobe";
import profileRoute from "./routes/profile";
import avatarRoute from "./routes/avatar";
import chatRoute from "./routes/chat";
dotenv.config();
const app = express();
app.use(cors());
app.use(express.json({ limit: "10mb" }));
// Root endpoint with milestone information
app.get("/", (req, res) => {
res.json({
name: "StyleGPT Milestone 2",
version: "1.0.0",
description: "Visual Wardrobe Tagging & AI-Powered Outfit Suggestions",
milestone: 2,
features: [
"User Authentication (JWT-based)",
"Visual Wardrobe Management",
"AI-Powered Image Classification (Fashion-CLIP)",
"Smart Outfit Suggestions",
"User Profile Management"
],
endpoints: {
root: "/",
docs: "/docs",
health: "/health",
api: {
auth: "/api/auth",
profile: "/api/profile",
upload: "/api/upload",
suggest: "/api/suggest",
chat: "/api/chat",
wardrobe: "/api/wardrobe",
avatar: "/api/avatar"
}
},
technologies: [
"Node.js",
"TypeScript",
"Express.js",
"PostgreSQL",
"TypeORM",
"Hugging Face Fashion-CLIP",
"JWT Authentication"
]
});
});
// Swagger/OpenAPI configuration
const swaggerOptions: swaggerJsdoc.Options = {
definition: {
openapi: "3.0.0",
info: {
title: "StyleGPT Milestone 2 API",
version: "1.0.0",
description: "API documentation for StyleGPT Milestone 2 - Visual Wardrobe Tagging & AI-Powered Outfit Suggestions",
contact: {
name: "StyleGPT",
url: "https://huggingface.co/spaces/nexusbert/StyleGPT-milestone2"
}
},
servers: [
{
url: process.env.API_URL || `http://localhost:${process.env.PORT || 7860}`,
description: "API Server"
}
],
components: {
securitySchemes: {
bearerAuth: {
type: "http",
scheme: "bearer",
bearerFormat: "JWT"
}
},
schemas: {
User: {
type: "object",
properties: {
id: { type: "integer" },
name: { type: "string" },
email: { type: "string", format: "email" },
profilePicture: { type: "string", format: "uri", description: "Avatar render URL or base64 image" },
readyPlayerMeAvatarId: { type: "string", description: "Ready Player Me avatar ID" },
createdAt: { type: "string", format: "date-time" }
}
},
WardrobeItem: {
type: "object",
properties: {
id: { type: "integer" },
imageUrl: { type: "string", format: "uri" },
category: {
type: "string",
description: "Classification: shirt, pants, dress, jacket, shoes, sneakers, boots, watch, glasses, bag, hat, jewelry, accessories, etc."
},
style: {
type: "string",
enum: ["formal", "casual", "streetwear", "sportswear"],
description: "Style classification"
},
userId: { type: "integer" },
createdAt: { type: "string", format: "date-time" }
}
},
RegisterRequest: {
type: "object",
required: ["name", "email", "password"],
properties: {
name: { type: "string" },
email: { type: "string", format: "email" },
password: { type: "string", minLength: 6 }
}
},
LoginRequest: {
type: "object",
required: ["email", "password"],
properties: {
email: { type: "string", format: "email" },
password: { type: "string" }
}
},
AuthResponse: {
type: "object",
properties: {
success: { type: "boolean" },
user: { $ref: "#/components/schemas/User" },
token: { type: "string" },
error: { type: "string" }
}
},
UploadRequest: {
type: "object",
required: ["image"],
properties: {
image: {
type: "string",
format: "binary",
description: "Image file (JPEG, PNG, etc.)"
}
}
},
SuggestRequest: {
type: "object",
required: ["message"],
properties: {
message: { type: "string" },
session_id: { type: "string" }
}
}
}
},
tags: [
{ name: "Authentication", description: "User registration and login" },
{ name: "Profile", description: "User profile management" },
{ name: "Upload", description: "Wardrobe item upload and classification" },
{ name: "Suggest", description: "AI-powered outfit suggestions with wardrobe" },
{ name: "Chat", description: "Fashion chat without wardrobe" },
{ name: "Avatar", description: "Ready Player Me avatar management" },
{ name: "Health", description: "Health check endpoints" }
]
},
apis: ["./src/routes/*.ts", "./src/index.ts"]
};
const swaggerSpec = swaggerJsdoc(swaggerOptions);
// Swagger UI endpoint
app.use("/docs", swaggerUi.serve, swaggerUi.setup(swaggerSpec, {
customCss: ".swagger-ui .topbar { display: none }",
customSiteTitle: "StyleGPT Milestone 2 API Docs"
}));
// Swagger JSON endpoint
app.get("/docs.json", (req, res) => {
res.setHeader("Content-Type", "application/json");
res.send(swaggerSpec);
});
// Health check endpoint
/**
* @openapi
* /health:
* get:
* summary: Health check endpoint
* tags: [Health]
* responses:
* 200:
* description: Service is healthy
* content:
* application/json:
* schema:
* type: object
* properties:
* status:
* type: string
* example: healthy
* database:
* type: boolean
* example: true
*/
app.get("/health", (req, res) => {
res.json({ status: "healthy", database: AppDataSource.isInitialized });
});
app.use("/api/auth", authRoute);
app.use("/api/profile", profileRoute);
app.use("/api/upload", uploadRoute);
app.use("/api/suggest", suggestRoute);
app.use("/api/wardrobe", wardrobeRoute);
app.use("/api/avatar", avatarRoute);
app.use("/api/chat", chatRoute);
const PORT = process.env.PORT || 7860;
AppDataSource.initialize()
.then(() => {
console.log("✅ Database connected");
app.listen(PORT, () => console.log(`🧥 StyleGPT running on port ${PORT}`));
})
.catch((error) => console.error("❌ DB connection failed:", error));
|