Spaces:
Runtime error
Runtime error
File size: 1,470 Bytes
112b6aa |
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
from fastapi import FastAPI, File, UploadFile
import shutil
import os
from utils.cad_utils import convert_cad_to_step
from utils.ansys_utils import run_simulation
from utils.gcode_utils import generate_gcode
app = FastAPI()
# Define a temporary directory to save files
TEMP_DIR = "/tmp/cad_files"
os.makedirs(TEMP_DIR, exist_ok=True)
@app.post("/automate_workflow/")
async def automate_workflow(cad_file: UploadFile = File(...)):
"""
Automates the workflow:
1. Convert CAD file to STEP format.
2. Run simulation in ANSYS.
3. Generate G-Code for CNC.
"""
# Save uploaded CAD file to temporary directory
file_location = os.path.join(TEMP_DIR, cad_file.filename)
with open(file_location, "wb") as f:
shutil.copyfileobj(cad_file.file, f)
# Step 1: Convert CAD to STEP format
try:
step_file = convert_cad_to_step(file_location)
except Exception as e:
return {"error": f"Error converting CAD to STEP: {str(e)}"}
# Step 2: Run simulation in ANSYS
try:
simulation_results = run_simulation(step_file)
except Exception as e:
return {"error": f"Error running ANSYS simulation: {str(e)}"}
# Step 3: Generate G-Code for CNC
try:
gcode_file = generate_gcode(step_file)
except Exception as e:
return {"error": f"Error generating G-Code: {str(e)}"}
return {
"simulation_results": simulation_results,
"gcode_file": gcode_file
}
|