from fastapi import FastAPI, HTTPException from pydantic import BaseModel import os from cad_model_generator import create_press_tool_model # Initialize FastAPI app app = FastAPI() # Input model for the API endpoint class ModelInput(BaseModel): length: float width: float height: float # Endpoint to generate the CAD model @app.post("/generate-model/") async def generate_model(model_input: ModelInput): try: # Generate the CAD model using FreeCAD model_path = create_press_tool_model(model_input.length, model_input.width, model_input.height) # Return the path or URL to the generated STL file return {"model_url": model_path} except Exception as e: raise HTTPException(status_code=500, detail=str(e)) # To run the server with: uvicorn api:app --reload