Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,74 +1,53 @@
|
|
| 1 |
-
import os
|
| 2 |
import streamlit as st
|
| 3 |
-
from groq import Groq
|
| 4 |
-
from pyvista import read
|
| 5 |
-
from cadquery import exporters
|
| 6 |
from datasets import load_dataset
|
| 7 |
-
import
|
| 8 |
|
| 9 |
# Initialize Groq API client
|
| 10 |
client = Groq(api_key="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")
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
-
file_path = f"uploaded_{uploaded_file.name}"
|
| 15 |
-
with open(file_path, "wb") as f:
|
| 16 |
-
f.write(uploaded_file.getbuffer())
|
| 17 |
-
st.write(f"File saved as: {file_path}")
|
| 18 |
-
return file_path
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
# Placeholder for actual DFM analysis logic using LLMs
|
| 23 |
-
result = {"CNC_Machinable": True, "Complexity_Score": 0.75} # Mock result
|
| 24 |
-
return result
|
| 25 |
|
| 26 |
-
#
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
try:
|
| 30 |
-
dataset = load_dataset("FreedomIntelligence/CADBench", split="train")
|
| 31 |
-
templates = [entry["name"] for entry in dataset if "name" in entry]
|
| 32 |
-
return templates
|
| 33 |
-
except Exception as e:
|
| 34 |
-
st.error(f"Error loading dataset: {e}")
|
| 35 |
-
return []
|
| 36 |
|
| 37 |
-
|
| 38 |
-
st.
|
| 39 |
-
|
| 40 |
-
generated_file = f"{template_name}_output.step"
|
| 41 |
-
return generated_file
|
| 42 |
|
| 43 |
-
|
| 44 |
-
st.
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
-
if
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
if st.button("Analyze for CNC"):
|
| 53 |
-
try:
|
| 54 |
-
dfm_result = perform_dfm_analysis(file_path)
|
| 55 |
-
st.success("DFM Analysis Completed!")
|
| 56 |
-
st.json(dfm_result)
|
| 57 |
-
except Exception as e:
|
| 58 |
-
st.error(f"Error in DFM Analysis: {e}")
|
| 59 |
|
| 60 |
-
|
| 61 |
-
templates = get_templates_from_dataset()
|
| 62 |
-
if templates:
|
| 63 |
-
template_name = st.selectbox("Choose a Template", templates)
|
| 64 |
-
parameters = st.text_area("Enter Parameters (JSON format)", placeholder='{"length": 100, "width": 50}')
|
| 65 |
-
if st.button("Generate CAD"):
|
| 66 |
-
try:
|
| 67 |
-
params = json.loads(parameters) if parameters else {}
|
| 68 |
-
generated_file = generate_cad_from_template(template_name, params)
|
| 69 |
-
st.success("CAD Model Generated!")
|
| 70 |
-
st.download_button("Download CAD File", open(generated_file, "rb"), file_name=generated_file)
|
| 71 |
-
except json.JSONDecodeError:
|
| 72 |
-
st.error("Invalid JSON format for parameters.")
|
| 73 |
-
except Exception as e:
|
| 74 |
-
st.error(f"Error in CAD Generation: {e}")
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
| 2 |
from datasets import load_dataset
|
| 3 |
+
from groq import Groq
|
| 4 |
|
| 5 |
# Initialize Groq API client
|
| 6 |
client = Groq(api_key="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")
|
| 7 |
|
| 8 |
+
# Load dataset
|
| 9 |
+
st.session_state.setdefault("cadbench_dataset", load_dataset("FreedomIntelligence/CADBench"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
# Page Title
|
| 12 |
+
st.title("Quick CAD Model Generator")
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
# Sidebar Options
|
| 15 |
+
st.sidebar.title("Input Options")
|
| 16 |
+
input_option = st.sidebar.radio("Select an Option", ["Upload CAD File for DFM", "Select Predefined Template"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
if input_option == "Upload CAD File for DFM":
|
| 19 |
+
st.header("Upload a CAD File for DFM Analysis")
|
| 20 |
+
uploaded_file = st.file_uploader("Upload your CAD file (any format)", type=["step", "iges", "dwg", "dxf", "scad"])
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
if uploaded_file and st.button("Run DFM Analysis"):
|
| 23 |
+
st.write("**Performing Design for Manufacturing (DFM) Analysis...**")
|
| 24 |
+
# Placeholder for processing and results
|
| 25 |
+
st.info("The DFM analysis will check if the design is manufacturable on a CNC machine.")
|
| 26 |
+
# Future implementation: Integrate CAD file feature extraction, feature encoding, and analysis.
|
| 27 |
+
|
| 28 |
+
elif input_option == "Select Predefined Template":
|
| 29 |
+
st.header("Select Predefined Template")
|
| 30 |
+
dataset = st.session_state["cadbench_dataset"]
|
| 31 |
+
|
| 32 |
+
# Get template names from the dataset
|
| 33 |
+
template_names = dataset["train"]["template_name"]
|
| 34 |
+
selected_template = st.selectbox("Choose a Template", template_names)
|
| 35 |
+
|
| 36 |
+
if selected_template:
|
| 37 |
+
st.subheader(f"Selected Template: {selected_template}")
|
| 38 |
+
|
| 39 |
+
# Retrieve template parameters
|
| 40 |
+
template_parameters = dataset["train"]["parameters"][template_names.index(selected_template)]
|
| 41 |
+
|
| 42 |
+
user_inputs = {}
|
| 43 |
+
for param_name, param_details in template_parameters.items():
|
| 44 |
+
st.write(f"Parameter: **{param_name}**")
|
| 45 |
+
param_value = st.text_input(f"Enter value for {param_name} (Expected type: {param_details['type']})")
|
| 46 |
+
user_inputs[param_name] = param_value
|
| 47 |
|
| 48 |
+
if st.button("Generate CAD Model"):
|
| 49 |
+
st.write("**Generating CAD Model based on provided parameters...**")
|
| 50 |
+
# Placeholder for CAD generation process
|
| 51 |
+
st.info("The CAD model will be generated and made available for download.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
+
# Future implementation: Generate and preview CAD models, allow downloads in required formats.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|