CoolFace
Apppublic

hamzahaider75/Pipe_Sizes

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
app.py61 linesDownload Raw Back to root
1import streamlit as st2import math3import matplotlib.pyplot as plt4 5# App title and configuration6st.set_page_config(page_title="Pipe Sizing Helper", layout="centered")7 8# Display app title9st.title("Pipe Sizing Helper")10 11# Description12st.write("""13This tool helps you calculate the recommended pipe diameter for a given flow rate and velocity.14Just enter the flow rate and the permissible velocity, and click the button below to generate the recommended pipe diameter.15""")16 17# Input fields18flow_rate = st.number_input("Enter the flow rate (Q) in cubic meters per second (m³/s):", min_value=0.0, step=0.01)19velocity = st.number_input("Enter the permissible velocity (v) in meters per second (m/s):", min_value=0.0, step=0.01)20 21# Button for generating recommended pipe diameter22if st.button("Calculate Recommended Pipe Diameter"):23    if flow_rate > 0 and velocity > 0:24        # Calculate pipe diameter25        diameter = math.sqrt((4 * flow_rate) / (math.pi * velocity))26        diameter_mm = diameter * 1000  # Convert to mm27        28        # Display result29        st.success(f"Recommended Pipe Diameter: {diameter:.4f} meters ({diameter_mm:.2f} mm)")30 31        # Graphical representation of the pipe diameter32        st.subheader("Graphical Representation")33 34        # Create a simple circle to represent the pipe diameter35        fig, ax = plt.subplots(figsize=(5, 5))36        circle = plt.Circle((0.5, 0.5), 0.5, color='blue', alpha=0.3)37        ax.add_artist(circle)38        ax.set_xlim(0, 1)39        ax.set_ylim(0, 1)40        ax.set_aspect('equal', adjustable='datalim')41        ax.set_title(f"Pipe Diameter: {diameter_mm:.2f} mm")42        ax.axis('off')  # Hide axes43        st.pyplot(fig)44 45        # Optional: Add a flow rate vs. velocity graph46        st.subheader("Flow Rate vs. Velocity")47 48        velocities = [i for i in range(1, 11)]  # Example velocity range (1 to 10 m/s)49        diameters = [math.sqrt((4 * flow_rate) / (math.pi * v)) * 1000 for v in velocities]50 51        # Plotting the graph52        plt.figure(figsize=(8, 5))53        plt.plot(velocities, diameters, marker='o', linestyle='-', color='orange')54        plt.xlabel("Velocity (m/s)")55        plt.ylabel("Pipe Diameter (mm)")56        plt.title("Pipe Diameter vs. Velocity for Given Flow Rate")57        plt.grid(True)58        st.pyplot(plt)59    else:60        st.warning("Please enter positive values for both flow rate and velocity.")61