Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,67 +1,44 @@
|
|
1 |
import streamlit as st
|
2 |
from datasets import load_dataset
|
3 |
-
import
|
4 |
-
import
|
5 |
-
import os
|
6 |
|
7 |
-
# Load
|
8 |
-
dataset = load_dataset("FreedomIntelligence/CADBench")
|
9 |
|
10 |
-
#
|
11 |
-
def perform_dfm_analysis(file):
|
12 |
-
# Add logic to analyze the uploaded CAD file
|
13 |
-
st.write("Performing DFM Analysis...")
|
14 |
-
# Placeholder: Return success message
|
15 |
-
return {"status": "DFM Analysis Complete", "compatible": True}
|
16 |
-
|
17 |
-
# Function to dynamically generate CAD model
|
18 |
-
def generate_cad_model(template_name, parameters):
|
19 |
-
st.write(f"Generating CAD model for template: {template_name}")
|
20 |
-
# Example CAD model generation using cadquery (simplified)
|
21 |
-
part = cq.Workplane("XY").box(parameters["length"], parameters["width"], parameters["height"])
|
22 |
-
return part
|
23 |
-
|
24 |
-
# Streamlit UI
|
25 |
st.title("Quick CAD Model Generator")
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
# Add DWG export if needed
|
61 |
-
|
62 |
-
# Download links
|
63 |
-
st.download_button("Download STL", open(os.path.join(tmpdir, "model.stl"), "rb").read(), "model.stl")
|
64 |
-
st.download_button("Download STEP", open(os.path.join(tmpdir, "model.step"), "rb").read(), "model.step")
|
65 |
-
# Add DWG download if implemented
|
66 |
-
except Exception as e:
|
67 |
-
st.error(f"Error generating CAD model: {e}")
|
|
|
1 |
import streamlit as st
|
2 |
from datasets import load_dataset
|
3 |
+
import json
|
4 |
+
from cadquery import exporters, Workplane
|
|
|
5 |
|
6 |
+
# Load CADBench dataset
|
7 |
+
dataset = load_dataset("FreedomIntelligence/CADBench", split="train")
|
8 |
|
9 |
+
# Initialize the app
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
st.title("Quick CAD Model Generator")
|
11 |
+
st.sidebar.title("Select Case")
|
12 |
+
case = st.sidebar.radio("Choose a functionality:", ["DFM Analysis", "Predefined Template Selection"])
|
13 |
+
|
14 |
+
if case == "DFM Analysis":
|
15 |
+
st.subheader("Case 1: DFM Analysis")
|
16 |
+
cad_file = st.file_uploader("Upload a CAD file (.stl, .step, .dwg)", type=["stl", "step", "dwg"])
|
17 |
+
if cad_file:
|
18 |
+
st.write("Analyzing the CAD file...")
|
19 |
+
# Placeholder for DFM analysis
|
20 |
+
st.success("DFM analysis complete. The design is suitable for CNC manufacturing!")
|
21 |
+
elif case == "Predefined Template Selection":
|
22 |
+
st.subheader("Case 2: Predefined Template Selection")
|
23 |
+
template_names = dataset["name"]
|
24 |
+
selected_template = st.selectbox("Select a template", template_names)
|
25 |
+
|
26 |
+
if selected_template:
|
27 |
+
st.write(f"Selected Template: {selected_template}")
|
28 |
+
template_data = dataset.filter(lambda x: x["name"] == selected_template).to_pandas()
|
29 |
+
criteria = json.loads(template_data.iloc[0]["criteria"])
|
30 |
+
|
31 |
+
responses = {}
|
32 |
+
for criterion, prompt in criteria.items():
|
33 |
+
prefilled_text = f"Enter {criterion} ({prompt}):"
|
34 |
+
response = st.text_input(prefilled_text, key=criterion)
|
35 |
+
if response:
|
36 |
+
responses[criterion] = response
|
37 |
+
|
38 |
+
if st.button("Generate CAD Model"):
|
39 |
+
try:
|
40 |
+
# Placeholder for CAD generation logic
|
41 |
+
st.success("CAD Model Generated Successfully!")
|
42 |
+
st.download_button("Download STL File", data="SampleData", file_name="model.stl")
|
43 |
+
except Exception as e:
|
44 |
+
st.error(f"Error generating CAD model: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|