Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,7 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from datasets import load_dataset
|
| 3 |
-
from
|
| 4 |
-
import
|
| 5 |
-
|
| 6 |
-
# Initialize Groq API client
|
| 7 |
-
client = Groq(api_key="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")
|
| 8 |
-
|
| 9 |
-
# Load dataset
|
| 10 |
-
@st.cache_data
|
| 11 |
-
def load_cadbench_dataset():
|
| 12 |
-
return load_dataset("FreedomIntelligence/CADBench")
|
| 13 |
-
|
| 14 |
-
dataset = load_cadbench_dataset()
|
| 15 |
|
| 16 |
# Page Title
|
| 17 |
st.title("Quick CAD Model Generator")
|
|
@@ -20,31 +10,27 @@ st.title("Quick CAD Model Generator")
|
|
| 20 |
st.sidebar.title("Input Options")
|
| 21 |
input_option = st.sidebar.radio("Select an Option", ["Upload CAD File for DFM", "Select Predefined Template"])
|
| 22 |
|
| 23 |
-
# Case 1: Upload CAD File for DFM Analysis
|
| 24 |
-
if input_option == "Upload CAD File for DFM":
|
| 25 |
st.header("Upload a CAD File for DFM Analysis")
|
| 26 |
uploaded_file = st.file_uploader(
|
| 27 |
-
"Upload your CAD file (.stl, .step, .iges, .dwg, .dxf, .scad)",
|
| 28 |
type=["stl", "step", "iges", "dwg", "dxf", "scad"]
|
| 29 |
)
|
| 30 |
|
| 31 |
-
if uploaded_file and st.button("Run DFM Analysis"):
|
| 32 |
-
st.write("**
|
| 33 |
-
|
| 34 |
-
st.write(f"Uploaded file format: **{file_extension}**")
|
| 35 |
-
|
| 36 |
-
# Placeholder for DFM processing
|
| 37 |
-
if file_extension in [".stl", ".step", ".iges", ".dwg", ".dxf", ".scad"]:
|
| 38 |
-
st.success("File accepted for DFM analysis. Processing...")
|
| 39 |
-
else:
|
| 40 |
-
st.error("Unsupported file format for DFM analysis.")
|
| 41 |
|
| 42 |
# Case 2: Select Predefined Template
|
| 43 |
elif input_option == "Select Predefined Template":
|
| 44 |
st.header("Select Predefined Template")
|
| 45 |
|
|
|
|
|
|
|
|
|
|
| 46 |
# Use 'name' column instead of 'template_name' as per dataset structure
|
| 47 |
-
template_names = dataset["train"]["name"]
|
| 48 |
selected_template = st.selectbox("Choose a Template", template_names)
|
| 49 |
|
| 50 |
if selected_template:
|
|
@@ -59,7 +45,7 @@ elif input_option == "Select Predefined Template":
|
|
| 59 |
st.write("**Instruction:**", template_instruction)
|
| 60 |
st.write("**Criteria:**", template_criteria)
|
| 61 |
|
| 62 |
-
# Input parameters for the template
|
| 63 |
st.subheader("Provide Required Parameters")
|
| 64 |
user_inputs = {}
|
| 65 |
for criterion in template_criteria.split(";"):
|
|
@@ -69,6 +55,26 @@ elif input_option == "Select Predefined Template":
|
|
| 69 |
|
| 70 |
if st.button("Generate CAD Model"):
|
| 71 |
st.write("**Generating CAD Model based on provided parameters...**")
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from datasets import load_dataset
|
| 3 |
+
from pymesh import Mesh # For 3D mesh generation
|
| 4 |
+
import pyvista as pv # For 3D mesh visualization
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
# Page Title
|
| 7 |
st.title("Quick CAD Model Generator")
|
|
|
|
| 10 |
st.sidebar.title("Input Options")
|
| 11 |
input_option = st.sidebar.radio("Select an Option", ["Upload CAD File for DFM", "Select Predefined Template"])
|
| 12 |
|
| 13 |
+
# Case 1: Upload CAD File for DFM Analysis (placeholder)
|
| 14 |
+
if input_option == "Upload CAD File for DFM Analysis":
|
| 15 |
st.header("Upload a CAD File for DFM Analysis")
|
| 16 |
uploaded_file = st.file_uploader(
|
| 17 |
+
"Upload your CAD file (.stl, .step, .iges, .dwg, .dxf, .scad)",
|
| 18 |
type=["stl", "step", "iges", "dwg", "dxf", "scad"]
|
| 19 |
)
|
| 20 |
|
| 21 |
+
if uploaded_file and st.button("Run DFM Analysis (Placeholder)"):
|
| 22 |
+
st.write("**DFM analysis functionality is currently under development.**")
|
| 23 |
+
st.write(f"Uploaded file format: **{os.path.splitext(uploaded_file.name)[-1].lower()}**")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
# Case 2: Select Predefined Template
|
| 26 |
elif input_option == "Select Predefined Template":
|
| 27 |
st.header("Select Predefined Template")
|
| 28 |
|
| 29 |
+
# Load dataset
|
| 30 |
+
dataset = load_dataset("FreedomIntelligence/CADBench")
|
| 31 |
+
|
| 32 |
# Use 'name' column instead of 'template_name' as per dataset structure
|
| 33 |
+
template_names = dataset["train"]["name"].tolist()
|
| 34 |
selected_template = st.selectbox("Choose a Template", template_names)
|
| 35 |
|
| 36 |
if selected_template:
|
|
|
|
| 45 |
st.write("**Instruction:**", template_instruction)
|
| 46 |
st.write("**Criteria:**", template_criteria)
|
| 47 |
|
| 48 |
+
# Input parameters for the template (extract parameters from criteria)
|
| 49 |
st.subheader("Provide Required Parameters")
|
| 50 |
user_inputs = {}
|
| 51 |
for criterion in template_criteria.split(";"):
|
|
|
|
| 55 |
|
| 56 |
if st.button("Generate CAD Model"):
|
| 57 |
st.write("**Generating CAD Model based on provided parameters...**")
|
| 58 |
+
|
| 59 |
+
# Example using PyMesh for generating a simple cube
|
| 60 |
+
if selected_template == "Cube": # Replace with your template logic
|
| 61 |
+
if "width" in user_inputs and "height" in user_inputs and "depth" in user_inputs:
|
| 62 |
+
width = float(user_inputs["width"])
|
| 63 |
+
height = float(user_inputs["height"])
|
| 64 |
+
depth = float(user_inputs["depth"])
|
| 65 |
+
cube_vertices = [
|
| 66 |
+
[0, 0, 0], [width, 0, 0], [width, height, 0], [0, height, 0],
|
| 67 |
+
[0, 0, depth], [width, 0, depth], [width, height, depth], [0, height, depth]
|
| 68 |
+
]
|
| 69 |
+
cube_faces = [
|
| 70 |
+
[0, 1, 2, 3], [4, 5, 6, 7],
|
| 71 |
+
[0, 4, 5, 1], [1, 5, 6, 2],
|
| 72 |
+
[2, 6, 7, 3], [0, 3, 7, 4]
|
| 73 |
+
]
|
| 74 |
+
cube_mesh = Mesh(vertices=cube_vertices, faces=cube_faces)
|
| 75 |
+
|
| 76 |
+
# **Visualization using PyVista**
|
| 77 |
+
py_mesh = pv.wrap(cube_mesh) # Convert PyMesh to PyVista mesh
|
| 78 |
+
plotter = pv.Plotter()
|
| 79 |
+
plotter.add_mesh(py_mesh)
|
| 80 |
+
plotter.show(jupyter_backend='static')
|