File size: 825 Bytes
a321dde
 
 
d3d60ee
e847e43
a321dde
 
e847e43
a321dde
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e847e43
a321dde
 
d3d60ee
a321dde
d3d60ee
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
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