kshdes37 commited on
Commit
a3ac0b3
Β·
verified Β·
1 Parent(s): ac551f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -9
app.py CHANGED
@@ -123,34 +123,67 @@ def generate_cad_from_text(text_prompt, max_length=512, temperature=0.8, top_p=0
123
  try:
124
  # Load model if not already loaded
125
  if not cad_fusion.model_loaded:
126
- cad_fusion.load_model()
 
 
 
 
 
 
 
 
127
 
128
  # Generate CAD sequence
129
  cad_sequence = cad_fusion.generate_cad_sequence(
130
- text_prompt,
131
  max_length=int(max_length),
132
  temperature=temperature,
133
  top_p=top_p
134
  )
135
 
 
 
 
136
  # Create visualization info
137
  viz_info = cad_fusion.render_cad_visualization(cad_sequence)
138
 
139
- # Format output
 
140
  output_text = f"""
 
 
 
 
141
  **Generated CAD Sequence:**
142
- {cad_sequence}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
 
144
- **Analysis:**
145
- - Operations detected: {viz_info.get('operations', 0)}
146
- - Sketches detected: {viz_info.get('sketches', 0)}
147
- - Status: {viz_info.get('status', 'Generated')}
148
  """
149
 
150
  return output_text, cad_sequence
151
 
152
  except Exception as e:
153
- error_msg = f"Error: {str(e)}"
154
  logger.error(error_msg)
155
  return error_msg, ""
156
 
 
123
  try:
124
  # Load model if not already loaded
125
  if not cad_fusion.model_loaded:
126
+ try:
127
+ cad_fusion.load_model()
128
+ except Exception as e:
129
+ error_msg = f"Failed to load CADFusion model: {str(e)}\n\nThis might be due to:\n- Model access restrictions\n- Insufficient resources\n- Network connectivity issues"
130
+ return error_msg, ""
131
+
132
+ # Validate input
133
+ if not text_prompt or text_prompt.strip() == "":
134
+ return "Please provide a description for the CAD model.", ""
135
 
136
  # Generate CAD sequence
137
  cad_sequence = cad_fusion.generate_cad_sequence(
138
+ text_prompt.strip(),
139
  max_length=int(max_length),
140
  temperature=temperature,
141
  top_p=top_p
142
  )
143
 
144
+ if not cad_sequence:
145
+ return "No CAD sequence was generated. Please try with a different prompt.", ""
146
+
147
  # Create visualization info
148
  viz_info = cad_fusion.render_cad_visualization(cad_sequence)
149
 
150
+ # Format detailed output
151
+ ops = viz_info.get('operations', {})
152
  output_text = f"""
153
+ ## 🎯 Generated CAD Model
154
+
155
+ **Input Description:** {text_prompt}
156
+
157
  **Generated CAD Sequence:**
158
+ ```
159
+ {cad_sequence[:500]}{'...' if len(cad_sequence) > 500 else ''}
160
+ ```
161
+
162
+ ## πŸ“Š Analysis:
163
+ - **Total Operations:** {viz_info.get('total_operations', 0)}
164
+ - **Complexity:** {viz_info.get('complexity', 'Unknown')}
165
+ - **Lines of Code:** {viz_info.get('line_count', 0)}
166
+
167
+ ### Operation Breakdown:
168
+ - **Sketches:** {ops.get('sketch', 0)}
169
+ - **Extrusions:** {ops.get('extrude', 0)}
170
+ - **Revolutions:** {ops.get('revolve', 0)}
171
+ - **Circles:** {ops.get('circle', 0)}
172
+ - **Rectangles:** {ops.get('rectangle', 0)}
173
+ - **Lines:** {ops.get('line', 0)}
174
+ - **Fillets:** {ops.get('fillet', 0)}
175
+ - **Chamfers:** {ops.get('chamfer', 0)}
176
+
177
+ **Status:** {viz_info.get('status', 'Generated successfully')}
178
 
179
+ ---
180
+ *Note: This is the parametric CAD sequence. For full 3D rendering, use CAD software that supports these operations.*
 
 
181
  """
182
 
183
  return output_text, cad_sequence
184
 
185
  except Exception as e:
186
+ error_msg = f"❌ Error generating CAD: {str(e)}"
187
  logger.error(error_msg)
188
  return error_msg, ""
189