Spaces:
Build error
Build error
Update app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464712 unmodified lines606162636465import gradio as grimport pandas as pdimport matplotlib.pyplot as plt# Updated Calculation Functiondef load_calculator(load_rating, num_of_loads, voltage, power_factor, safety_factor, phase_type):total_load = load_rating * num_of_loads # Total Load in kWtotal_current = (total_load * 1000) / (voltage * power_factor) # Current in Amperesif phase_type == "Three-Phase":total_current /= (3 ** 0.5)# Adjust breaker and cable sizes using safety factorbreaker_size = total_current * safety_factorcable_size = total_current * safety_factor * 0.75 # Example adjustment for cable sizeapparent_power = total_load / power_factor # Apparent Power in kVA# Save results to DataFrameresults = pd.DataFrame({"Metric": ["Total Load (kW)", "Total Current (A)", "Breaker Size (A)", "Cable Size (mm²)", "Apparent Power (kVA)"],"Value": [total_load, total_current, breaker_size, cable_size, apparent_power],})# Generate bar chartplt.figure(figsize=(6, 4))plt.bar(results["Metric"], results["Value"], color="skyblue")plt.title("Load Calculation Results")plt.xticks(rotation=45, ha='right')plt.tight_layout()plt.savefig("results_chart.png")plt.close()# Save results to Excelresults.to_excel("load_results.xlsx", index=False)return (round(total_load, 2),round(total_current, 2),round(breaker_size, 2),round(cable_size, 2),round(apparent_power, 2),"results_chart.png",)# Gradio Interfacedef interface():12 unmodified linesgr.Textbox(label="Recommended Cable Size (mm²)"),gr.Textbox(label="Total Apparent Power (kVA)"),gr.Image(label="Graphical Visualization"), # Graph output]# Launch Interface12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565712 unmodified lines70717273747576import gradio as grimport pandas as pdimport matplotlib.pyplot as pltfrom io import BytesIO# Updated Calculation Functiondef load_calculator(load_rating, num_of_loads, voltage, power_factor, safety_factor, phase_type):try:total_load = load_rating * num_of_loads # Total Load in kWtotal_current = (total_load * 1000) / (voltage * power_factor) # Current in Amperesif phase_type == "Three-Phase":total_current /= (3 ** 0.5)# Adjust breaker and cable sizes using safety factorbreaker_size = total_current * safety_factorcable_size = total_current * safety_factor * 0.75 # Example adjustment for cable sizeapparent_power = total_load / power_factor # Apparent Power in kVA# Prepare resultsresults = pd.DataFrame({"Metric": ["Total Load (kW)", "Total Current (A)", "Breaker Size (A)", "Cable Size (mm²)", "Apparent Power (kVA)"],"Value": [total_load, total_current, breaker_size, cable_size, apparent_power],})# Generate bar chartplt.figure(figsize=(6, 4))plt.bar(results["Metric"], results["Value"], color="skyblue")plt.title("Load Calculation Results")plt.xticks(rotation=45, ha='right')plt.tight_layout()# Save the plot to a BytesIO objectbuf = BytesIO()plt.savefig(buf, format='png')buf.seek(0)plt.close()# Save Excel data to a BytesIO objectexcel_buf = BytesIO()results.to_excel(excel_buf, index=False)excel_buf.seek(0)return (round(total_load, 2),round(total_current, 2),round(breaker_size, 2),round(cable_size, 2),round(apparent_power, 2),buf,excel_buf,)except Exception as e:return f"An error occurred: {e}"# Gradio Interfacedef interface():12 unmodified linesgr.Textbox(label="Recommended Cable Size (mm²)"),gr.Textbox(label="Total Apparent Power (kVA)"),gr.Image(label="Graphical Visualization"), # Graph outputgr.File(label="Download Excel Results"), # Excel file output]# Launch Interface
app.py+43-32