37 lines
887 B
Python
37 lines
887 B
Python
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})
|