Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
# Function to calculate pump power
|
| 4 |
+
def pump_power(density, flow_rate, head, efficiency):
|
| 5 |
+
try:
|
| 6 |
+
density = float(density)
|
| 7 |
+
flow_rate = float(flow_rate)
|
| 8 |
+
head = float(head)
|
| 9 |
+
efficiency = float(efficiency)
|
| 10 |
+
|
| 11 |
+
if efficiency <= 0 or efficiency > 1:
|
| 12 |
+
return "❌ Efficiency must be between 0 and 1 (e.g., 0.7 for 70%)."
|
| 13 |
+
|
| 14 |
+
g = 9.81 # gravitational acceleration (m/s²)
|
| 15 |
+
power = (density * g * flow_rate * head) / efficiency # in watts
|
| 16 |
+
power_kw = power / 1000 # convert to kW
|
| 17 |
+
|
| 18 |
+
return f"🔹 Pump Power: {power_kw:.2f} kW ({power:.2f} W)"
|
| 19 |
+
|
| 20 |
+
except Exception as e:
|
| 21 |
+
return f"⚠️ Error: {str(e)}"
|
| 22 |
+
|
| 23 |
+
# Gradio Interface
|
| 24 |
+
demo = gr.Interface(
|
| 25 |
+
fn=pump_power,
|
| 26 |
+
inputs=[
|
| 27 |
+
gr.Textbox(label="Fluid Density (kg/m³)", placeholder="e.g., 1000 for water"),
|
| 28 |
+
gr.Textbox(label="Flow Rate (m³/s)", placeholder="e.g., 0.05"),
|
| 29 |
+
gr.Textbox(label="Head (m)", placeholder="e.g., 15"),
|
| 30 |
+
gr.Textbox(label="Efficiency (0-1)", placeholder="e.g., 0.7 for 70%")
|
| 31 |
+
],
|
| 32 |
+
outputs="text",
|
| 33 |
+
title="⚙️ Pump Power Calculator",
|
| 34 |
+
description="Calculate pump power using the formula P = (ρ * g * Q * H) / η"
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
if __name__ == "__main__":
|
| 38 |
+
demo.launch()
|