Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,54 +1,27 @@
|
|
| 1 |
-
import
|
| 2 |
-
import
|
| 3 |
-
import
|
| 4 |
-
from FreeCAD import Base
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
|
| 11 |
-
"Authorization": "Bearer your_huggingface_api_token"
|
| 12 |
-
}
|
| 13 |
-
|
| 14 |
-
# Function to query the Hugging Face model
|
| 15 |
-
def query_huggingface_model(inputs):
|
| 16 |
-
# Send data to Hugging Face API and get the response
|
| 17 |
-
response = requests.post(huggingface_api_url, headers=headers, json=inputs)
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
optimized_radius = predicted_parameters.get("radius", 10) # Default to 10 if not returned
|
| 36 |
-
optimized_height = predicted_parameters.get("height", 50) # Default to 50 if not returned
|
| 37 |
-
|
| 38 |
-
# Create a new FreeCAD document
|
| 39 |
-
doc = FreeCAD.newDocument()
|
| 40 |
-
|
| 41 |
-
# Create a cylinder using the predicted dimensions
|
| 42 |
-
cylinder = Part.makeCylinder(optimized_radius, optimized_height)
|
| 43 |
-
|
| 44 |
-
# Add the cylinder to the document
|
| 45 |
-
part_object = doc.addObject("Part::Feature", "OptimizedCylinder")
|
| 46 |
-
part_object.Shape = cylinder
|
| 47 |
-
|
| 48 |
-
# Recompute the document to apply the changes
|
| 49 |
-
doc.recompute()
|
| 50 |
-
|
| 51 |
-
# Optionally save the document
|
| 52 |
-
doc.saveAs("optimized_cylinder.FCStd")
|
| 53 |
-
|
| 54 |
-
print(f"Created optimized cylinder with radius={optimized_radius} and height={optimized_height}")
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from cad_model_generator import create_press_tool_model
|
| 3 |
+
from model_validation import validate_model_with_ansys
|
|
|
|
| 4 |
|
| 5 |
+
def generate_and_validate_model(length, width, height):
|
| 6 |
+
# Generate CAD model
|
| 7 |
+
stl_file = create_press_tool_model(length, width, height)
|
| 8 |
|
| 9 |
+
# Validate the model with ANSYS
|
| 10 |
+
validation_results = validate_model_with_ansys(stl_file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
return validation_results
|
| 13 |
+
|
| 14 |
+
# Create Gradio interface
|
| 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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|