Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,80 +1,54 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
from datasets import load_dataset
|
3 |
import json
|
4 |
-
from cadquery import Workplane, exporters
|
5 |
-
import tempfile
|
6 |
-
import os
|
7 |
|
8 |
-
# Load
|
9 |
-
dataset = load_dataset("FreedomIntelligence/CADBench"
|
10 |
|
11 |
-
#
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
|
17 |
-
""
|
18 |
-
try:
|
19 |
-
st.write(f"Analyzing {file_format} file...")
|
20 |
-
# Placeholder: Replace with real DFM logic
|
21 |
-
return "The design is suitable for CNC manufacturing!"
|
22 |
-
except Exception as e:
|
23 |
-
return f"Error analyzing file: {e}"
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
try:
|
28 |
-
# Placeholder: CAD generation logic
|
29 |
-
result = Workplane("XY").box(1, 1, 1) # Example model
|
30 |
-
return result
|
31 |
-
except Exception as e:
|
32 |
-
raise RuntimeError(f"Error generating CAD model: {e}")
|
33 |
|
34 |
-
|
35 |
-
"""Export CAD model to selected format."""
|
36 |
-
with tempfile.NamedTemporaryFile(delete=False, suffix=f".{file_format}") as temp_file:
|
37 |
-
if file_format == "stl":
|
38 |
-
exporters.exportShape(model, exporters.ExportTypes.STL, temp_file.name)
|
39 |
-
elif file_format == "step":
|
40 |
-
exporters.exportShape(model, exporters.ExportTypes.STEP, temp_file.name)
|
41 |
-
elif file_format == "dwg":
|
42 |
-
# Placeholder: Add DWG export logic
|
43 |
-
pass
|
44 |
-
return temp_file.name
|
45 |
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
if cad_file:
|
50 |
-
file_format = os.path.splitext(cad_file.name)[1][1:]
|
51 |
-
analysis_result = analyze_dfm(cad_file, file_format)
|
52 |
-
st.success(analysis_result)
|
53 |
|
54 |
-
|
55 |
-
st.subheader("
|
56 |
-
template_names = dataset["name"]
|
57 |
-
selected_template = st.selectbox("Select a
|
58 |
|
|
|
59 |
if selected_template:
|
60 |
-
|
61 |
-
|
62 |
-
criteria = template_data.iloc[0]["criteria"] # Already a dict
|
63 |
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
if response:
|
69 |
-
responses[criterion] = response
|
70 |
|
71 |
if st.button("Generate CAD Model"):
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
except Exception as e:
|
80 |
-
st.error(f"Error generating CAD model: {e}")
|
|
|
1 |
import streamlit as st
|
2 |
+
import cadquery as cq
|
3 |
from datasets import load_dataset
|
4 |
import json
|
|
|
|
|
|
|
5 |
|
6 |
+
# Load dataset
|
7 |
+
dataset = load_dataset("FreedomIntelligence/CADBench")
|
8 |
|
9 |
+
# Helper to generate Cargo Crane CAD
|
10 |
+
def generate_cargo_crane(inputs):
|
11 |
+
# Parse inputs
|
12 |
+
boom_length = inputs.get("Boom Length (in mm)", 3000)
|
13 |
+
lifting_capacity = inputs.get("Lifting Capacity (in tons)", 10)
|
14 |
+
base_height = inputs.get("Base Height (in mm)", 500)
|
15 |
+
material_type = inputs.get("Material Type", "Steel")
|
16 |
+
|
17 |
+
# Create base
|
18 |
+
base = cq.Workplane("XY").box(200, 200, base_height)
|
19 |
|
20 |
+
# Create boom
|
21 |
+
boom = cq.Workplane("XY").box(50, boom_length, 50).translate((0, base_height, 0))
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
+
# Combine parts
|
24 |
+
crane = base.union(boom)
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
+
return crane
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
+
# Streamlit Interface
|
29 |
+
st.title("Quick CAD Model Generator")
|
30 |
+
case = st.radio("Select Case", ["DFM Analysis", "Predefined Template"])
|
|
|
|
|
|
|
|
|
31 |
|
32 |
+
if case == "Predefined Template":
|
33 |
+
st.subheader("Predefined Template Selection")
|
34 |
+
template_names = dataset["train"]["name"]
|
35 |
+
selected_template = st.selectbox("Select a Template", template_names)
|
36 |
|
37 |
+
# Retrieve criteria
|
38 |
if selected_template:
|
39 |
+
template_data = dataset["train"].filter(lambda x: x["name"] == selected_template).to_pandas()
|
40 |
+
criteria = json.loads(template_data.iloc[0]["criteria"])
|
|
|
41 |
|
42 |
+
# Dynamic input collection
|
43 |
+
inputs = {}
|
44 |
+
for question in criteria.keys():
|
45 |
+
inputs[question] = st.text_input(f"{question}: ")
|
|
|
|
|
46 |
|
47 |
if st.button("Generate CAD Model"):
|
48 |
+
if selected_template == "Cargo Crane":
|
49 |
+
cad_model = generate_cargo_crane(inputs)
|
50 |
+
st.success("CAD Model Generated!")
|
51 |
+
cq.exporters.export(cad_model, "cargo_crane.step")
|
52 |
+
cq.exporters.export(cad_model, "cargo_crane.stl")
|
53 |
+
st.download_button("Download STEP File", open("cargo_crane.step", "rb").read(), "cargo_crane.step")
|
54 |
+
st.download_button("Download STL File", open("cargo_crane.stl", "rb").read(), "cargo_crane.stl")
|
|
|
|