karthikmn commited on
Commit
d3d60ee
·
verified ·
1 Parent(s): 369cacc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -51
app.py CHANGED
@@ -1,54 +1,27 @@
1
- import requests
2
- import FreeCAD
3
- import Part
4
- from FreeCAD import Base
5
 
6
- # Hugging Face API URL (replace with your own model's endpoint)
7
- huggingface_api_url = "https://api-inference.huggingface.co/models/your-username/your-model-name"
 
8
 
9
- # Set the authorization token (replace with your Hugging Face API token)
10
- headers = {
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
- if response.status_code == 200:
20
- return response.json() # Return the predictions
21
- else:
22
- raise Exception(f"Error querying model: {response.text}")
23
-
24
- # Example design parameters (e.g., dimensions of the part)
25
- design_parameters = {
26
- "material": "steel",
27
- "load": 1000, # Load applied to the part (in N)
28
- "shape": "cylinder" # Shape of the part
29
- }
30
-
31
- # Query the Hugging Face model for optimized dimensions
32
- predicted_parameters = query_huggingface_model(design_parameters)
33
-
34
- # Extract the predicted parameters from the model response
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()