Spaces:
Sleeping
Sleeping
File size: 3,229 Bytes
80117c1 9c5a0d7 80117c1 867928f a5ad080 867928f a5ad080 867928f 9c5a0d7 867928f 9c5a0d7 867928f 9c5a0d7 867928f 9c5a0d7 867928f 9c5a0d7 867928f 9c5a0d7 867928f a5ad080 867928f a5ad080 867928f a5ad080 867928f 9c5a0d7 867928f 9c5a0d7 867928f 9c5a0d7 867928f 9c5a0d7 |
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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
import gradio as gr
import pandas as pd
# Updated Calculation Function (No Safety Factor)
def load_calculator(load_rating, num_of_loads, voltage, power_factor, phase_type):
try:
# Check if any input is invalid
if not all([load_rating, num_of_loads, voltage, power_factor]):
raise ValueError("All input fields must be filled with valid numbers.")
# Step 1: Calculate total load in kW
total_load = load_rating * num_of_loads # Total Load in kW
print(f"Total Load (kW): {total_load}")
# Step 2: Calculate current based on the type of phase (Single or Three Phase)
total_load_watts = total_load * 1000 # Convert kW to Watts
print(f"Total Load (W): {total_load_watts}")
# Current formula for Single Phase: I = P / (V * PF)
if phase_type == "Single-Phase":
total_current = total_load_watts / (voltage * power_factor)
print(f"Total Current (A - Single-Phase): {total_current}")
else: # Three-Phase: I = P / (sqrt(3) * V * PF)
total_current = total_load_watts / (3 ** 0.5 * voltage * power_factor)
print(f"Total Current (A - Three-Phase): {total_current}")
# Step 3: Calculate breaker size (no safety factor)
breaker_size = total_current # Breaker size in Amperes
print(f"Breaker Size (A): {breaker_size}")
# Step 4: Calculate cable size (assuming 0.75mm² per Ampere of current as an example)
cable_size = total_current * 0.75 # Cable size in mm²
print(f"Cable Size (mm²): {cable_size}")
# Step 5: Calculate apparent power in kVA
apparent_power = total_load / power_factor # Apparent Power in kVA
print(f"Apparent Power (kVA): {apparent_power}")
# Prepare results for returning to Gradio
return (
str(round(total_load, 2)),
str(round(total_current, 2)),
str(round(breaker_size, 2)),
str(round(cable_size, 2)),
str(round(apparent_power, 2))
)
except Exception as e:
# Return the error message if any exception occurs
return f"An error occurred: {str(e)}"
# Gradio Interface
def interface():
load_rating = gr.Number(label="Load Rating per Device (kW)")
num_of_loads = gr.Number(label="Number of Loads")
voltage = gr.Number(label="Voltage (230V for single-phase, 400V for three-phase)")
power_factor = gr.Number(label="Power Factor (0.8 for inductive loads, 1 for resistive)")
phase_type = gr.Radio(["Single-Phase", "Three-Phase"], label="Phase Type")
# Outputs
outputs = [
gr.Textbox(label="Total Load (kW)"),
gr.Textbox(label="Total Current (A)"),
gr.Textbox(label="Recommended Breaker Size (A)"),
gr.Textbox(label="Recommended Cable Size (mm²)"),
gr.Textbox(label="Total Apparent Power (kVA)")
]
# Launch Interface
gr.Interface(
fn=load_calculator,
inputs=[load_rating, num_of_loads, voltage, power_factor, phase_type],
outputs=outputs,
title="Load Calculation Assistant",
description="Calculate electrical loads and get the results."
).launch()
interface()
|