SissiFeng commited on
Commit
c131d7d
·
verified ·
1 Parent(s): 05c1555

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -19
app.py CHANGED
@@ -49,12 +49,14 @@ workflow_context = {
49
 
50
  # Optimized parameters for HF Spaces
51
  HF_OPTIMIZED_PARAMS = {
52
- "iters": 20, # Reduced from 50
53
- "complexity": 8, # Reduced from 12
54
- "generations": 15, # Reduced from 30
55
- "population_size": 50, # Reduced from 100
56
- "test_set_frac": 0.2, # Increased for faster validation
57
- "random_state": 42
 
 
58
  }
59
 
60
  def parse_workflow_params(request: gr.Request) -> Dict[str, Any]:
@@ -223,20 +225,23 @@ def analyze_eis_optimized(
223
  if progress_callback:
224
  progress_callback(0.4, "Detecting circuit model...")
225
 
226
- # Use simpler approach for HF
227
- circuits = ae.core.generate_equivalent_circuits(
228
- Z,
229
- freq,
230
  iters=params.get("iters", 20),
231
  complexity=params.get("complexity", 8),
232
  generations=params.get("generations", 15),
233
  population_size=params.get("population_size", 50),
234
- test_set_frac=params.get("test_set_frac", 0.2),
235
- random_state=params.get("random_state", 42)
 
 
236
  )
237
 
238
- if circuits and len(circuits) > 0:
239
- circuit_str = circuits[0] # Take the best circuit
 
240
  else:
241
  circuit_str = "R0-[R1,C1]" # Fallback simple circuit
242
  else:
@@ -456,11 +461,12 @@ def create_interface():
456
 
457
  with gr.Row():
458
  gr.Markdown("""
459
- **Optimization Settings (when enabled):**
460
- - Reduced iterations: 20 (vs 50)
461
- - Lower complexity: 8 (vs 12)
462
- - Smaller population: 50 (vs 100)
463
- - Faster validation: 20% test set
 
464
  """)
465
 
466
  # Results Tab
 
49
 
50
  # Optimized parameters for HF Spaces
51
  HF_OPTIMIZED_PARAMS = {
52
+ "iters": 30, # Increased for better circuit detection
53
+ "complexity": 10, # Increased for better circuit detection
54
+ "generations": 20, # Increased for better circuit detection
55
+ "population_size": 50, # Keep moderate for memory
56
+ "tol": 1e-3, # Tighter tolerance for better fits
57
+ "parallel": True, # Enable parallel processing
58
+ "terminals": "RLP", # R: resistor, L: inductor, P: constant-phase element
59
+ "seed": 42 # Random seed for reproducibility
60
  }
61
 
62
  def parse_workflow_params(request: gr.Request) -> Dict[str, Any]:
 
225
  if progress_callback:
226
  progress_callback(0.4, "Detecting circuit model...")
227
 
228
+ # Use simpler approach for HF - corrected parameter order and names
229
+ circuits_df = ae.core.generate_equivalent_circuits(
230
+ freq, # Frequency array (correct order)
231
+ Z, # Impedance array (correct order)
232
  iters=params.get("iters", 20),
233
  complexity=params.get("complexity", 8),
234
  generations=params.get("generations", 15),
235
  population_size=params.get("population_size", 50),
236
+ tol=params.get("tol", 1e-2),
237
+ parallel=params.get("parallel", True),
238
+ terminals=params.get("terminals", "RLP"),
239
+ seed=params.get("seed", 42)
240
  )
241
 
242
+ if circuits_df is not None and len(circuits_df) > 0:
243
+ # Extract the best circuit string from the DataFrame
244
+ circuit_str = circuits_df.iloc[0]['circuitstring'] # Take the best circuit
245
  else:
246
  circuit_str = "R0-[R1,C1]" # Fallback simple circuit
247
  else:
 
461
 
462
  with gr.Row():
463
  gr.Markdown("""
464
+ **HF-Optimized Settings (when enabled):**
465
+ - Circuit iterations: 30 (balanced performance/accuracy)
466
+ - Complexity limit: 10 (prevents overfitting)
467
+ - Population size: 50 (memory efficient)
468
+ - Tolerance: 1e-3 (good fit quality)
469
+ - Components: R (resistors), L (inductors), P (CPE)
470
  """)
471
 
472
  # Results Tab