Abdullah-Basar's picture
Update app.py
cad497b verified
import streamlit as st
import math
# Title and Description
st.title("🔧 Pipe Sizing Helper")
st.write("""
This app helps you determine the required pipe diameter based on the flow rate and fluid velocity.
Simply input the flow rate (in cubic meters per second) and velocity (in meters per second) to get the pipe diameter.
""")
# Sidebar Instructions
st.sidebar.title("How to Use")
st.sidebar.write("""
1. Enter the flow rate of the fluid in m³/s.
2. Enter the velocity of the fluid in m/s.
3. Click **Generate Pipe Diameter** to calculate the required pipe diameter.
4. Reset inputs using the **Clear Inputs** button.
""")
# User Inputs
st.subheader("Input Parameters")
flow_rate = st.number_input("Flow Rate (Q) in m³/s:", min_value=0.0, format="%.6f", step=0.01)
velocity = st.number_input("Fluid Velocity (v) in m/s:", min_value=0.1, format="%.2f", step=0.1)
# Generate Pipe Diameter Button
if st.button("Generate Pipe Diameter"):
if flow_rate <= 0:
st.error("Flow rate must be greater than zero!")
elif velocity <= 0:
st.error("Velocity must be greater than zero!")
else:
# Calculate pipe diameter
diameter = math.sqrt((4 * flow_rate) / (math.pi * velocity))
diameter_mm = diameter * 1000 # Convert to mm
st.subheader("Results")
st.write(f"**Required Pipe Diameter:** {diameter:.4f} meters ({diameter_mm:.2f} mm)")
# Reset Inputs
if st.button("Clear Inputs"):
flow_rate = 0.0
velocity = 0.0
st.experimental_rerun()
# Footer
st.write("---")
st.markdown("💡 **Developed by Abdullah**")