Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,27 +1,29 @@
|
|
| 1 |
-
import
|
|
|
|
|
|
|
| 2 |
from cad_model_generator import create_press_tool_model
|
| 3 |
-
from model_validation import validate_model_with_ansys
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
stl_file = create_press_tool_model(length, width, height)
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
|
|
|
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
iface = gr.Interface(
|
| 16 |
-
fn=generate_and_validate_model,
|
| 17 |
-
inputs=[
|
| 18 |
-
gr.Slider(minimum=10, maximum=500, label="Length (mm)"),
|
| 19 |
-
gr.Slider(minimum=10, maximum=500, label="Width (mm)"),
|
| 20 |
-
gr.Slider(minimum=5, maximum=100, label="Height (mm)"),
|
| 21 |
-
],
|
| 22 |
-
outputs="text",
|
| 23 |
-
title="Press Tool CAD Model Generator and Validator",
|
| 24 |
-
description="Generate 3D press tool CAD models and validate them using ANSYS"
|
| 25 |
-
)
|
| 26 |
|
| 27 |
-
iface.launch()
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
import os
|
| 4 |
from cad_model_generator import create_press_tool_model
|
|
|
|
| 5 |
|
| 6 |
+
# Initialize FastAPI app
|
| 7 |
+
app = FastAPI()
|
|
|
|
| 8 |
|
| 9 |
+
# Input model for the API endpoint
|
| 10 |
+
class ModelInput(BaseModel):
|
| 11 |
+
length: float
|
| 12 |
+
width: float
|
| 13 |
+
height: float
|
| 14 |
+
|
| 15 |
+
# Endpoint to generate the CAD model
|
| 16 |
+
@app.post("/generate-model/")
|
| 17 |
+
async def generate_model(model_input: ModelInput):
|
| 18 |
+
try:
|
| 19 |
+
# Generate the CAD model using FreeCAD
|
| 20 |
+
model_path = create_press_tool_model(model_input.length, model_input.width, model_input.height)
|
| 21 |
+
|
| 22 |
+
# Return the path or URL to the generated STL file
|
| 23 |
+
return {"model_url": model_path}
|
| 24 |
|
| 25 |
+
except Exception as e:
|
| 26 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 27 |
|
| 28 |
+
# To run the server with: uvicorn api:app --reload
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
|
|