Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import math | |
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| # Set the page configuration with an icon and title | |
| st.set_page_config(page_title="Pipe Sizing Helper", page_icon="💧") | |
| # Title and description | |
| st.title("💧 Pipe Sizing Helper") | |
| st.write("Calculate the recommended pipe diameter for a given flow rate and permissible velocity.") | |
| # Input fields | |
| st.sidebar.header("Input Parameters") | |
| flow_rate = st.sidebar.number_input("Enter the Flow Rate (m³/s):", min_value=0.0, format="%.6f") | |
| velocity = st.sidebar.number_input("Enter the Permissible Velocity (m/s):", min_value=0.1, format="%.3f") | |
| # Add a button to generate the result | |
| if st.sidebar.button("Generate Diameter"): | |
| if flow_rate > 0 and velocity > 0: | |
| diameter = math.sqrt((4 * flow_rate) / (math.pi * velocity)) | |
| st.success(f"Recommended Pipe Diameter: **{diameter:.3f} meters**") | |
| # Visualization of Pipe Diameter vs Flow Rate and Velocity | |
| fig, ax = plt.subplots(1, 2, figsize=(14, 6)) | |
| # Pipe Diameter vs Flow Rate | |
| flow_rate_values = np.linspace(0.1, 10, 100) # Generate a range of flow rates | |
| diameters_flow_rate = np.sqrt((4 * flow_rate_values) / (math.pi * velocity)) # Calculate diameters for each flow rate | |
| ax[0].plot(flow_rate_values, diameters_flow_rate, color='b', label="Diameter vs Flow Rate") | |
| ax[0].set_title("Pipe Diameter vs Flow Rate") | |
| ax[0].set_xlabel("Flow Rate (m³/s)") | |
| ax[0].set_ylabel("Pipe Diameter (meters)") | |
| ax[0].grid(True) | |
| ax[0].legend() | |
| # Pipe Diameter vs Velocity | |
| velocity_values = np.linspace(0.1, 10, 100) # Generate a range of velocities | |
| diameters_velocity = np.sqrt((4 * flow_rate) / (math.pi * velocity_values)) # Calculate diameters for each velocity | |
| ax[1].plot(velocity_values, diameters_velocity, color='r', label="Diameter vs Velocity") | |
| ax[1].set_title("Pipe Diameter vs Velocity") | |
| ax[1].set_xlabel("Velocity (m/s)") | |
| ax[1].set_ylabel("Pipe Diameter (meters)") | |
| ax[1].grid(True) | |
| ax[1].legend() | |
| # Show the plot | |
| st.pyplot(fig) | |
| else: | |
| st.error("Please enter positive values for flow rate and velocity.") | |
| else: | |
| st.info("Click the 'Generate Diameter' button to calculate.") | |