This commit is contained in:
timothyafolami
2024-10-22 23:37:05 +01:00
parent 0680807bfd
commit 957bac887d
6 changed files with 1070 additions and 144 deletions
+36
View File
@@ -0,0 +1,36 @@
import sys, os
from fastapi import FastAPI, Form, Body
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import FileResponse, JSONResponse
from typing import List, Dict
from pydantic import BaseModel
from utils import product_categorizer
app = FastAPI()
# Define allowed origins for CORS
origins = [
"http://localhost:5300",
"http://localhost:3000",
# Add other allowed origins here
]
# Add CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
class ProductRequest(BaseModel):
products: List[str]
@app.post("/categorize-products/")
async def categorize_products(request: ProductRequest):
categorized_output = product_categorizer(request.products)
return JSONResponse(content={"categorized_products": categorized_output})