File size: 1,710 Bytes
593dc08
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import gradio as gr

# Constants for resistivity (ohm·mm²/m)
RESISTIVITY = {
    "Copper": 0.0172,
    "Aluminum": 0.0282
}

def cable_sizing(load_kw, voltage, power_factor, length, drop_percent, material):
    try:
        # Step 1: Calculate current
        current = (load_kw * 1000) / (voltage * power_factor)
        
        # Step 2: Allowable voltage drop
        vd_allowed = (drop_percent / 100) * voltage
        
        # Step 3: Required cross-sectional area
        rho = RESISTIVITY[material]
        area = (2 * rho * length * current) / vd_allowed   # 2 for single-phase, use √3 for three-phase
        
        # Round to nearest standard cable size
        standard_sizes = [1.5, 2.5, 4, 6, 10, 16, 25, 35, 50, 70, 95, 120, 150, 185, 240]
        recommended_size = min([s for s in standard_sizes if s >= area], default=">240")
        
        return (
            f"Calculated Current: {current:.2f} A\n"
            f"Required Area: {area:.2f} mm²\n"
            f"Recommended Cable Size: {recommended_size} mm² ({material})"
        )
    except Exception as e:
        return f"Error: {e}"

# Gradio Interface
iface = gr.Interface(
    fn=cable_sizing,
    inputs=[
        gr.Number(label="Load (kW)"),
        gr.Number(label="Voltage (V)"),
        gr.Number(label="Power Factor (pf)", value=0.8),
        gr.Number(label="Cable Length (m)"),
        gr.Number(label="Allowable Voltage Drop (%)", value=3),
        gr.Radio(["Copper", "Aluminum"], label="Conductor Material", value="Copper")
    ],
    outputs="text",
    title="Cable Sizing Calculator ⚙️",
    description="Estimate suitable cable size based on load, voltage, and voltage drop limit."
)

iface.launch()