Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
# Import libraries
|
| 2 |
import os
|
| 3 |
import numpy as np
|
| 4 |
import pandas as pd
|
|
@@ -14,7 +13,8 @@ client = Groq(api_key=api_key)
|
|
| 14 |
# HVAC Load Calculation Logic
|
| 15 |
def calculate_load(room_size, insulation_type, climate, occupants, outdoor_air, dust_efficiency, design_temp,
|
| 16 |
material, infiltration, internal_loads, lighting_cooling_factor, heat_gain_occupant,
|
| 17 |
-
space_per_occupant, sensible_heat_factor, solar_heat_gain, shading_coefficients, cooling_load_temp_diff
|
|
|
|
| 18 |
try:
|
| 19 |
# R-values for selected materials (per inch)
|
| 20 |
material_r_values = {
|
|
@@ -70,10 +70,23 @@ def calculate_load(room_size, insulation_type, climate, occupants, outdoor_air,
|
|
| 70 |
# Calculate tonnage
|
| 71 |
required_tonnage = total_load_btu / 12000
|
| 72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
# Determine recommendation
|
| 74 |
recommendation = "AC is required" if climate == "Hot" else "Heater is required"
|
| 75 |
|
| 76 |
-
return total_load_btu, total_load_kw, required_tonnage, recommendation, {
|
| 77 |
"Base Load": base_load,
|
| 78 |
"Ventilation Load": ventilation_load,
|
| 79 |
"Infiltration Load": infiltration_load,
|
|
@@ -83,7 +96,7 @@ def calculate_load(room_size, insulation_type, climate, occupants, outdoor_air,
|
|
| 83 |
"Wall Load": wall_load,
|
| 84 |
}
|
| 85 |
except Exception as e:
|
| 86 |
-
return f"Error in calculation: {e}", None, None, None, {}
|
| 87 |
|
| 88 |
# Visualization Function
|
| 89 |
def generate_plot(load_components):
|
|
@@ -106,19 +119,13 @@ def generate_plot(load_components):
|
|
| 106 |
def app(room_size, insulation_type, climate, occupants, outdoor_air, dust_efficiency, design_temp,
|
| 107 |
material, infiltration, internal_loads, lighting_cooling_factor, heat_gain_occupant,
|
| 108 |
space_per_occupant, sensible_heat_factor, solar_heat_gain, shading_coefficients, cooling_load_temp_diff,
|
| 109 |
-
hours_of_usage, cost_per_kwh):
|
| 110 |
try:
|
| 111 |
-
|
| 112 |
-
"Room Size (sq ft)": room_size,
|
| 113 |
-
"Insulation Type": insulation_type,
|
| 114 |
-
"Climate": climate,
|
| 115 |
-
"Occupants": occupants,
|
| 116 |
-
"Selected Material": material,
|
| 117 |
-
}
|
| 118 |
-
total_load_btu, total_load_kw, required_tonnage, recommendation, load_components = calculate_load(
|
| 119 |
room_size, insulation_type, climate, occupants, outdoor_air, dust_efficiency, design_temp,
|
| 120 |
material, infiltration, internal_loads, lighting_cooling_factor, heat_gain_occupant,
|
| 121 |
-
space_per_occupant, sensible_heat_factor, solar_heat_gain, shading_coefficients, cooling_load_temp_diff
|
|
|
|
| 122 |
)
|
| 123 |
|
| 124 |
# Calculate energy consumption and cost
|
|
@@ -127,16 +134,37 @@ def app(room_size, insulation_type, climate, occupants, outdoor_air, dust_effici
|
|
| 127 |
|
| 128 |
plot_path = generate_plot(load_components)
|
| 129 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
return (
|
| 131 |
f"Total HVAC Load: {total_load_btu:.2f} BTU/hr ({total_load_kw:.2f} kW)\n"
|
| 132 |
f"Recommended Tonnage: {required_tonnage:.2f} tons\n"
|
| 133 |
f"Recommendation: {recommendation}\n"
|
| 134 |
f"Energy Consumed: {energy_consumed_kwh:.2f} kWh\n"
|
| 135 |
-
f"Total Cost: ${total_cost:.2f}"
|
|
|
|
|
|
|
| 136 |
plot_path,
|
|
|
|
| 137 |
)
|
| 138 |
except Exception as e:
|
| 139 |
-
return f"Error: {e}", None
|
| 140 |
|
| 141 |
# Gradio Interface
|
| 142 |
interface = gr.Interface(
|
|
@@ -150,39 +178,29 @@ interface = gr.Interface(
|
|
| 150 |
gr.Number(label="ASHRAE Dust Spot Efficiency (%)", value=100),
|
| 151 |
gr.Number(label="Design Temperature (°C)", value=24),
|
| 152 |
gr.Dropdown(
|
| 153 |
-
label="
|
| 154 |
-
choices=[
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
"Extruded Polystyrene (XPS)",
|
| 158 |
-
"Spray Foam Insulation",
|
| 159 |
-
"Wood (Softwood)",
|
| 160 |
-
"Concrete (6\" thick)",
|
| 161 |
-
"Brick",
|
| 162 |
-
"Double Glazed Glass",
|
| 163 |
-
"Mineral Wool Insulation",
|
| 164 |
-
"Cellulose Insulation",
|
| 165 |
-
],
|
| 166 |
-
value="Fiberglass Insulation (Batt or Roll)",
|
| 167 |
),
|
| 168 |
-
gr.Number(label="Infiltration
|
| 169 |
-
gr.Number(label="Internal Loads (
|
| 170 |
-
gr.Number(label="Lighting Cooling Factor (
|
| 171 |
-
gr.Number(label="Heat Gain
|
| 172 |
-
gr.Number(label="Space per Occupant (sq ft
|
| 173 |
-
gr.Number(label="Sensible Heat Factor for
|
| 174 |
-
gr.Number(label="Solar Heat Gain
|
| 175 |
-
gr.Number(label="Shading Coefficients"
|
| 176 |
-
gr.Number(label="Cooling Load
|
| 177 |
-
gr.Number(label="Hours of Usage
|
| 178 |
-
gr.Number(label="Cost per kWh (
|
|
|
|
| 179 |
],
|
| 180 |
outputs=[
|
| 181 |
-
gr.
|
| 182 |
gr.Image(label="Load Breakdown Plot"),
|
| 183 |
-
|
| 184 |
-
|
| 185 |
)
|
| 186 |
|
| 187 |
-
|
| 188 |
-
interface.launch(share=True)
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import numpy as np
|
| 3 |
import pandas as pd
|
|
|
|
| 13 |
# HVAC Load Calculation Logic
|
| 14 |
def calculate_load(room_size, insulation_type, climate, occupants, outdoor_air, dust_efficiency, design_temp,
|
| 15 |
material, infiltration, internal_loads, lighting_cooling_factor, heat_gain_occupant,
|
| 16 |
+
space_per_occupant, sensible_heat_factor, solar_heat_gain, shading_coefficients, cooling_load_temp_diff,
|
| 17 |
+
is_commercial=False):
|
| 18 |
try:
|
| 19 |
# R-values for selected materials (per inch)
|
| 20 |
material_r_values = {
|
|
|
|
| 70 |
# Calculate tonnage
|
| 71 |
required_tonnage = total_load_btu / 12000
|
| 72 |
|
| 73 |
+
# Commercial building load: increase size factor for larger spaces
|
| 74 |
+
if is_commercial:
|
| 75 |
+
total_load_btu *= 1.5 # Scale load for commercial buildings
|
| 76 |
+
required_tonnage = total_load_btu / 12000
|
| 77 |
+
|
| 78 |
+
# Maintenance recommendations based on usage
|
| 79 |
+
maintenance_recommendation = ""
|
| 80 |
+
if room_size > 1000:
|
| 81 |
+
maintenance_recommendation = "Regular HVAC maintenance is recommended, check air filters and ducts."
|
| 82 |
+
|
| 83 |
+
# Energy savings tips based on input
|
| 84 |
+
energy_savings_tips = "Consider upgrading insulation or using energy-efficient HVAC systems for better performance."
|
| 85 |
+
|
| 86 |
# Determine recommendation
|
| 87 |
recommendation = "AC is required" if climate == "Hot" else "Heater is required"
|
| 88 |
|
| 89 |
+
return total_load_btu, total_load_kw, required_tonnage, recommendation, maintenance_recommendation, energy_savings_tips, {
|
| 90 |
"Base Load": base_load,
|
| 91 |
"Ventilation Load": ventilation_load,
|
| 92 |
"Infiltration Load": infiltration_load,
|
|
|
|
| 96 |
"Wall Load": wall_load,
|
| 97 |
}
|
| 98 |
except Exception as e:
|
| 99 |
+
return f"Error in calculation: {e}", None, None, None, None, None, {}
|
| 100 |
|
| 101 |
# Visualization Function
|
| 102 |
def generate_plot(load_components):
|
|
|
|
| 119 |
def app(room_size, insulation_type, climate, occupants, outdoor_air, dust_efficiency, design_temp,
|
| 120 |
material, infiltration, internal_loads, lighting_cooling_factor, heat_gain_occupant,
|
| 121 |
space_per_occupant, sensible_heat_factor, solar_heat_gain, shading_coefficients, cooling_load_temp_diff,
|
| 122 |
+
hours_of_usage, cost_per_kwh, is_commercial):
|
| 123 |
try:
|
| 124 |
+
total_load_btu, total_load_kw, required_tonnage, recommendation, maintenance_recommendation, energy_savings_tips, load_components = calculate_load(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
room_size, insulation_type, climate, occupants, outdoor_air, dust_efficiency, design_temp,
|
| 126 |
material, infiltration, internal_loads, lighting_cooling_factor, heat_gain_occupant,
|
| 127 |
+
space_per_occupant, sensible_heat_factor, solar_heat_gain, shading_coefficients, cooling_load_temp_diff,
|
| 128 |
+
is_commercial
|
| 129 |
)
|
| 130 |
|
| 131 |
# Calculate energy consumption and cost
|
|
|
|
| 134 |
|
| 135 |
plot_path = generate_plot(load_components)
|
| 136 |
|
| 137 |
+
# Generate a report PDF
|
| 138 |
+
report_pdf = FPDF()
|
| 139 |
+
report_pdf.add_page()
|
| 140 |
+
report_pdf.set_font("Arial", size=12)
|
| 141 |
+
report_pdf.cell(200, 10, txt="HVAC Load Calculation Report", ln=True, align="C")
|
| 142 |
+
report_pdf.ln(10)
|
| 143 |
+
report_pdf.multi_cell(0, 10, txt=f"Room Size: {room_size} sq ft\n"
|
| 144 |
+
f"Insulation Type: {insulation_type}\n"
|
| 145 |
+
f"Climate: {climate}\n"
|
| 146 |
+
f"Number of Occupants: {occupants}\n"
|
| 147 |
+
f"Recommended Tonnage: {required_tonnage:.2f} tons\n"
|
| 148 |
+
f"Total HVAC Load: {total_load_btu:.2f} BTU/hr ({total_load_kw:.2f} kW)\n"
|
| 149 |
+
f"Energy Consumed: {energy_consumed_kwh:.2f} kWh\n"
|
| 150 |
+
f"Total Cost: ${total_cost:.2f}\n"
|
| 151 |
+
f"Maintenance Recommendation: {maintenance_recommendation}\n"
|
| 152 |
+
f"Energy Savings Tips: {energy_savings_tips}")
|
| 153 |
+
report_pdf.output("hvac_report.pdf")
|
| 154 |
+
|
| 155 |
return (
|
| 156 |
f"Total HVAC Load: {total_load_btu:.2f} BTU/hr ({total_load_kw:.2f} kW)\n"
|
| 157 |
f"Recommended Tonnage: {required_tonnage:.2f} tons\n"
|
| 158 |
f"Recommendation: {recommendation}\n"
|
| 159 |
f"Energy Consumed: {energy_consumed_kwh:.2f} kWh\n"
|
| 160 |
+
f"Total Cost: ${total_cost:.2f}\n"
|
| 161 |
+
f"Maintenance Recommendation: {maintenance_recommendation}\n"
|
| 162 |
+
f"Energy Savings Tips: {energy_savings_tips}",
|
| 163 |
plot_path,
|
| 164 |
+
"hvac_report.pdf"
|
| 165 |
)
|
| 166 |
except Exception as e:
|
| 167 |
+
return f"Error: {e}", None, None
|
| 168 |
|
| 169 |
# Gradio Interface
|
| 170 |
interface = gr.Interface(
|
|
|
|
| 178 |
gr.Number(label="ASHRAE Dust Spot Efficiency (%)", value=100),
|
| 179 |
gr.Number(label="Design Temperature (°C)", value=24),
|
| 180 |
gr.Dropdown(
|
| 181 |
+
label="Building Material",
|
| 182 |
+
choices=["Fiberglass Insulation (Batt or Roll)", "Expanded Polystyrene (EPS)", "Extruded Polystyrene (XPS)",
|
| 183 |
+
"Spray Foam Insulation", "Wood (Softwood)", "Concrete (6\" thick)", "Brick", "Double Glazed Glass",
|
| 184 |
+
"Mineral Wool Insulation", "Cellulose Insulation"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
),
|
| 186 |
+
gr.Number(label="Infiltration (CFM)"),
|
| 187 |
+
gr.Number(label="Internal Loads (W/m²)"),
|
| 188 |
+
gr.Number(label="Lighting Cooling Factor (W/m²)"),
|
| 189 |
+
gr.Number(label="Heat Gain per Occupant (W)"),
|
| 190 |
+
gr.Number(label="Space per Occupant (sq ft)"),
|
| 191 |
+
gr.Number(label="Sensible Heat Factor for Occupants"),
|
| 192 |
+
gr.Number(label="Solar Heat Gain (W/m²)"),
|
| 193 |
+
gr.Number(label="Shading Coefficients"),
|
| 194 |
+
gr.Number(label="Cooling Load Temperature Difference (°C)"),
|
| 195 |
+
gr.Number(label="Hours of Usage (hrs/day)", value=5),
|
| 196 |
+
gr.Number(label="Cost per kWh ($)", value=0.12),
|
| 197 |
+
gr.Checkbox(label="Is Commercial Building?", value=False)
|
| 198 |
],
|
| 199 |
outputs=[
|
| 200 |
+
gr.Textbox(label="Results"),
|
| 201 |
gr.Image(label="Load Breakdown Plot"),
|
| 202 |
+
gr.File(label="Download HVAC Report")
|
| 203 |
+
]
|
| 204 |
)
|
| 205 |
|
| 206 |
+
interface.launch()
|
|
|