Spaces:
Build error
Build error
Update app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354# Import necessary librariesimport gradio as gr# Function to calculate load distributiondef load_calculation(load_rating, num_of_loads, voltage, load_type):# Constantssafety_factor = 1.25 # 25% safety margincable_size_factor = 1.5 # Approximation factor for cable size# Calculate total load (kW to kVA conversion for inductive loads)if load_type == "Inductive":total_load = load_rating * num_of_loads * 1.2 # Assuming 0.8 power factorelse:total_load = load_rating * num_of_loads# Calculate currentcurrent = (total_load * 1000) / (voltage * (3**0.5) if voltage > 240 else voltage)# Calculate breaker sizebreaker_size = round(current * safety_factor, 2)# Calculate cable size (approximation)cable_size = round(current * cable_size_factor, 2)# Return the resultsreturn f"""Total Load: {round(total_load, 2)} kWRecommended Breaker Size: {breaker_size} ASuggested Cable Size: {cable_size} mm²"""# Gradio interfacedef interface():# Inputsload_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)")load_type = gr.Dropdown(choices=["Resistive", "Inductive"], label="Load Type")# Outputsoutput = gr.Textbox(label="Load Calculation Results")# Launch the Gradio appgr.Interface(fn=load_calculation,inputs=[load_rating, num_of_loads, voltage, load_type],outputs=output,title="Load Calculation Assistant",description="Calculate load, breaker size, and cable size for electrical systems.").launch()# Run the interfaceinterface()12345678910111213141516171819202122232425262728293031import gradio as gr# Function to calculate load, breaker size, and cable sizedef calculate_load(load_rating, num_of_loads, voltage, load_type):# Convert total load to wattstotal_load_kw = load_rating * num_of_loadstotal_load_w = total_load_kw * 1000 # Convert kW to W# Calculate breaker sizeif load_type == "Resistive":breaker_size = total_load_w / (voltage * 0.8)elif load_type == "Inductive":breaker_size = total_load_w / (voltage * 0.9)# Calculate cable size (simplified estimation)cable_size = total_load_w / (voltage * 2)# Prepare the outputresult = f"Total Load: {total_load_kw} kW\nBreaker Size: {breaker_size:.2f} A\nCable Size: {cable_size:.2f} mm²"return result# Set up the Gradio interfaceinterface = gr.Interface(fn=calculate_load,inputs=[gr.Number(label="Load Rating per Device (kW)"),gr.Number(label="Number of Loads"),gr.Number(label="Voltage (V)"),gr.Dropdown(choices=["Resistive", "Inductive"], label="Load Type")],outputs="text")if __name__ == "__main__":interface.launch()
app.py+28-51