Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -34,7 +34,17 @@ def calculate_hydraulic_parameters(displacement, pressure, rpm, torque, flow_rat
|
|
34 |
power_torque = (torque_nm * rpm) / 9549 if torque_nm and rpm else None
|
35 |
power_flow_rate = (flow_rate_lpm * pressure_bar) / 600.0 if flow_rate_lpm and pressure_bar else None
|
36 |
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
# Streamlit App
|
40 |
st.title("Hydraulic Pump Power Calculator")
|
@@ -49,27 +59,78 @@ flow_rate_unit = st.sidebar.selectbox("Flow Rate Unit:", ["L/min", "m^3/h", "GPM
|
|
49 |
st.sidebar.header("Input Parameters")
|
50 |
|
51 |
# User inputs
|
52 |
-
displacement = st.sidebar.number_input("Pump Displacement (cc/rev, in^3/rev, or liters/rev):",
|
53 |
-
pressure = st.sidebar.number_input("Working Pressure (bar, MPa, PSI, kPa, or atm):",
|
54 |
-
rpm = st.sidebar.number_input("Pump RPM:",
|
55 |
-
torque = st.sidebar.number_input("Torque (Nm or lb-ft):",
|
56 |
-
flow_rate = st.sidebar.number_input("Flow Rate (L/min, m^3/h, GPM (US), or GPM (UK)):",
|
57 |
|
58 |
# Calculate parameters and power
|
59 |
if st.sidebar.button("Calculate"):
|
60 |
-
displacement_cc, pressure_bar,
|
61 |
displacement, pressure, rpm, torque, flow_rate,
|
62 |
displacement_unit, pressure_unit, torque_unit, flow_rate_unit
|
63 |
)
|
64 |
|
65 |
st.subheader("Results")
|
66 |
-
|
67 |
-
|
68 |
-
st.write(
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
|
74 |
# Hugging Face Space Deployment Notice
|
75 |
st.sidebar.markdown("---")
|
|
|
34 |
power_torque = (torque_nm * rpm) / 9549 if torque_nm and rpm else None
|
35 |
power_flow_rate = (flow_rate_lpm * pressure_bar) / 600.0 if flow_rate_lpm and pressure_bar else None
|
36 |
|
37 |
+
# Convert results to all available units
|
38 |
+
results = {
|
39 |
+
"displacement": {unit: displacement_cc / factor for unit, factor in UNIT_CONVERSIONS["Displacement"].items()} if displacement_cc else {},
|
40 |
+
"pressure": {unit: pressure_bar / factor for unit, factor in UNIT_CONVERSIONS["Pressure"].items()} if pressure_bar else {},
|
41 |
+
"torque": {unit: torque_nm / factor for unit, factor in UNIT_CONVERSIONS["Torque"].items()} if torque_nm else {},
|
42 |
+
"flow_rate": {unit: flow_rate_lpm / factor for unit, factor in UNIT_CONVERSIONS["Flow Rate"].items()} if flow_rate_lpm else {},
|
43 |
+
"power_displacement": power_displacement,
|
44 |
+
"power_torque": power_torque,
|
45 |
+
"power_flow_rate": power_flow_rate
|
46 |
+
}
|
47 |
+
return results, displacement_cc, pressure_bar, torque_nm, flow_rate_lpm
|
48 |
|
49 |
# Streamlit App
|
50 |
st.title("Hydraulic Pump Power Calculator")
|
|
|
59 |
st.sidebar.header("Input Parameters")
|
60 |
|
61 |
# User inputs
|
62 |
+
displacement = st.sidebar.number_input("Pump Displacement (cc/rev, in^3/rev, or liters/rev):", value=None, step=0.1, format="%.2f")
|
63 |
+
pressure = st.sidebar.number_input("Working Pressure (bar, MPa, PSI, kPa, or atm):", value=None, step=0.1, format="%.2f")
|
64 |
+
rpm = st.sidebar.number_input("Pump RPM:", value=None, step=1.0, format="%.0f")
|
65 |
+
torque = st.sidebar.number_input("Torque (Nm or lb-ft):", value=None, step=0.1, format="%.2f")
|
66 |
+
flow_rate = st.sidebar.number_input("Flow Rate (L/min, m^3/h, GPM (US), or GPM (UK)):", value=None, step=0.1, format="%.2f")
|
67 |
|
68 |
# Calculate parameters and power
|
69 |
if st.sidebar.button("Calculate"):
|
70 |
+
results, displacement_cc, pressure_bar, torque_nm, flow_rate_lpm = calculate_hydraulic_parameters(
|
71 |
displacement, pressure, rpm, torque, flow_rate,
|
72 |
displacement_unit, pressure_unit, torque_unit, flow_rate_unit
|
73 |
)
|
74 |
|
75 |
st.subheader("Results")
|
76 |
+
|
77 |
+
# Display formulas
|
78 |
+
st.write("### Formulas Used:")
|
79 |
+
if displacement_cc and pressure_bar and rpm:
|
80 |
+
st.write("Power based on Displacement: Power (kW) = (Displacement (cc/rev) × Pressure (bar) × RPM) / 600")
|
81 |
+
if torque_nm and rpm:
|
82 |
+
st.write("Power based on Torque: Power (kW) = (Torque (Nm) × RPM) / 9549")
|
83 |
+
if flow_rate_lpm and pressure_bar:
|
84 |
+
st.write("Power based on Flow Rate: Power (kW) = (Flow Rate (L/min) × Pressure (bar)) / 600")
|
85 |
+
|
86 |
+
# Display input conversions
|
87 |
+
st.write("### Converted Input Parameters:")
|
88 |
+
if displacement_cc:
|
89 |
+
st.write(f"Displacement: {displacement_cc:.2f} cc/rev")
|
90 |
+
if pressure_bar:
|
91 |
+
st.write(f"Pressure: {pressure_bar:.2f} bar")
|
92 |
+
if torque_nm:
|
93 |
+
st.write(f"Torque: {torque_nm:.2f} Nm")
|
94 |
+
if flow_rate_lpm:
|
95 |
+
st.write(f"Flow Rate: {flow_rate_lpm:.2f} L/min")
|
96 |
+
|
97 |
+
# Display results for all units
|
98 |
+
if results["displacement"]:
|
99 |
+
st.write("### Pump Displacement:")
|
100 |
+
for unit, value in results["displacement"].items():
|
101 |
+
st.write(f"{value:.2f} {unit}")
|
102 |
+
|
103 |
+
if results["pressure"]:
|
104 |
+
st.write("### Working Pressure:")
|
105 |
+
for unit, value in results["pressure"].items():
|
106 |
+
st.write(f"{value:.2f} {unit}")
|
107 |
+
|
108 |
+
if results["torque"]:
|
109 |
+
st.write("### Torque:")
|
110 |
+
for unit, value in results["torque"].items():
|
111 |
+
st.write(f"{value:.2f} {unit}")
|
112 |
+
|
113 |
+
if results["flow_rate"]:
|
114 |
+
st.write("### Flow Rate:")
|
115 |
+
for unit, value in results["flow_rate"].items():
|
116 |
+
st.write(f"{value:.2f} {unit}")
|
117 |
+
|
118 |
+
# Power results
|
119 |
+
st.write("### Hydraulic Power:")
|
120 |
+
if results['power_displacement']:
|
121 |
+
st.write(f"Based on Displacement: {results['power_displacement']:.2f} kW / {(results['power_displacement'] * 1.34102):.2f} HP")
|
122 |
+
else:
|
123 |
+
st.write("Power based on Displacement: Not calculable.")
|
124 |
+
|
125 |
+
if results['power_torque']:
|
126 |
+
st.write(f"Based on Torque: {results['power_torque']:.2f} kW / {(results['power_torque'] * 1.34102):.2f} HP")
|
127 |
+
else:
|
128 |
+
st.write("Power based on Torque: Not calculable.")
|
129 |
+
|
130 |
+
if results['power_flow_rate']:
|
131 |
+
st.write(f"Based on Flow Rate: {results['power_flow_rate']:.2f} kW / {(results['power_flow_rate'] * 1.34102):.2f} HP")
|
132 |
+
else:
|
133 |
+
st.write("Power based on Flow Rate: Not calculable.")
|
134 |
|
135 |
# Hugging Face Space Deployment Notice
|
136 |
st.sidebar.markdown("---")
|