Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
!pip install gradio
|
| 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()
|