# app.py import streamlit as st import math import matplotlib.pyplot as plt import numpy as np # Page Configuration with Icon st.set_page_config( page_title="🔧 Pipe Sizing Helper", page_icon="💧", layout="centered" ) # Custom CSS for Styling st.markdown(""" """, unsafe_allow_html=True) # Header with Icon st.markdown("
💧
", unsafe_allow_html=True) st.markdown("

🔧 Pipe Sizing Helper

", unsafe_allow_html=True) st.markdown("

Calculate optimal pipe size based on flow rate and velocity

", unsafe_allow_html=True) # User Inputs st.subheader("💡 Input Parameters") flow_rate = st.number_input("🌊 Enter Flow Rate (m³/s):", min_value=0.0, format="%.4f") velocity = st.number_input("💨 Enter Permissible Velocity (m/s):", min_value=0.1, format="%.2f") # Button for Calculation and Visualization st.markdown("
", unsafe_allow_html=True) if st.button("🔄 Generate Pipe Diameter and Visualize"): if velocity > 0 and flow_rate > 0: # Formula: Diameter = sqrt((4 * Flow Rate) / (π * Velocity)) diameter = math.sqrt((4 * flow_rate) / (math.pi * velocity)) st.markdown(f"

✅ Recommended Pipe Diameter: {diameter:.2f} meters

", unsafe_allow_html=True) # Visualization st.subheader("📊 Visualization: Pipe Diameter vs Flow Rate and Velocity") flow_rates = np.linspace(0.1, flow_rate * 2, 100) velocities = np.linspace(0.1, velocity * 2, 100) diameters = [math.sqrt((4 * fr) / (math.pi * velocity)) for fr in flow_rates] # Plot fig, ax = plt.subplots() ax.plot(flow_rates, diameters, label='Pipe Diameter (m)', lw=2) ax.scatter(flow_rate, diameter, color='red', zorder=5, label='Your Input') ax.set_xlabel('Flow Rate (m³/s)') ax.set_ylabel('Pipe Diameter (m)') ax.set_title('Pipe Diameter vs Flow Rate') ax.legend() ax.grid(True) st.pyplot(fig) else: st.warning("⚠️ Please enter valid positive values for flow rate and velocity.") st.markdown("
", unsafe_allow_html=True) # Footer st.markdown("", unsafe_allow_html=True)