Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,23 +3,26 @@ import math
|
|
| 3 |
import matplotlib.pyplot as plt
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
-
#
|
|
|
|
|
|
|
|
|
|
| 7 |
st.set_page_config(page_title="Pipe Sizing Helper", page_icon="💧")
|
| 8 |
|
| 9 |
# Title and description
|
| 10 |
st.title("💧 Pipe Sizing Helper")
|
| 11 |
st.write("Calculate the recommended pipe diameter for a given flow rate and permissible velocity.")
|
| 12 |
|
| 13 |
-
#
|
| 14 |
st.sidebar.header("Input Parameters")
|
| 15 |
flow_rate = st.sidebar.number_input("Enter the Flow Rate (m³/s):", min_value=0.0, format="%.6f")
|
| 16 |
velocity = st.sidebar.number_input("Enter the Permissible Velocity (m/s):", min_value=0.1, format="%.3f")
|
| 17 |
|
| 18 |
-
#
|
| 19 |
if st.sidebar.button("Generate Diameter"):
|
| 20 |
if flow_rate > 0 and velocity > 0:
|
| 21 |
diameter = math.sqrt((4 * flow_rate) / (math.pi * velocity))
|
| 22 |
-
st.success(f"Recommended Pipe Diameter:
|
| 23 |
|
| 24 |
# Visualization of Pipe Diameter vs Flow Rate and Velocity
|
| 25 |
fig, ax = plt.subplots(1, 2, figsize=(14, 6))
|
|
@@ -28,7 +31,7 @@ if st.sidebar.button("Generate Diameter"):
|
|
| 28 |
flow_rate_values = np.linspace(0.1, 10, 100) # Generate a range of flow rates
|
| 29 |
diameters_flow_rate = np.sqrt((4 * flow_rate_values) / (math.pi * velocity)) # Calculate diameters for each flow rate
|
| 30 |
|
| 31 |
-
ax[0].plot(flow_rate_values, diameters_flow_rate, color='b', label="Diameter vs Flow Rate")
|
| 32 |
ax[0].set_title("Pipe Diameter vs Flow Rate")
|
| 33 |
ax[0].set_xlabel("Flow Rate (m³/s)")
|
| 34 |
ax[0].set_ylabel("Pipe Diameter (meters)")
|
|
@@ -39,7 +42,7 @@ if st.sidebar.button("Generate Diameter"):
|
|
| 39 |
velocity_values = np.linspace(0.1, 10, 100) # Generate a range of velocities
|
| 40 |
diameters_velocity = np.sqrt((4 * flow_rate) / (math.pi * velocity_values)) # Calculate diameters for each velocity
|
| 41 |
|
| 42 |
-
ax[1].plot(velocity_values, diameters_velocity, color='r', label="Diameter vs Velocity")
|
| 43 |
ax[1].set_title("Pipe Diameter vs Velocity")
|
| 44 |
ax[1].set_xlabel("Velocity (m/s)")
|
| 45 |
ax[1].set_ylabel("Pipe Diameter (meters)")
|
|
@@ -48,8 +51,8 @@ if st.sidebar.button("Generate Diameter"):
|
|
| 48 |
|
| 49 |
# Show the plot
|
| 50 |
st.pyplot(fig)
|
| 51 |
-
|
| 52 |
else:
|
| 53 |
-
st.error("Please enter positive values for flow rate and velocity.")
|
| 54 |
else:
|
| 55 |
-
st.info("Click the 'Generate Diameter' button to calculate.")
|
|
|
|
| 3 |
import matplotlib.pyplot as plt
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
+
# Ensure better visualization
|
| 7 |
+
plt.style.use("seaborn-darkgrid")
|
| 8 |
+
|
| 9 |
+
# Set page configuration with an icon and title
|
| 10 |
st.set_page_config(page_title="Pipe Sizing Helper", page_icon="💧")
|
| 11 |
|
| 12 |
# Title and description
|
| 13 |
st.title("💧 Pipe Sizing Helper")
|
| 14 |
st.write("Calculate the recommended pipe diameter for a given flow rate and permissible velocity.")
|
| 15 |
|
| 16 |
+
# Sidebar input fields
|
| 17 |
st.sidebar.header("Input Parameters")
|
| 18 |
flow_rate = st.sidebar.number_input("Enter the Flow Rate (m³/s):", min_value=0.0, format="%.6f")
|
| 19 |
velocity = st.sidebar.number_input("Enter the Permissible Velocity (m/s):", min_value=0.1, format="%.3f")
|
| 20 |
|
| 21 |
+
# Button to generate the result
|
| 22 |
if st.sidebar.button("Generate Diameter"):
|
| 23 |
if flow_rate > 0 and velocity > 0:
|
| 24 |
diameter = math.sqrt((4 * flow_rate) / (math.pi * velocity))
|
| 25 |
+
st.success(f"**Recommended Pipe Diameter: {diameter:.3f} meters**")
|
| 26 |
|
| 27 |
# Visualization of Pipe Diameter vs Flow Rate and Velocity
|
| 28 |
fig, ax = plt.subplots(1, 2, figsize=(14, 6))
|
|
|
|
| 31 |
flow_rate_values = np.linspace(0.1, 10, 100) # Generate a range of flow rates
|
| 32 |
diameters_flow_rate = np.sqrt((4 * flow_rate_values) / (math.pi * velocity)) # Calculate diameters for each flow rate
|
| 33 |
|
| 34 |
+
ax[0].plot(flow_rate_values, diameters_flow_rate, color='b', linewidth=2, label="Diameter vs Flow Rate")
|
| 35 |
ax[0].set_title("Pipe Diameter vs Flow Rate")
|
| 36 |
ax[0].set_xlabel("Flow Rate (m³/s)")
|
| 37 |
ax[0].set_ylabel("Pipe Diameter (meters)")
|
|
|
|
| 42 |
velocity_values = np.linspace(0.1, 10, 100) # Generate a range of velocities
|
| 43 |
diameters_velocity = np.sqrt((4 * flow_rate) / (math.pi * velocity_values)) # Calculate diameters for each velocity
|
| 44 |
|
| 45 |
+
ax[1].plot(velocity_values, diameters_velocity, color='r', linewidth=2, label="Diameter vs Velocity")
|
| 46 |
ax[1].set_title("Pipe Diameter vs Velocity")
|
| 47 |
ax[1].set_xlabel("Velocity (m/s)")
|
| 48 |
ax[1].set_ylabel("Pipe Diameter (meters)")
|
|
|
|
| 51 |
|
| 52 |
# Show the plot
|
| 53 |
st.pyplot(fig)
|
| 54 |
+
|
| 55 |
else:
|
| 56 |
+
st.error("⚠️ Please enter positive values for flow rate and velocity.")
|
| 57 |
else:
|
| 58 |
+
st.info("ℹ️ Click the 'Generate Diameter' button to calculate.")
|