windamir123 commited on
Commit
593dc08
·
verified ·
1 Parent(s): 600ff3b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ # Constants for resistivity (ohm·mm²/m)
4
+ RESISTIVITY = {
5
+ "Copper": 0.0172,
6
+ "Aluminum": 0.0282
7
+ }
8
+
9
+ def cable_sizing(load_kw, voltage, power_factor, length, drop_percent, material):
10
+ try:
11
+ # Step 1: Calculate current
12
+ current = (load_kw * 1000) / (voltage * power_factor)
13
+
14
+ # Step 2: Allowable voltage drop
15
+ vd_allowed = (drop_percent / 100) * voltage
16
+
17
+ # Step 3: Required cross-sectional area
18
+ rho = RESISTIVITY[material]
19
+ area = (2 * rho * length * current) / vd_allowed # 2 for single-phase, use √3 for three-phase
20
+
21
+ # Round to nearest standard cable size
22
+ standard_sizes = [1.5, 2.5, 4, 6, 10, 16, 25, 35, 50, 70, 95, 120, 150, 185, 240]
23
+ recommended_size = min([s for s in standard_sizes if s >= area], default=">240")
24
+
25
+ return (
26
+ f"Calculated Current: {current:.2f} A\n"
27
+ f"Required Area: {area:.2f} mm²\n"
28
+ f"Recommended Cable Size: {recommended_size} mm² ({material})"
29
+ )
30
+ except Exception as e:
31
+ return f"Error: {e}"
32
+
33
+ # Gradio Interface
34
+ iface = gr.Interface(
35
+ fn=cable_sizing,
36
+ inputs=[
37
+ gr.Number(label="Load (kW)"),
38
+ gr.Number(label="Voltage (V)"),
39
+ gr.Number(label="Power Factor (pf)", value=0.8),
40
+ gr.Number(label="Cable Length (m)"),
41
+ gr.Number(label="Allowable Voltage Drop (%)", value=3),
42
+ gr.Radio(["Copper", "Aluminum"], label="Conductor Material", value="Copper")
43
+ ],
44
+ outputs="text",
45
+ title="Cable Sizing Calculator ⚙️",
46
+ description="Estimate suitable cable size based on load, voltage, and voltage drop limit."
47
+ )
48
+
49
+ iface.launch()