Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -52,3 +52,40 @@ if case == "Predefined Template":
|
|
| 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")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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")
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
if case == "DFM Analysis":
|
| 58 |
+
st.subheader("Case 1: DFM Analysis")
|
| 59 |
+
cad_file = st.file_uploader("Upload a CAD file (.stl, .step, .dwg)", type=["stl", "step", "dwg"])
|
| 60 |
+
if cad_file:
|
| 61 |
+
file_format = os.path.splitext(cad_file.name)[1][1:]
|
| 62 |
+
analysis_result = analyze_dfm(cad_file, file_format)
|
| 63 |
+
st.success(analysis_result)
|
| 64 |
+
|
| 65 |
+
elif case == "Predefined Template Selection":
|
| 66 |
+
st.subheader("Case 2: Predefined Template Selection")
|
| 67 |
+
template_names = dataset["name"]
|
| 68 |
+
selected_template = st.selectbox("Select a template", template_names)
|
| 69 |
+
|
| 70 |
+
if selected_template:
|
| 71 |
+
st.write(f"Selected Template: {selected_template}")
|
| 72 |
+
template_data = dataset.filter(lambda x: x["name"] == selected_template).to_pandas()
|
| 73 |
+
criteria = template_data.iloc[0]["criteria"] # Already a dict
|
| 74 |
+
|
| 75 |
+
responses = {}
|
| 76 |
+
for criterion, prompt in criteria.items():
|
| 77 |
+
prefilled_text = f"Enter {criterion} ({prompt}):"
|
| 78 |
+
response = st.text_input(prefilled_text, key=criterion)
|
| 79 |
+
if response:
|
| 80 |
+
responses[criterion] = response
|
| 81 |
+
|
| 82 |
+
if st.button("Generate CAD Model"):
|
| 83 |
+
try:
|
| 84 |
+
model = generate_cad_model(responses)
|
| 85 |
+
file_format = st.selectbox("Select file format for download", ["stl", "step", "dwg"])
|
| 86 |
+
file_path = export_cad(model, file_format)
|
| 87 |
+
st.success("CAD Model Generated Successfully!")
|
| 88 |
+
with open(file_path, "rb") as f:
|
| 89 |
+
st.download_button("Download CAD File", data=f.read(), file_name=f"model.{file_format}")
|
| 90 |
+
except Exception as e:
|
| 91 |
+
st.error(f"Error generating CAD model: {e}")
|