Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,89 +1,30 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
"hydraulic_power_kw": r(P_hydraulic_kW, 6),
|
| 3 |
-
"pump_power_kw": r(P_pump_kW, 6),
|
| 4 |
-
"hydraulic_power_hp": r(P_hydraulic_HP, 4),
|
| 5 |
-
"pump_power_hp": r(P_pump_HP, 4),
|
| 6 |
-
"notes": notes
|
| 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 |
-
head = gr.Number(value=10.0, label="Head (m)")
|
| 33 |
-
efficiency = gr.Number(value=70.0, label="Pump efficiency (%)")
|
| 34 |
-
fluid_density = gr.Number(value=RHO_WATER, label="Fluid density (kg/m^3)")
|
| 35 |
-
units_output = gr.Radio(choices=['kW','HP','Both'], value='Both', label='Output units')
|
| 36 |
-
calc_btn = gr.Button("Calculate")
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
with gr.Column(scale=1):
|
| 40 |
-
hydraulic_kw = gr.Textbox(label="Hydraulic power (kW)")
|
| 41 |
-
pump_kw = gr.Textbox(label="Pump shaft power (kW)")
|
| 42 |
-
hydraulic_hp = gr.Textbox(label="Hydraulic power (HP)")
|
| 43 |
-
pump_hp = gr.Textbox(label="Pump shaft power (HP)")
|
| 44 |
-
notes_box = gr.Textbox(label="Notes / Conversion info", lines=3)
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
def _on_calculate(flow_rate, flow_unit, head, efficiency, fluid_density, units_output):
|
| 48 |
-
out = calculate_pump_power(flow_rate, flow_unit, head, efficiency, fluid_density, units_output)
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
# prepare display depending on units_output
|
| 52 |
-
hk = out['hydraulic_power_kw']
|
| 53 |
-
pk = out['pump_power_kw']
|
| 54 |
-
hh = out['hydraulic_power_hp']
|
| 55 |
-
ph = out['pump_power_hp']
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
if units_output == 'kW':
|
| 59 |
-
return hk, pk, "-", "-", out['notes']
|
| 60 |
-
elif units_output == 'HP':
|
| 61 |
-
return "-", "-", hh, ph, out['notes']
|
| 62 |
-
else:
|
| 63 |
-
return hk, pk, hh, ph, out['notes']
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
calc_btn.click(
|
| 67 |
-
_on_calculate,
|
| 68 |
-
inputs=[flow_rate, flow_unit, head, efficiency, fluid_density, units_output],
|
| 69 |
-
outputs=[hydraulic_kw, pump_kw, hydraulic_hp, pump_hp, notes_box]
|
| 70 |
)
|
| 71 |
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
**Example use-cases / sanity checks:**
|
| 75 |
-
- Small utility pump: Q = 10 L/s, H = 20 m, η = 65% → result should be a few kW.
|
| 76 |
-
- Large circulation pump: Q = 0.5 m³/s, H = 15 m, η = 80% → result tens of kW.
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
**Notes:** The calculator uses a steady-state hydraulic power equation and ignores pipe losses, NPSH, cavitation and other real-world factors. Use this for first-order sizing only.
|
| 80 |
-
""")
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
gr.HTML("<small>Made with Gradio — ready for deployment to Hugging Face Spaces (use `gradio` >= 3.0).</small>")
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
if __name__ == '__main__':
|
| 89 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
def pump_power(flow_rate, head, efficiency):
|
| 4 |
+
"""
|
| 5 |
+
flow_rate: m^3/s
|
| 6 |
+
head: m
|
| 7 |
+
efficiency: decimal (0.7 for 70%)
|
| 8 |
+
"""
|
| 9 |
+
rho = 1000 # water density kg/m³
|
| 10 |
+
g = 9.81 # gravity m/s²
|
| 11 |
+
try:
|
| 12 |
+
P = (rho * g * flow_rate * head) / (efficiency if efficiency > 0 else 1)
|
| 13 |
+
return f"Pump Power: {P/1000:.2f} kW"
|
| 14 |
+
except Exception as e:
|
| 15 |
+
return f"Error: {e}"
|
| 16 |
+
|
| 17 |
+
iface = gr.Interface(
|
| 18 |
+
fn=pump_power,
|
| 19 |
+
inputs=[
|
| 20 |
+
gr.Number(label="Flow Rate (m³/s)"),
|
| 21 |
+
gr.Number(label="Head (m)"),
|
| 22 |
+
gr.Number(label="Efficiency (0-1)")
|
| 23 |
+
],
|
| 24 |
+
outputs="text",
|
| 25 |
+
title="Pump Power Calculator",
|
| 26 |
+
description="Calculates pump power requirement for water flow."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
)
|
| 28 |
|
| 29 |
+
if __name__ == "__main__":
|
| 30 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|