AR1769 commited on
Commit
deb842f
·
verified ·
1 Parent(s): b4b41b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -51
app.py CHANGED
@@ -1,54 +1,31 @@
1
-
2
- # Import necessary libraries
3
  import gradio as gr
4
 
5
- # Function to calculate load distribution
6
- def load_calculation(load_rating, num_of_loads, voltage, load_type):
7
- # Constants
8
- safety_factor = 1.25 # 25% safety margin
9
- cable_size_factor = 1.5 # Approximation factor for cable size
10
-
11
- # Calculate total load (kW to kVA conversion for inductive loads)
12
- if load_type == "Inductive":
13
- total_load = load_rating * num_of_loads * 1.2 # Assuming 0.8 power factor
14
- else:
15
- total_load = load_rating * num_of_loads
16
-
17
- # Calculate current
18
- current = (total_load * 1000) / (voltage * (3**0.5) if voltage > 240 else voltage)
19
-
20
  # Calculate breaker size
21
- breaker_size = round(current * safety_factor, 2)
22
-
23
- # Calculate cable size (approximation)
24
- cable_size = round(current * cable_size_factor, 2)
25
-
26
- # Return the results
27
- return f"""
28
- Total Load: {round(total_load, 2)} kW
29
- Recommended Breaker Size: {breaker_size} A
30
- Suggested Cable Size: {cable_size} mm²
31
- """
32
-
33
- # Gradio interface
34
- def interface():
35
- # Inputs
36
- load_rating = gr.Number(label="Load Rating per Device (kW)")
37
- num_of_loads = gr.Number(label="Number of Loads")
38
- voltage = gr.Number(label="Voltage (230V for single-phase, 400V for three-phase)")
39
- load_type = gr.Dropdown(choices=["Resistive", "Inductive"], label="Load Type")
40
-
41
- # Outputs
42
- output = gr.Textbox(label="Load Calculation Results")
43
-
44
- # Launch the Gradio app
45
- gr.Interface(
46
- fn=load_calculation,
47
- inputs=[load_rating, num_of_loads, voltage, load_type],
48
- outputs=output,
49
- title="Load Calculation Assistant",
50
- description="Calculate load, breaker size, and cable size for electrical systems."
51
- ).launch()
52
-
53
- # Run the interface
54
- interface()
 
 
 
1
  import gradio as gr
2
 
3
+ # Function to calculate load, breaker size, and cable size
4
+ def calculate_load(load_rating, num_of_loads, voltage, load_type):
5
+ # Convert total load to watts
6
+ total_load_kw = load_rating * num_of_loads
7
+ total_load_w = total_load_kw * 1000 # Convert kW to W
8
+
 
 
 
 
 
 
 
 
 
9
  # Calculate breaker size
10
+ if load_type == "Resistive":
11
+ breaker_size = total_load_w / (voltage * 0.8)
12
+ elif load_type == "Inductive":
13
+ breaker_size = total_load_w / (voltage * 0.9)
14
+
15
+ # Calculate cable size (simplified estimation)
16
+ cable_size = total_load_w / (voltage * 2)
17
+
18
+ # Prepare the output
19
+ result = f"Total Load: {total_load_kw} kW\nBreaker Size: {breaker_size:.2f} A\nCable Size: {cable_size:.2f} mm²"
20
+ return result
21
+
22
+ # Set up the Gradio interface
23
+ interface = gr.Interface(fn=calculate_load,
24
+ inputs=[gr.Number(label="Load Rating per Device (kW)"),
25
+ gr.Number(label="Number of Loads"),
26
+ gr.Number(label="Voltage (V)"),
27
+ gr.Dropdown(choices=["Resistive", "Inductive"], label="Load Type")],
28
+ outputs="text")
29
+
30
+ if __name__ == "__main__":
31
+ interface.launch()