import streamlit as st import math import numpy as np import plotly.graph_objects as go # Title and description st.title("🚀 Pipe Size Suggestion App") st.markdown(""" #### Enter the required flow rate and permissible velocity to get the suggested pipe diameter. **Formula Used:** - **Q = A × V** Where: - Q = Flow rate (m³/s) - A = Cross-sectional Area (m²) - V = Velocity (m/s) """) # Input fields with stylish layout st.sidebar.header("Input Parameters") flow_rate = st.sidebar.number_input("Flow Rate (m³/s)", min_value=0.0, step=0.01, format="%.4f") velocity = st.sidebar.number_input("Permissible Velocity (m/s)", min_value=0.01, step=0.01, format="%.2f") if st.sidebar.button("Calculate Pipe Size"): if velocity > 0: area = flow_rate / velocity # m^2 diameter = math.sqrt((4 * area) / math.pi) # m diameter_mm = diameter * 1000 # mm st.success(f"\U0001F4A1 Suggested Pipe Diameter: **{diameter_mm:.2f} mm**") # Create a 3D pipe visualization theta = np.linspace(0, 2 * np.pi, 50) z = np.linspace(0, 3, 50) theta_grid, z_grid = np.meshgrid(theta, z) x_grid = (diameter / 2) * np.cos(theta_grid) y_grid = (diameter / 2) * np.sin(theta_grid) fig = go.Figure(data=[go.Surface(x=x_grid, y=y_grid, z=z_grid, colorscale='Blues', opacity=0.8)]) fig.update_layout( title=f"3D Pipe Visualization ({diameter_mm:.1f} mm Diameter)", scene=dict( xaxis_title='X (m)', yaxis_title='Y (m)', zaxis_title='Length (m)', aspectratio=dict(x=1, y=1, z=2) ), margin=dict(l=0, r=0, t=50, b=0) ) st.plotly_chart(fig, use_container_width=True) else: st.error("Velocity must be greater than 0.")